Numbers in JavaScript

Data Types

Numbers in JavaScript

🙋 Need help? Ask an expert now!

All numbers in JavaScript are stored internally as double-precision floating-point numbers, following the IEEE-754 Standard. Integers are accurate up to 15 digits while decimals are accurate up to 17 digits.

Extremely large or small numbers such as 10^9 or 10^-9 can be written using scientific notation if necessary. Numbers can be wrapped as objects of type Number, which essentially does the same thing and creates a number according to the data type.

The sample code above shows four different examples of variables holding numbers. The first line shows an integer declaration as the integer 5 is being declared into the variable value. The second line assigns a rough estimate of PI into the variable pi. The third line creates a new object using new Number(), which essentially does the same thing as the two statements above. Creating Number objects slows down execution speed and complicates the code, so is not recommended. The last variable declaration assigns biggestNum to the maximum value of a number, which is approximately 1.8 x 10^308. The minimum value for JavaScript numbers is 5 x 10^-324. This gives you an opportunity to create a variety of programs that use big or small numbers.

Edit Me on GitHub!

Application Question

Consider the following code segment:

let pi = 3.14159.....;

What will be printed on the console after running the code above?