源地址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…
1.typeof 1 console.log(typeof ""); //string 2 console.log(typeof 1); //number 3 console.log(typeof true); //boolean 4 console.log(typeof null); //object 5 console.log(typeof undefined); //undefined 6 console.log(typeof []); //object 7 console.lo…
数据类型的判断 typeof typeof返回一个表示数据类型的字符串,返回结果包括:number.boolean.string.symbol.object.undefined.function等7种数据类型,但不能判断null.array等 typeof Symbol(); // symbol 有效 typeof ''; // string 有效 typeof 1; // number 有效 typeof true; //boolean 有效 typeof undefined; //undef…
有何区别,为何一定要通过call. 我们知道call是用来改变函数作用域的,Object.prototype.toString.call在这儿也是用来改变作用域的. Object.prototype.toString()  在toString方法被调用时,会执行下面的操作步骤(参考): 1. 获取this对象的[[Class]]属性的值. 2. 计算出三个字符串"[object ", 第一步的操作结果Result(1), 以及 "]"连接后的新字符串. 3. 返回第…
数据类型 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…
一.toString方法和Object.prototype.toSting.call()的区别 var arr=[1,2]; 直接对一个数组调用toString()方法, console.log(arr.toString());    //输出1,2 现在通过call方法指定arr数组为Object.prototype对象中的toString方法的上下文. console.log(Object.prototype.toString.call(arr));    //输出[Object Array…
1. Object.prototype.toString.call() 每一个继承 Object 的对象都有 toString 方法,如果 toString 方法没有重写的话,会返回 [Object type],其中 type 为对象的类型.但当除了 Object 类型的对象外,其他类型直接使用 toString 方法时,会直接返回都是内容的字符串,所以我们需要使用call或者apply方法来改变toString方法的执行上下文. const an = ['Hello','An'];an.toS…
1. Object.prototype.toString.call() 每一个继承 Object 的对象都有 toString 方法,如果 toString 方法没有重写的话,会返回 [Object type],其中 type 为对象的类型.但当除了 Object 类型的对象外,其他类型直接使用 toString 方法时,会直接返回都是内容的字符串,所以我们需要使用call或者apply方法来改变toString方法的执行上下文 const an = ['Hello','An']; an.toS…
typeof用在基本数据类型和函数时,返回其对应类型的描述,对于引用类型都返回为object. instanceof无法判断基本数据类型,对于引用类型数据,返回其其对应类型. Object.prototype.toString无论基本数据类型还是引用类型返回其对应类型. 对应测试结果如下:   typeof test instanceof Object.prototype.toString.call(test) var test = 'xuriliang'; string test instan…
使用 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…