今天在学习JS时发现 typeof 原来有8种返回类型,其中除了众所周知的7种外还有一个叫Bigint的返回类型。
MDN对于Bigint的定义是:
BigInt 是一种内置对象,可以表示大于 253 的整数。而在Javascript中,Number 基本类型可以精确表示的最大整数是 253。BigInt 可以表示任意大的整数。
BigInt 现在处在 ECMAScript 标准化过程中的 第三阶段 。 当它进入第四阶段草案,也就是最终标准时, BigInt 将成为 Javacript 中的第二种内置数值类型。
BigInt 可能会成为自 ES2015 引入 Symbol 之后,增加的第一个新的内置类型。
对这8种类型分别举几个例子: number:
typeof 123
typeof NaN
typeof Infinity
bigint:
typeof 2n
typeof 123n
function:
typeof isNaN
typeof Promise
string:
typeof "123"
object:
typeof null
typeof {}
typeof []
boolean:
typeof true
typeof false
symbol:
typeof Symbol()
undefined:
typeof undefined
typeof a