值类型:每个变量存储的是各自的值,不会相互影响。
引用类型:存储的是引用地址。
在JavaScript中值类型的类型判断用typeof,引用类型的判断用instanceof。
typeof undefined; // undefined
typeof 'abc'; // string
typeof 123; // number
typeof true; // boolean
typeof {}; // object
typeof []; // object
typeof null; // object
typeof console.log; // function
从以上代码可看出,typeof可识别出值类型的详细类型(undefined, number, string ,boolean),但在判断引用类型时,返回值只有object/function,无法判断它到底是一个object对象,还是数组,这时就要用到instanceof。