Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The Number() constructor function
takes one parameter: the numeric value being created. Below, we create a
number object for the value 456 called
numberOne.
<!DOCTYPE html><html lang="en"><body><script> var numberOne = new Number(456); console.log(numberOne); // logs '456{}' </script></body></html>
Instances from the Number()
constructor, when used with the new
keyword, produce a complex object. You should avoid creating number
values using the Number() constructor
(use literal/primitive numbers) due to the potential problems associated
with the typeof operator. The
typeof operator reports number
objects as 'object' instead of the primitive label
('number') you might expect. The literal/primitive
value is just more concise.