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
发表回复