JavaScript 常见问题
#
Primitive vs Object- Primitive
- primitive value, primitive data type
- 不是对象,没有方法,不可变
- 7 种类型 - string, number, bigint, boolean, undefined, symbol, null
- 除了 null 和 undefined 都有封装类型 - String, Number, BigInt, Boolean, Symbol
- Object
- 非 Primitive
- 集成自 Object.prototype
- Object.create(null)
- JS 中 数组为对象
- typeof
- 会返回 function, undefined, object, string, number, boolean, bigint, symbol
typeof null
会返回object
- 参考
- 性能对比 typeof vs Object()
- typeof 更快
- 性能对比 typeof vs Object()