Number returns the value of a primitive number. Yes, itβs a little strange that you can also use a constructor function as a simple function, but that is how JavaScript is defined. Most built-in language types have strange and inconsistent additional features, such as, for example.
new Number creates an explicit Box object Number . Difference:
typeof Number(1) // number typeof new Number(1) // object
Unlike Java classes with primitive primitives, objects are not used at all in an explicit JavaScript Number expression.
I would not worry about using Number . If you want to be explicit, use parseFloat('09') ; if you want to be brief, use +'09' ; if you want to allow only integers, use parseInt('09', 10) .
bobince
source share