🔢Number

JSvalueprimitive ⟩ number

convert any value to Number.

+x               // any -> number, same as `Number(x)`
+x.toFixed(2)    // number -> at most 2 decimal places

BigInt can't be converted to Number(👉 TypeError )

arithmetic operator(s) do not allow to mix BigInt and Number

Be care with very small or very big numbers

const e = Number.EPSILON;         // 2^(-52)    (very small)
const BIG = Math.pow(10, 300);    // 10^300     (very big)

Number.EPSILON,               //  2.220446049250313e-16 = 2^(-52)
(0.1 + 0.2) - 0.3,            // ❗️ 5.551115123125783e-17 < e
0.1 + 0.2 === 0.3,            // ❗️ false  (should be true)
2.5 + e > 2.5,                // ❗️ false  (should be true)
BIG + 1 > BIG,                // ❗️ false  (should be true)   
BIG + 1 === BIG,              // ❗️ true   (should be false)

Last updated