ES6 Number has several methods and properties to perform numeric functions that has the date, floating points, integers, etc. Using Numbers in ES6, we can easily work with the Number objects. It is because the browser automatically converts number literals to instances of the number class.
The Number object is created by using the Number() constructor. Some of the primary uses of the Number object include NaN, which will return when the argument cannot be converted into a number.
Value: It is the numeric value of the object being created. If we give any non-number argument in place of it, then it returns NaN because the corresponding argument cannot be converted into a number.
Let us see some of the properties of Number object which are introduced in ES6 are tabulated as follows:
Let us try to elaborate on the Number properties introduced in ES6.
This property represents the difference between 1 and the smallest floating-point number, which is greater than 1. We do not have to create a Number object for accessing the static property because we can simply use Number.EPSILON property.
This property belongs to the static Number object and represents constants for the largest possible positive numbers.
Number.MAX_VALUE equals to: 1.7976931348623157e+308
Number. MIN_SAFE_INTEGER equals to: -9007199254740991
It represents the smallest positive numeric value.
Number.MIN_VALUE equals to : 5e-324
The Number object contains only default methods that are part of every object's definition. The methods of the number object are tabulated as follows:
Let us try to elaborate on the above Number methods introduced in ES6.
It determines whether the value is Nan or not. It returns true if the value is not a number.
true false false
It determines whether a value is a finite number or not. It returns true if the value is of the Number type and equates to a finite number. Otherwise, it returns false.
false true false
As its name implies, it determines whether the passed value is an integer or not. It returns true if the value is a number and must be an integer (number without decimals). Otherwise, it returns false.
true true false
A safe integer is an integer which is in the range of - (253 - 1) and (253-1). The Number.isSafeInteger() method determines whether or not the value is a safe integer.
true false true true
Binary, Octal and Hexadecimal Literals
ES6 added support for binary literals and changed the way of representing the literals. Let's see the representation of the literals in ES6.
Binary Literals representation
Binary literals in ES6 are represented by using the 0b prefix, followed by the sequence of binary numbers, which are 0 and 1.
The prefix can be written in lowercase as well as in uppercase. However, the lowercase is recommended for the prefix.
2 6 5 4
Octal Literals representation
Octal literals in ES6 are represented by using the 0o prefix, followed by the sequence of octal digits (from 0 to 7). We cannot include a digit or the combination of digits in octal literal that is out of range (0 to 7).
28 519 193180
Hexadecimal Literals representation
Hexadecimal literals in ES6 are represented by using the 0x prefix
1656 256 1928