js检测数据类型完美兼容所有数据类型

let a = ""//undefined/null/new Function/new Object/{}/new Date()/"" 
console.log("33",Object.prototype.toString.call(a))
console.log(Object.prototype.toString.call(a) === `[object String]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Number]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Array]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Date]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Function]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Object]`) //-------> true;
console.log(Object.prototype.toString.call(a) === `[object Null]`) //-------> true
console.log(Object.prototype.toString.call(a) === `[object Undefined]`) //-------> true

 

posted @ 2021-01-13 15:45  问问大将军  阅读(118)  评论(0编辑  收藏  举报