Javascript 7 种数据类型:
- null(空值)
- undefined(未定义)
- boolean(布尔值)
- number(数字)
- string(字符串)
- object(对象)
- symbol(符号)
typeof 类型检测:
-
typeof null; // object (特殊 返回null值更合理)
-
typeof cuijiaqi; // undefined (变量cuijiaqi在之前连声明都没有声明居然就返回undefined,也显得不是很合理, 因为一般一个变量在声明之后并未赋值 用typeof检测才会返回undefined,这也是未声明和未定义的区别)
-
typeof undefined; // undefined
-
typeof true; // boolean
-
typeof 22; // number
-
typeof 'cuijiaqi'; // string
-
typeof {}; // object
-
typeof Symbol('cuijiaqi'); // symbol
-
typeof function () {}; // function (需注意)
-
typeof [1, 2, 3]; // object (需注意)