ES6 – Number Primitive Datatype

ES6 – Number Primitive Datatype

JavaScript uses a fixed number 64 bits to store a single number value. This makes too many patterns available to create a number. Given 65 binary digits you can represent 10N numbers, this can represented as 264 different numbers. Which is about 18 quintillion (18,000,000,000,000,000,000), that is a huge number.

JavaScript Numbers:

Computers were used to be much smaller in early days, so groups of 8 or 16 bits were used to represent numbers. So memory would be easily be overflown by numbers. But today even small computer that fits in your pocket have plenty of memory to store any large number with less likely to overflow the memory.

Bits also can store any negative number by designating one bit for the sign (+, -) for that number that uses it.

Example: let num = 7

JavaScript Decimal Numbers:

To store decimal numbers in JavaScript some bits are used to store the position of the decimal point. In this case the maximum number that can be stored is in range of quadrillion (15 zeros), that is still a huge number to use. However, number less than than 9 quadrillion are guaranteed to always be precise. But calculation with decimal numbers are generally approximations not as precise values.

Decimal or functional numbers in JavaScript are written by using a dot:

Example: let num = 8.9

JavaScript Scientific Notation:

JavaScript uses scientific notation to store small mostly large numbers by adding an e for exponent followed by exponent of the number.

Example: let num = 5.76e8 that is 576 x 108 = 299800000

JavaScript Special Numbers:

There are three special values in JavaScript that are considered numbers but don’t behave like a normal numbers.

  • Infinity
  • -Infinity
  • NaN

The Infinity and -Infinity numbers that represent the positive and negative infinity numbers in mathematics,  These cannot be trusted in computation which leads to NaN special number.

NaN stands for “not a number” and that is still consider as a value type in JavaScript. Generally this number can be generated as result of 0/0 (zero divided by zero), to Infinity and this would not be a meaningful number.


// Literal syntax
let num1 = 980
let num2 = 980.00
num1 === num2 // true


// Function syntax
let num3 = Number(980) // 980
Number(“number”) // NaN