javascript Tutorial

JavaScript Numbers

Learn more about one of the world’s most popular programming languages.

Numerical information in JavaScript is represented by a data type called number. Whether the numeric value of the JavaScript numbers is a whole number, fraction, or a number with decimal point precision, numbers in JavaScript are all collectively represented as a number data type.

In JavaScript, regular numbers are always stored as double-precision floating-point numbers. Unlike other programming languages, JavaScript doesn’t define different types of numbers.

Code Example
const weight = 78.5;
const grades = 98;
const remainder = 80 % 4;

console.log(weight); // prints 78.5
console.log(grades); // prints 98
console.log(remainder); // 0

console.log(typeof weight); // prints number
console.log(typeof grades); // prints number
console.log(typeof remainder); // prints number

Infinity, -Infinity and NaN

Numbers in JavaScript can also be +Infinity, -Infinity or NaN (Not a Number) value based on the numerical calculations.

Code Example
const value = 65 / 0;
const data = -65 / 0;
const result = ‘hello’ / 10;

console.log(value); // prints Infinity
console.log(data); // prints -Infinity
console.log(result); // prints NaN

Learn JavaScript Today

Get hands-on experience writing code with interactive tutorials in our free online learning platform.

  • Free and fun
  • Designed for beginners
  • No downloads or setup required