del

num = 123;
str = "123";

alert(num == 123); //true
alert(str == 123); //true

alert(num === 123); //true; 值相同且类型相同
alert(str === 123); //false

alert(typeof num === "number"); //true
alert(typeof str === "string"); //true

//数组的类型也是 object
alert(typeof []); //object
alert(typeof {}); //object


//判断是否是数组的函数
var isArray = function (obj) {
    //return obj && !(obj.propertyIsEnumerable(\'length\')) && typeof obj === \'object\' && typeof obj.length === \'number\';
    return obj instanceof Array;
};

arr = [ 1, 2, 3 ];
obj = { a: 1, b: 2, c: 3 };
alert(isArray(arr)); //true
alert(isArray(obj)); //false
alert(isArray(num)); //false
alert(isArray(str)); //false

分类:

技术点:

相关文章:

  • 2021-11-18
  • 2021-12-09
  • 2021-11-20
  • 2021-11-17
  • 2021-11-30
  • 2021-11-30
  • 2021-06-30
  • 2021-10-31
猜你喜欢
  • 2021-11-17
  • 2021-11-27
  • 2021-11-28
  • 2021-10-15
  • 2021-10-03
  • 2021-11-18
  • 2021-11-18
相关资源
相似解决方案