Fundamentals

Numbers in JavaScript

The Number Type

JavaScript uses a single Number type to represent both integers and floating-point numbers.

let a = 10;
let b = 3.14;
let c = 10 / 3; // 3.3333333333333335

Useful Number Methods

  • Number.isInteger(5) — checks if a value is an integer.
  • parseInt("42") — converts a string to an integer.
  • parseFloat("3.14") — converts a string to a floating-point number.
  • toFixed(2) — rounds a number to a fixed number of decimal places.
  • Math.round(), Math.floor(), Math.ceil() — rounding utilities.

Special Numeric Values

NaN (Not a Number), Infinity, and -Infinity are special values within the Number type.

Ready to master real-world JavaScript development?

Learn JavaScript hands-on with mentor-led, live sessions.

Explore Course