# JavaScript Numbers

A JavaScript number is any positive or negative integer, float, double, short, long and yes, just any mathematically correct number you may think of. Unlike, some statistically typed programming languages, JavaScript does not require you to specify if a number is an integer or float or double. Once a number is mathematically correct, it is a JavaScript number and can be used in arithmetic operations.
``````1;
109;
2.00;
3.45;
1E5; //100000
2e6; //2000000
1E-5; //0.00001
2e-6; //0.000002
-1;
-109;
-2.00;
-3.45;
-1E5; //-100000
-2e6; //-2000000
-1E-5; //-0.00001
-2e-6; //-0.000002``````
NaN The JavaScript NaN stands for "Not a Number". It is a reserved keyword that is returned when a number is not mathematically correct or not acceptable in JavaScript. For example, if you multiply a number with a string, "NaN" is returned.
``````<script>
</script>``````
Number Object Though numbers are primitive data types yet there exists an object that can be used in creating or manipulating them. Below is how a number can be created using the Number object prototype.
``````<script>
var num = new Number(134);

num = new Number(1e5);
</script>``````
As you can see, creating numbers explicitly e.g 124 is easier and better than using the Number object prototype. You can manipulate numbers whether created explicitly or implicitly using the properties or methods of the Number object. For example, you can use the toString() method to convert numbers, which are originally hexadecimal, to any base.
``````<script>
var num = 5; //Hexadecimal or base 10
alert(num.toString(8)); //converts to octal or base 8
</script>``````
Number's typeof() Using the typeof() operator on a number or variable containing a number (including NaN) will return number. Therefore, to test if a value is a number or not, use the typeof() operator on the value.
``````<script>
var num = 50;
</script>``````
1. A JavaScript number is any positive or negative integer, float or double.
2. Unlike strictly typed programming languages, in JavaScript, you don't need to further specify what kind(integer, float, double, short, long) is a number.
3. NaN is a JavaScript reserved keyword that means a number is not valid or acceptable in JavaScript.
4. Though primitive, JavaScript numbers have an object.
5. We can use the object to create new numbers or use its properties and methods to manipulate numbers created explicitly or implicitly.
6. The typeof operator when used on numbers will return number.
Take a short quiz on JavaScript Numbers.
Ask a question or tell us if JavaScript Numbers is easy or not.
cent?

We won't spam your mail box. We hate it.