标签:bsp property 知识 note [] 技术 组成 html return
typeof 1 // "number" typeof ‘1‘ // "string" typeof true // "boolean" typeof {} // "object" typeof [] // "object" typeof function(){} // "function" typeof undefined // "undefined" typeof null // "object",注意!!!
let num = 1 num instanceof Number // false num = new Number(1) num instanceof Number // true
console.log(Object.prototype.toString.call(Object) === "[object Object]"); console.log(Object.prototype.toString.call("jerry"));//[object String] console.log(Object.prototype.toString.call(12));//[object Number] console.log(Object.prototype.toString.call(true));//[object Boolean] console.log(Object.prototype.toString.call(undefined));//[object Undefined] console.log(Object.prototype.toString.call(null));//[object Null] console.log(Object.prototype.toString.call({name: "jerry"}));//[object Object] console.log(Object.prototype.toString.call(function(){}));//[object Function] console.log(Object.prototype.toString.call([]));//[object Array] console.log(Object.prototype.toString.call(new Date));//[object Date] console.log(Object.prototype.toString.call(/\d/));//[object RegExp] function Person(){}; console.log(Object.prototype.toString.call(new Person));//[object Object]
console.log("jerry".toString());//jerry console.log((1).toString());//1 console.log([1,2].toString());//1,2 console.log(new Date().toString());//Wed Dec 21 2016 20:35:48 GMT+0800 (中国标准时间) console.log(function(){}.toString());//function (){} console.log(null.toString());//报错 console.log(undefined.toString());//报错
var arr=[1,2,3]; console.log(Array.prototype.hasOwnProperty("toString"));//true console.log(arr.toString());//1,2,3 delete Array.prototype.toString;//delete操作符可以删除实例属性 console.log(Array.prototype.hasOwnProperty("toString"));//false console.log(arr.toString());//"[object Array]"
参考:
https://www.cnblogs.com/youhong/p/6209054.html
https://www.cnblogs.com/Yance/p/7655320.html
类型判断----小白讲解typeof,instanceof,Object.prototype.toString.call()
标签:bsp property 知识 note [] 技术 组成 html return
原文地址:https://www.cnblogs.com/echo-hui/p/9551472.html