Converts a value to a number
将值转换为数字
The value to convert. 要转换的值
The converted number, or NaN if conversion is not possible. 转换后的数字,如果无法转换则返回 NaN
Symbols are specially handled: Number(Symbol()) would throw a TypeError, so this function returns NaN for symbols instead.
Number(Symbol())
TypeError
NaN
Symbol 被特殊处理:Number(Symbol()) 会抛出 TypeError,因此此函数对 Symbol 返回 NaN。
toNumber('42') // => 42toNumber('hello') // => NaNtoNumber(undefined) // => NaN Copy
toNumber('42') // => 42toNumber('hello') // => NaNtoNumber(undefined) // => NaN
Converts a value to a number
将值转换为数字