Number (integers, floats, NaN, Infinity)
The number type represents both integers and floating‑point numbers.
let integer = 42;let float = 3.14;let negative = -10;let scientific = 2.5e3; // 2500Special numeric values:
NaN (Not‑a‑Number): result of an invalid or undefined mathematical operation.
let result = "hello" * 5; // NaNconsole.log(isNaN(result)); // trueInfinity and -Infinity: represent mathematical infinity.
let tooBig = 1 / 0; // Infinitylet tooSmall = -1 / 0; // -InfinityNumber methods:
Number.isInteger(), Number.isNaN(), Number.parseFloat(), Number.parseInt().
console.log(Number.isInteger(42)); // trueconsole.log(Number.parseInt("123px")); // 123Precision issues: Floating point arithmetic is not always exact.
console.log(0.1 + 0.2); // 0.30000000000000004Use toFixed() or libraries for exact decimal calculations.