Toán tử typeof là gì?

{{FormatNumbertoThousand(model.total_like)}} lượt thích
4.872 lượt xem

JavaScript cung cấp một toán tử typeof có thể kiểm tra một giá trị và cho bạn biết nó là loại gì:

var a;
typeof a; // "undefined"

a = "hello world";
typeof a; // "string"

a = 42;
typeof a; // "number"

a = true;
typeof a; // "boolean"

a = null;
typeof a; // "object" -- weird, bug

a = undefined;
typeof a; // "undefined"

a = { b: "c" };
typeof a; // "object"
{{login.error}}