题目描述:写出执行结果并解释原因
function f(){}
const a = f.prototype,
b = Object.getPrototypeOf(f);
console.log(a===b);
答案:
false
解析:
- f.prototype 是使用 new 创建的 f 实例的原型。而Object.getPrototypeOf(f) 是 f 函数的原型。即去寻找 f 的构造函数的 prototype属性 即 Function.prototype
- a === Object.getPrototypeOf(new f()) //true
- b === Function.prototype //true
题目描述:写出执行结果
console.log(typeof null)
console.log(null instanceof Object)
答案:
object
false
解析:
- type of返回表示类型的字符串,
- Undefined "undefined"
- Null "object"
- Boolean "boolean"
- Number "number"
- String "string"
- Symbol "symbol"
- Function "function"
- Object "object"
- instanceof 用来检测参数是否在目标对象的原型链上