How to work Number type in JavaScript

Numbers

Number type in JavaScript includes both integer and floating-point values. JavaScript numbers are always stored as double-precision floating-point numbers, following the international IEEE 754 standard.

JavaScript also provides an object representation of numbers.

Ex:-

12
23.45
5e3

Numbers

Primitive

Constructor

Accessing Number

Number with String

NaN

The NaN property represents the “Not-a-Number” value. This property indicates that a value is not a legal number. NaN never compares equal to anything, even itself.
The NaN property is the same as the Number. Nan property.

Global isNaN ( ) Method

The isNaN() function is used to determines whether a value is an illegal number (Not-a-Number).
This function returns true if the value equates to NaN. Otherwise, it returns false.
This function is different from the Number specific Number.isNaN() method.
The global isNaN() function, converts the tested value to a Number, then tests it.

Syntax: – isNaN(value)

Infinity and – Infinity

Infinity or -Infinity is the value JavaScript will return if a number is too large or too small. All Infinity values compare equal to each other.

Ex:-
document.write(5 / 0); // infinity
document.write(- 5 / 0); // – infinity

Tagged : / / / / /