JavaScript log2() Method
Example
Return the base 2 logarithm of different numbers:
var a = Math.log2(2.7183);
var b = Math.log2(2);
var c = Math.log2(1);
var d = Math.log2(0);
var e = Math.log2(-1);
Try it Yourself »
Definition and Usage
The log2() method returns the base-2 logarithm of a number.
Browser Support
Method | |||||
---|---|---|---|---|---|
log2() | 38.0 | 12.0 | 25.0 | 8.0 | 25.0 |
Syntax
Math.log2(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. A number |
Technical Details
Return Value: | A Number, representing the base-2 logarithm of a number If the number is -1, -Infinity is returned. If the number is less than -1, it returns NaN |
---|---|
JavaScript Version: | ECMAScript 2015 |