jsguides

Reference

Math

Math object for mathematical functions and constants.

  1. Math.abs()

    Math.abs() returns the absolute value of a number by dropping its sign. Use it for tolerance checks, distance comparisons, and normalizing signed values.

  2. Math.ceil()

    Math.ceil() returns the smallest integer greater than or equal to a given number. Learn how it handles positive and negative numbers, edge cases, and more.

  3. Math.clz32()

    Math.clz32() returns leading zero count in 32-bit binary, useful for fast bit manipulation and log2 floor computation in performance-sensitive code.

  4. Math.E

    Math.E is the base of natural logarithms (≈2.718) — used with Math.exp() and Math.log() for compound interest, exponential growth, and radioactive decay.

  5. Math.exp()

    Math.exp() returns e raised to the power of a given number, where e is the base of the natural logarithm (approximately 2.71828).

  6. Math.floor()

    Math.floor() rounds a number down to the nearest integer, always toward negative infinity. Used for random integers, pagination, and array chunking.

  7. Math.fround()

    Math.fround() converts a number to its 32-bit single-precision float representation, matching Float32Array precision for WebGL and Web Audio APIs.

  8. Math.imul()

    Math.imul() returns the C-like 32-bit signed integer multiplication of two values, with ToUint32 coercion on each operand.

  9. Math.LN10

    Math.LN10 is the natural logarithm of 10, approximately 2.302585. Use this read-only constant for base-10 log conversions in numerical formulas.

  10. Math.LN2

    Math.LN2 is the natural logarithm of 2, approximately 0.693. Use Math.LN2 for logarithmic calculations, base conversions, and information theory work.

  11. Math.log()

    Math.log() computes the natural logarithm (base e) of a number. Covers syntax, edge-case return values, and practical uses from change-of-base to entropy.

  12. Math.log10()

    Math.log10() computes the base-10 logarithm of a number. Covers magnitude, digit counting, scientific notation, decibels, and zero or negative inputs.

  13. Math.LOG10E

    Math.LOG10E is the base-10 logarithm of Euler's number (~0.434). Use it in JavaScript to convert natural logs to base-10 and for decimal log calculations.

  14. Math.log1p()

    Math.log1p(x) computes the natural logarithm of 1 + x with high accuracy for values near zero, avoiding the precision loss that occurs with Math.log(1 + x).

  15. Math.log2()

    Math.log2() computes the base-2 logarithm of a number, essential for binary algorithms, bit depth calculations, and understanding computational complexity.

  16. Math.LOG2E

    Math.LOG2E is the base-2 logarithm of Euler's number (≈1.4427). Use math.log2e for natural-to-base-2 log conversion in bit calculations and information theory.

  17. Math.max()

    Math.max() returns the largest of zero or more numbers, returning -Infinity with no arguments and NaN if any argument cannot be converted to a number.

  18. Math.min()

    Return the lowest of zero or more numbers. Learn how Math.min() handles empty arguments, NaN, and how it compares to Math.max().

  19. Math.PI

    The ratio of a circle's circumference to its diameter, approximately 3.141592653589793. Math.PI is a read-only constant on the Math object.

  20. Math.pow()

    Raise a number to a power. Learn how Math.pow() handles integers, decimals, special values like NaN and Infinity, and how it differs from the ** exponentiati...

  21. Math.round()

    Round a number to the nearest integer. Learn how Math.round() handles .5 cases, negative numbers, and how it differs from Math.floor(), Math.ceil(), and Math...

  22. Math.sign()

    Math.sign() returns 1 for positive, -1 for negative, or 0 for zero. Useful for direction detection in games, physics, and normalizing vectors.

  23. Math.sqrt()

    Math.sqrt() computes the square root of a given number. For negative inputs it returns NaN, for zero it returns 0, and for Infinity it returns Infinity.

  24. Math.SQRT1_2

    The square root of 1/2, approximately 0.7071067811865476. Math.SQRT1_2 is a static constant used in trigonometry, geometry, and normalization calculations.

  25. Math.SQRT2

    Math.SQRT2 is the square root of 2, approximately 1.414. Use Math.SQRT2 for geometry, scaling, vector math, and diagonal calculations.

  26. Math.trunc()

    Remove fractional digits from a number. Learn how Math.trunc() differs from Math.floor(), Math.round(), and bitwise alternatives.