Alternative Number Formats in JavaScript
JavaScript supports numeric literals in four bases — decimal, binary, octal, and hexadecimal — as well as scientific (exponential) notation. These are useful when working with bitwise operations, colours, file permissions, or very large or very small quantities.
Hexadecimal (base 16)
Prefix with 0x or 0X. Widely used for colour codes, memory addresses, and Unicode code points.
Binary (base 2)
Prefix with 0b or 0B. Essential for bit manipulation and understanding flags.
Octal (base 8)
Prefix with 0o or 0O. Occasionally used for Unix file permission masks.
Scientific Notation
Write 1e6 for one million or 1.5e-3 for 0.0015. The exponent indicates a power of ten.
Number.prototype.toString(radix)
Convert a number to a string in any base between 2 and 36 using num.toString(base).