typeof
操作符返回一个字符串,表示未经计算的操作数的类型。
可能返回值有:"undefined"、"object"、"boolean"、"number"、"string"、"symbol"、"function"、"object"
例:
console.log(typeof 42); // expected output: "number" console.log(typeof 'blubber'); // expected output: "string" console.log(typeof true); // expected output: "boolean" console.log(typeof declaredbutundefinedvariable); // expected output: "undefined";
instanceof运算符用于测试构造函数的prototype属性是否出现在对象的原型链中的任何位置。
即判断一个变量是否某个对象的实例。
例:
// 定义构造函数 function c(){} function d(){} var o = new c(); o instanceof c; // true,因为 object.getprototypeof(o) === c.prototype o instanceof d; // false,因为 d.prototype不在o的原型链上 o instanceof object; // true,因为object.prototype.isprototypeof(o)返回true
如对本文有疑问, 点击进行留言回复!!
使用纯前端JavaScript实现Excel导入导出方法过程详解
微信小程序完美解决scroll-view高度自适应问题的方法
网友评论