I used var n=Number(3);
by mistake (I should have usedvar n=new Number(3);
), but I got n=3. As Number() is an object constructor, who can explain this?
An object constructor is also a function.
Number
(MDN doc) as a function can be used to convert to a primitive type number.
> Number(3)
3
> Number("3")
3
> Number("A")
NaN
> Number("2e2")
200
> Number("0xff")
255
> ["1", "2", "3"].map(Number)
[1, 2, 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With