to-number-x
Converts argument to a value of type Number.
module.exports(value)
⇒ *
⏏
to-number-x
⇒ *
This method converts argument to a value of type Number. (ES2019)
Kind: static property of to-number-x
Returns: *
- The argument converted to a number.
Throws:
TypeError
- If argument is a Symbol or not coercible.
Param | Type | Description |
---|---|---|
argument | * |
The argument to convert to a number. |
Example
import toNumber from 'to-number-x';
console.log(toNumber('1')); // 1
console.log(toNumber(null)); // 0
console.log(toNumber(true)); // 1
console.log(toNumber('0o10')); // 8
console.log(toNumber('0b10')); // 2
console.log(toNumber('0xF')); // 16
console.log(toNumber(' 1 ')); // 1
console.log(toNumber(Symbol(''))); // TypeError
console.log(toNumber(Object.create(null))); // TypeError