Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Number() > Number() Parameters

Number() Parameters

The Number() constructor function takes one parameter: the numeric value being created. Below, we create a number object for the value 456 called numberOne.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var numberOne = new Number(456);

console.log(numberOne); // logs '456{}'

</script></body></html>

Note

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.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint