网站运营专员是干嘛的,网站ui设计师培训,链接网站开发需要多少钱,wordpress首页缩略图插件typeof
对于基本类型#xff0c;除 null 以外#xff0c;均可以返回正确的结果。对于引用类型#xff0c;除 function 以外#xff0c;一律返回 object 类型。对于 null #xff0c;返回 object 类型。对于 function 返回 function 类型。
typeof; // string 有效
typeo…typeof
对于基本类型除 null 以外均可以返回正确的结果。对于引用类型除 function 以外一律返回 object 类型。对于 null 返回 object 类型。对于 function 返回 function 类型。
typeof; // string 有效
typeof1; // number 有效
typeofSymbol(); // symbol 有效
typeoftrue; //boolean 有效
typeofundefined; //undefined 有效
typeofnull; //object 无效
typeof[] ; //object 无效
typeofnewFunction(); // function 有效
typeofnewDate(); //object 无效
typeofnewRegExp(); //object 无效
Array.isArray()
只能辨别数组
console.log(Array.isArray([])) //true
toString
toString() 是 Object 的原型方法调用该方法默认返回当前对象的 [[Class]] 。这是一个内部属性其格式为 [object Xxx] 其中 Xxx 就是对象的类型。
对于 Object 对象直接调用 toString() 就能返回 [object Object] 。而对于其他对象则需要通过 call / apply 来调用才能返回正确的类型信息。
Object.prototype.toString.call() ; // [object String]
Object.prototype.toString.call(1) ; // [object Number]
Object.prototype.toString.call(true) ; // [object Boolean]
Object.prototype.toString.call(Symbol()); //[object Symbol]
Object.prototype.toString.call(undefined) ; // [object Undefined]
Object.prototype.toString.call(null) ; // [object Null]
Object.prototype.toString.call(newFunction()) ; // [object Function]
Object.prototype.toString.call(newDate()) ; // [object Date]
Object.prototype.toString.call([]) ; // [object Array]
Object.prototype.toString.call(newRegExp()) ; // [object RegExp]
Object.prototype.toString.call(newError()) ; // [object Error]
Object.prototype.toString.call(document) ; // [object HTMLDocument]
Object.prototype.toString.call(window) ; //[object global] window 是全局对象 global 的引用