Number Object
Number object in JavaScript is used to represent numeric values. Unlike other programming languages, JavaScript does not provide different types of numbers, like integer, float, short etc. In JavaScript numbers are always stored as double precision floating point numbers. Numbers are stored in 64 bit format, where the fraction is stored in bits 0 to 51, the exponent in bits 52 to 62 and sign in bit 63. The number object is created as follows:
- var value = new Number(numberValue);
In the place of numberValue, if you provide any non-numeric parameter, it returns NaN.
In JavaScript you don’t need to create number object like above syntax because the numeric literals are treated as instances of Number class.
Note:
Don’t create Number objects. It slows down execution speed. The “new” keyword complicates the code. This can produce some unexpected results as below:
If you create numbers as:
- var x = 100;
- var y = new Number(100);
When we compare these x and y using “==” operator it returns true.
But when we use “===” operator it returns false. Because this operator checks both value and type.
If you create both numbers using “new” keyword, the “==” operator returns false because objects in JavaScript cannot be compared. So don’t create Number objects.
Hexadecimal:
JavaScript interprets numeric constants if they are prefixed by “0x”.
- var x=0xFF;
Here the value of x will be 255.
Number Properties
The following are the properties of Number.
| Property | Description |
| MAX_VALUE | Returns largest possible value in JavaScript, 1.7976931348623157E+308 |
| MIN_VALUE | Returns smallest possible value in JavaScript, 5E-324 |
| NaN | Represents value that is not number |
| NEGATIVE_INFINITY | Represents value that is less than MIN_VALUE |
| POSITIVE_INFINITY | Represents value that is greater than MAX_VALUE |

Mohammad KhalidPosted Mar 25, 2016, 3:01 AM
Very Nice article.
Ranjit PowarPosted Jan 25, 2016, 5:03 AM
Thanks
Mohammed IbrahimPosted Jan 25, 2016, 4:34 AM
nice