原始类型
- Number
- String
- Boolean
- undefined
- null
- Symbol (es6新增数据类型)
- BigInt
对象类型
- object (包含 , Array , Map,Weekmap, Set,WeekSet, Data)
typeof 仅适用于检测原始数据类型
- undefined:typeof instance === “undefined”
- Boolean: typeof instance === “boolean”
- Number:typeof instance === “number”
- String:typeof instance === "string
- BigInt:typeof instance === “bigint”
- Symbol :typeof instance === “symbol”
- null:typeof instance === “object”。
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);
console.log(auto instanceof Object);