JS深入理解

数据类型

  • 分类

    • 基本(值)类型
      • string 任意字符串
      • number 任意数字
      • boolean true / false
      • undefined undefined
      • null null
    • 对象(引用)类型
      • object 任意对象
      • function 一种特别的对象(可执行)
      • array 一种特别的对象(数值下标,内部数据是有序的)
  • 判断

    • typeof
      • typeof返回数据类型的字符串表达
      • 可以判断 undefined数值字符串布尔值
    • instanceof
      • 判断对象具体的类型
    • ===
// 判断undefined
var a;
console.log(typeof a === 'undefined'); // true
console.log(a === undefined);   // true
// 判断数字,字符串,布尔值
a = 4;
console.log(typeof a === 'number');   // true
a = 'abcd';
console.log(typeof a === 'string');   // true
a = true;
console.log(typeof a === 'boolean');   // true
console.log(a === true || false);   // true
a = null;
console.log(typeof a === 'object');   // true 不能判断
console.log(a === null);   // true
var b1 = {
    b2: [1, 'abc', console.log],
    b3: function(){
        console.log('b3');
        return function(){
            return 'dcba';
        }
    }
}
console.log(b1 instanceof Object);  // true
console.log(b1.b2 instanceof Array);  // true
console.log(b1.b3 instanceof Function);  // true
console.log(typeof b1.b3 === 'function');  // true
console.log(typeof b1.b2[2] === 'function');  // true
b1.b2[2](4);
console.log(b1.b3()());

数据,变量与内存

对象

函数

原文地址:https://www.cnblogs.com/SharkJiao/p/13828915.html