Advertisement
Google Ad Slot: content-top
JS Number
In JavaScript, numbers are used to represent both integer and floating-point values. JavaScript has only one type of number (unlike other languages which may have int, float, double, etc.).
Types of Numbers in JavaScript
- Integers: Whole numbers (e.g.,
1,42,-10) - Floating-Point Numbers: Decimal numbers (e.g.,
3.14,-0.99) - Exponential Notation: Large or small numbers using
e(e.g.,5e3is5000) - NaN (Not-a-Number): Represents an invalid number (e.g.,
parseInt("hello")) - Infinity & -Infinity: Represents positive or negative infinite values.
Example
let intNum = 42; // Integer
let floatNum = 3.14; // Floating-point number
let expNum = 2e5; // 200000
let infNum = Infinity; // Infinity
let nanValue = NaN; // Not-a-Number