欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JS中typeof、Object.prototype.toString.call、constructor

程序员文章站 2022-07-08 16:53:04
...

JS中typeof、Object.prototype.toString.call、constructorJS中typeof、Object.prototype.toString.call、constructor

console.log("-----------typeof o------------");
        console.log("null\t\t\t",       typeof null);
        console.log("{}\t\t\t\t",       typeof {});
        console.log("[]\t\t\t\t",       typeof []);
        console.log("\"a\"\t\t\t\t",    typeof "a");
        console.log("new Date()\t\t",   typeof new Date());
        console.log("1\t\t\t\t",        typeof 1);
        console.log("Number(1)\t\t",    typeof Number(1));
        console.log("undefined\t\t",    typeof undefined);
        console.log("-----------Object.prototype.toString.call(o)------------");
        console.log("null\t\t\t",       Object.prototype.toString.call(null));
        console.log("{}\t\t\t\t",       Object.prototype.toString.call({}));
        console.log("[]\t\t\t\t",       Object.prototype.toString.call([]));
        console.log("\"a\"\t\t\t\t",    Object.prototype.toString.call("a"));
        console.log("new Date()\t\t",   Object.prototype.toString.call(new Date()));
        console.log("1\t\t\t\t",        Object.prototype.toString.call(1));
        console.log("Number(1)\t\t",    Object.prototype.toString.call(Number(1)));
        console.log("undefined\t\t",    Object.prototype.toString.call(undefined));
        console.log("------------o.constructor-----------");
        console.log("{}\t\t\t\t",       {}.constructor);
        console.log("{}\t\t\t\t",       {}.constructor === Object);
        console.log("[]\t\t\t\t",       [].constructor);
        console.log("[]\t\t\t\t",       [].constructor === Array);
        console.log("\"a\"\t\t\t\t",    "a".constructor);
        console.log("\"a\"\t\t\t\t",    "a".constructor === String);
        console.log("new Date()\t\t",   (new Date()).constructor);
        console.log("new Date()\t\t",   (new Date()).constructor === Date);
        console.log("Number(1)\t\t",    Number(1).constructor);
        console.log("Number(1)\t\t",    Number(1).constructor === Number);




相关标签: javascript