JS Built-ins
← Math147 / 215
Mathlog2beginner

Math.log2() β€” log2(2) = 1

πŸ“– 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: Verify that Math.log2(2) returns 1.

πŸ’‘ Hints (1)
  • β€’ log2(2) = 1 because 2^1 = 2