Javascript Math log2()

Introduction

The Math.log2() function returns the base 2 logarithm of a number.

Math.log2(x)   // x is a number.

If the number is negative, NaN is returned.

If x is less than 0, it returns NaN.

let a = Math.log2(3);    // 1.584962500721156
console.log(a);/*  w w w  . ja  v  a2s . com*/
a = Math.log2(2);    // 1
console.log(a);
a = Math.log2(1);    // 0
console.log(a);
a = Math.log2(0);    // -Infinity
console.log(a);
a = Math.log2(-2);   // NaN
console.log(a);
a = Math.log2(1024); // 10
console.log(a);



PreviousNext

Related