Number in ES6

In ES6, we have various methods and properties to implement numeric functions such as floating-point, integers, date, etc. The numbers in ES6 enable us to work with number objects. It is the cause of the browser that transforms number literals into number class instance. We can create a number object with the help of the Number constructor(). Sometimes the number object returns NaN. It means the argument can’t be changed into a number.

Syntax

The above syntax contains the following parameter.

value: It includes the numeric value of an object. If we pass a non-numeric argument in its place, then it returns NaN, because the related argument can’t be a number.

Methods of Number

A number object only consists of the default method, which is part of the object definition. Here, we have the following number methods that are listed below in the tabular form.

Now, we will elaborate on each method in detail with an example.

Number.isFinite()

This method determines that the value passed is finite or not. It returns true if the value is equal to a finite number. Otherwise, it returns false.

Example

Output

After the execution of the above code, we got the following output:

### Number.isNan()

It is used to define that the passed value is Nan or not. It returns true if the value is a number. Otherwise, it returns false.

Example

Here, we have an example to understand the above method.

Output

We got the following output after the successful execution of the above code:

### Number.isSafeInteger()

The Number.isSafeInteger() method defines that the passed value is a safe integer or not. The safe integer has the range of -(253 – 1) and (253- 1).

Example

Here, we have an example to understand the above method.

Output

After the successful execution of the following example, we got the following output:

### Number.isInteger()

This defines that the passed value is an integer value or not. This method returns true if the value is an integer. Otherwise, it returns false.

Example

An example is mentioned below to understand the method.

Output

After the successful execution of the code, we got the following output:

### Properties of Number

The number object contains various properties. These are listed below in the tabular form.

Here, we will try to elaborate the object’s property in the detailed form with the help of examples.

EPSILON

The EPSILON property is used to display the difference between 1 and the smallest floating-point number (greater than 1). There is no need to construct a Number object for retrieval of static property because we will use Number.EPSILON property.

Example

We have an example to understand the above property.

Output

We got the following output after the execution of the code.

### Number.MAX_VALUE

The Number.MAX_VALUE property refer to a static number object and define constants for the largest positive number.

Example

Here, we have an example for the Number.MAX_VALUE property.

Output

We have the following output, after the execution of the above code.

### Number.MAX_SAFE_INTEGER

This property is used to define that the passed value is a safe integer or not.

Example

We have an example to understand the above concept.

Output

After the successful execution of the code, we got the following output:

### Number.MIN_VALUE

The above property defines the smallest positive number.

Example

Here, we have an illustration for the same.

Output

After the execution of the following output, we got the following output:

### Number.MIN_SAFE_INTEGER

This property is used to determine the minimum safe number in JavScript.

Example

Here, we have an example to understand the above property.

Output

After the successful execution, we got the following output:

### Representation of Binary Literals

In ES6, the binary literals are represented with the help of prefix 0b, pursued by the binary numbers 1 and 0. We can write prefix in lowercase as well in uppercase.

Example

Here, we have an example for the above property.

Output

After the execution of the above example, we got the following output:

### Representation of octal Literals

The octal literals are represented using prefix 0o, pursued by the octal digit sequence (0 to 7). The combinations of digits or digits are referred as the octal literal.

Example

We have an example to elaborate the above concept.

Output

In ES6, the hexadecimal literals are represented in the form of 0x.

Example

Here, we have an example to understand the above representation.

Output

After the successful execution of the code, we got the following output: