JS中typeof、Object.prototype.toString.call、constructor
程序员文章站
2022-07-08 16:53:04
...
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);
推荐阅读
-
帮你彻底搞懂JS中的prototype、__proto__与constructor(图解)
-
js中typeof运算符返回规则
-
js中关于typeof与instanceof的区别讲解
-
帮你彻底搞懂JS中的prototype、__proto__与constructor(图解)
-
typeof、instanceof、constructor 的联系、区别、应用场景(js 类型判断)
-
JS中typeof、Object.prototype.toString.call、constructor
-
JavaScript中数据类型的判断——typeof,instanceof,constructor,Object.prototype.toString.call()
-
JS中的数据类型的判断(typeof,instanceof,constructor)
-
JS中数据类型的判断( typeof,instanceof,constructor,Object.prototype.toString.call() )
-
如何判断js中的数据类型:typeof、instanceof、 constructor、 prototype方法比较