Number Object Properties
Just like other objects, you can access the properties and methods of the number object. Let’s take a look at how to do this.
document.write( Number.MAX_VALUE + '<br>' );
document.write( Number.MIN_VALUE + '<br>' );
document.write( Number.POSITIVE_INFINITY + '<br>' );
You should be familiar with document.write() by now. We’ll be using this often instead of the alert box to show messages from now on. What’s important is what’s inside this method.
Another thing to know is that we’re adding + ‘<br’> after each number. The plus sign can be used to append values together. We’re appending a break line in HTML to better format the output. If you did everything right, you should see your page with the following output.
To be honest, you won’t be using the number object’s properties. You will most likely be using it’s methods. Let’s take a look at a few of it’s methods.
Number Object Methods
Clear your script and add this bit of code to your script.
var num = 550.343;
document.write( num.toExponential() + '<br>' );
document.write( num.toString() + '<br>' );
The toExponential() method will convert a number into exponential notation. The toString() method will convert a number into a string. If you refresh your page you should get something like this.
It’s important to note that I didn’t go over every property and method of the number object. The reason is because this object has A LOT of properties and methods. Actually, most built in objects have a lot of properties and methods. Some of them are useful and some of them are not. In this tutorial series, I will only be going over the properties and methods of an object that I believe are necessary to know. Trying to memorize all the properties and methods of an object is useless if you aren’t ever going to use them in the first place.
If you would like more information about the number object then go here.