typeof 运算符返回一个字符串,表示操作数的类型
console.log(typeof 42);
// Expected output: "number"
instanceof 运算符用于检测构造函数的prototype属性是否出现在某个实力对象的原型链上。
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
// Expected output: true
console.log(auto instanceof Object);
// Expected output: true
constructor属性返回Object的构造函数(用于创建实例对象)
const a = new Array
a.constructor === Array // true
const o = {}
o.constructor === Object // true
let b = [];
b.constructor = String
b.constructor === String // true
b instanceof String // false
b instanceof Array // true
标签:总结,instanceof,Object,year,constructor,Expected,true,Javasricpt
From: https://www.cnblogs.com/jia-95/p/17160665.html