JS Built-ins
← Math150 / 215
Mathlog2intermediate

Math.log2() β€” log2(0) = -Infinity

πŸ“– Usage Example
// Logarithm base 2
Math.log2(8)    // β†’ 3
Math.log2(256)  // β†’ 8

Use Math.log2() to compute the base-2 logarithm, useful for bit-length calculations and binary algorithms.

Math.log2()

Returns the base-2 logarithm of a number.

Challenge: Observe that Math.log2(0) returns -Infinity.

πŸ’‘ Hints (1)
  • β€’ log2 approaches -∞ as x approaches 0 from the right