JavaScript Number

📘 What is Number in JavaScript?

In JavaScript, Number is a data type used to represent both integers and floating-point numbers.

let age = 25;
let price = 99.99;
            

🔢 Types of Numbers

  • Integers: 10, -5
  • Floating Point: 3.14, 0.5
  • Exponential: 1e5

⚠️ Special Number Values

console.log(Infinity);   // Infinity
console.log(-Infinity);  // -Infinity
console.log(NaN);        // Not a Number
            
⚠️ NaN appears when a mathematical operation fails.

🧰 Common Number Methods

let num = 10.567;

num.toFixed(2);     // "10.57"
Number("100");     // 100
parseInt("50px");  // 50
parseFloat("3.14"); // 3.14
            

🧪 Try It Yourself

Click the button to see number operations in action: