JavaScript log2() method
- Previous Page log1p()
- Next Page LOG2E
- Go Back to Previous Level JavaScript Math Reference Manual
Definition and usage
log2()
The method returns the logarithm base 2 of the number.
Example
Return the logarithm base 2 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);
Syntax
Math.log2(x)
Parameter value
Parameter | Description |
---|---|
x | Required. A number. |
Technical details
Return value: |
A number representing the logarithm of the number with base 2.
|
---|---|
JavaScript Version: | ECMAScript 2015 |
Browser Support
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
log2() | 38.0 | 12.0 | 25.0 | 8.0 | 25.0 |
Related Pages
Tutorial:JavaScript Math
- Previous Page log1p()
- Next Page LOG2E
- Go Back to Previous Level JavaScript Math Reference Manual