# baseToNumber
# Description
转换为数字,toNumber
的基本实现
# Params
value
# Return
Number
# Depend
import isSymbol from '../isSymbol.js'
# Code
/** Used as references for various `Number` constants. */
const NAN = 0 / 0
function baseToNumber(value) {
if (typeof value === 'number') {
return value
}
if (isSymbol(value)) {
return NAN
}
return +value
}
# Analyze
value
为number
, 直接返回value
value
为symbol
, 返回NaN
- 否者直接返回
+value
(一元正号运算符)
# Remark
# Example
baseToNumber(1) // 1
baseToNumber('3') // 3
← baseSum baseToString →