The Number Object represents numerical date, either integers or floating-point numbers. In general, you do not need to worry about Number objects because the browser automatically converts number literals to instances of the number class.
Following is the syntax for creating a number object:
var val = new Number(number);
In the place of number, if you provide any non-number argument, the the argument cannot be converted into a number, it returns NaN (Not a number).
Number Properties
Number Methods
Number Instances Methods
The Number object contains only the default methods that are a part of every object's defintion.
Binary and Octal Literals
Before ES6, your best bet when it comes to binary or literal pr octal representation of integers was to just pass them to parseInt() with the radix. In ES6, you could use the 0b and 0o prefix to represent binary and octal integer literals respectively. similarly, to represent a hexadecimal value, use the 0x prefix.
The prefix can be written in upper or lower case. However, it is suggested to stick to the lowercase version.
Example of Binary Representation:
console.log(0b001)
console.log(0b010)
console.log(0b011)
console.log(0b100)
The following output is displayed on successful execution of the above code.
1
2
3
4
Example of Octal Representation:
console.log(0x010)
console.log(0x100)
The following output is displayed on successful execution of the above code:
16
256
Example of Hexadecimal Representation:
console.log(0x010)
console.log(0x100)
The following output is displayed on successful execution of the above code:
16
256