1. typeof
返回值: string number boolean function object undefined
其中通过typeof null 返回:object
2. constructor
返回值:String Boolean Number Array Date Function Object ...
看示例:
//constructor
function test3() {
var s = "123";
var n = 1000.111;
var f = true;
var arr = [1, 2, 3];
var json = {1: "123", obj: "number"};
var fun = new Function();
var fun2 = function() {return test1};
var date = new Date();
var obj = new Dog();
function Dog() {
this.dog = "dog";
}
// alert([].constructor);
// console.log(null.constructor, undefined.constructor); //报错 null和undefined不存在property
// 备注: 很有趣的现象:
//数值直接量没有constructor属性,不过通过括号运算符就能解决:
//如: (10).constructor
console.log(f.constructor, f.constructor === Boolean);
console.log(s.constructor, s.constructor === String, n.constructor, n.constructor === Number);
//ff的console出现bug
// [].constructor === Array
console.log(arr.constructor, [].constructor, "array", Array.constructor, new Array().constructor, "json", json.constructor);
console.log("fun", fun.constructor, "func2", fun2.constructor);
console.log("date", date.constructor, "obj", obj.constructor);
console.log(Object.constructor === Function, Function.constructor === Function)
}
test3();