变量类型
JS按照存储方式,分为值类型和引用类型。
值类型 && 引用类型
值类型(Number、Boolean、String)
var a = 100;
var b = a;
a = 200;
console.log(b); // 100
引用类型(Object、Array、Function)
var a = {age:20};
var b = a;
b.age = 21;
console.log(a.age); // 21
typeof运算符
JS中使用typeof能得到的类型
typeof只能得到值类型的详细类型以及引用类型的function
typeof undefined // undefined
typeof "abc" // string
typeof 123 // number
typeof {} // object
typeof [] // object
typeof null // object
typeof function // function
变量计算(值类型)——强制类型转换
字符串拼接
var a = 100 + 10; //110
var b = 100 + "10"; // "10010"
==运算符
何时使用 ===和==
当需要判断是否为空的时候,使用==null,这样可以判断是否为null、undefined
其余时候使用===
100 == "100" ; // true
0 == " " ; // true
null == undefined // true