数据类型分为2种
1 - 简单数据类型
- String
字符串类型
- Number
数字类型
- Boolean
布尔类型
- undefined
变量未定义
- null
空类型
2 - 复杂数据类型
- Array
数组类型
- Object
对象类型
查看类型的方式
typeof
console.log(typeof 100); // number
console.log(typeof 0.1); // number
console.log(typeof cwz); // string
console.log(typeof true); // boolean
console.log(typeof false); // boolean
var num;
console.log(num) // undefined
console.log(num1) // undefined
var str = null;
console.log(str); // null
console.log(typeof str) // object
undefined值实际上是由null衍生出来的,所以如果比较undefined和null是否相等,会返回true
var str1 = null;
var str2 = null;
console.log(str1 == str2); // true
console.log(str1 === str2); // true