typeof用在基本数据类型和函数时,返回其对应类型的描述,对于引用类型都返回为object. instanceof无法判断基本数据类型,对于引用类型数据,返回其其对应类型. Object.prototype.toString无论基本数据类型还是引用类型返回其对应类型. 对应测试结果如下:   typeof test instanceof Object.prototype.toString.call(test) var test = 'xuriliang'; string test instan…
1.typeof只能判断基本类型数据, 例子: typeof 1 // "number" typeof '1' // "string" typeof true // "boolean" typeof {} // "object" typeof [] // "object" typeof function(){} // "function" typeof undefined // &quo…
Object.prototype.toString.call()判断结果: Object.prototype.toString.call(true) "[object Boolean]" Object.prototype.toString.call(1) "[object Number]" Object.prototype.toString.call(null) "[object Null]" Object.prototype.toString.…
用typeof方法只能初步判断number string undefined boolean object function symbol这几种初步类型 使用Object.prototype.toString.call(var) 能判断具体的类型数组,函数 var arr = [1,2,3]; typeof(arr); object.prototype.toString.call(arr)…
使用 typeof 来判断数据类型,只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种. 但 Object.prototype.toString.call 使用,可以区分7种 console.log(Object.prototype.toString.call(123)) //[object Number]console.log(Object.prototype.toString.call('123')) //[objec…
数据类型 js 基本类型包括:Undefined  symbol null string boolean number js 引用类型包括:object array Date RegExp typeof 我们一般用typeof来判断数据的类型的 接下来我们试试 console.log(typeof undefined) //undefined console.log(typeof Undefined) //undefined console.log(typeof Null) //undefine…
源地址https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof typeof操作符 // Numbers typeof 37 === 'number'; typeof 3.14 === 'number'; typeof Math.LN2 === 'number'; typeof Infinity === 'number'; typeof NaN === 'number'; // 尽管NaN…
关于JavaScript中的类型判断,我想大部分JavaScripter 都很清楚 typeof 和  instanceof,却很少有人知道 constructor,以及constructor与前面二者的关系 typeof console.log(typeof 1); //number console.log(typeof "宋远溪"); // string console.log(typeof true); // boolean console.log(typeof {}); //…
在JavaScript里使用typeof判断数据类型,只能区分基本类型,即:number.string.undefined.boolean.object. 对于null.array.function.object来说,使用typeof都会统一返回object字符串. 要想区分对象.数组.函数.单纯使用typeof是不行的.在JS中,可以通过Object.prototype.toString方法,判断某个对象之属于哪种内置类型. 分为null.string.boolean.number.undef…
本文由segementfalt上的一道instanceof题引出: var str = new String("hello world"); console.log(str instanceof String);//true console.log(String instanceof Function);//true console.log(str instanceof Function);//false 先抛开这道题,我们都知道在JS中typeof可以检测变量的基本数据类型. let…