JavaScript Math.LOG2E Constant

Definition
Math.LOG2E is a built-in constant that holds the base-2 logarithm of e, about 1.4426950408889634. You read it as a property. You do not call it.
Read the value, use it in your math, and check the examples below for common patterns.
Syntax
Read the constant. Start with this line.
| Usage | What it does |
|---|
Math.LOG2E | Read the base-2 logarithm of e. |
Built into JavaScript. Read Math.LOG2E directly from the Math object — no parentheses and no import required.
Library declarations
Parameters
None. Math.LOG2E is a constant (a fixed value), not a function. Do not add parentheses.
Return Value
| Return Value | Description |
|---|
| Number | About 1.4426950408889634. |
JavaScript Examples
Example 1 — Read the Value of Math.LOG2E
No parentheses are needed.
console.log(Math.LOG2E); // 1.4426950408889634
console.log(Math.LOG2E.toFixed(4)); // 1.4427
console.log(typeof Math.LOG2E); // number
1.4426950408889634
1.4427
number
How It Works
- Plain property.
Math.LOG2E is a value, not a function. - Short form.
toFixed(4) keeps 4 decimals. - Type.
typeof says it is a number. - What it means. It answers: what power of 2 gives
e?
Example 2 — Convert a Natural Log to Base 2
Multiply a natural log by Math.LOG2E to get a base-2 log.
console.log((Math.log(8) * Math.LOG2E).toFixed(4)); // 3.0000
console.log((Math.log(32) * Math.LOG2E).toFixed(4)); // 5.0000
console.log(Math.log2(8)); // 3
How It Works
- Change of base.
Math.log(x) * Math.LOG2E is the base-2 log of x. - 8. 2 × 2 × 2 is 8, so the answer is
3. - 32. 2 to the power of 5 is 32, so the answer is
5. - Shortcut.
Math.log2(8) does it in one step.
Example 3 — How Many Bits Do I Need?
To store n different choices you need about log2(n) bits, rounded up.
function bitsNeeded(n) {
return Math.ceil(Math.log(n) * Math.LOG2E);
}
console.log(bitsNeeded(5)); // 3
console.log(bitsNeeded(100)); // 7
console.log(bitsNeeded(1000)); // 10
How It Works
- Base-2 log.
Math.log(n) * Math.LOG2E tells how many times you can halve n. - Round up.
Math.ceil() gives a whole number of bits. - Examples. 5 choices need
3 bits. 100 need 7. 1000 need 10. - Careful. Exact powers of 2 can be off by one because of rounding. Use
Math.log2() for those.
Compatibility
Browser & Runtime Support
Math.LOG2E is part of the first JavaScript standard (ES1) and is Baseline Widely available in every browser and in Node.js.
✓ Baseline · ES1
Math.LOG2E
A long-standing constant. It works in Chrome, Firefox, Safari, Edge, Internet Explorer and Node.js.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportMath.LOG2E Excellent
Bottom line: Use Math.LOG2E anywhere. It works in all browsers.
Frequently Asked Questions
It is the base-2 logarithm of e, about 1.4426950408889634.
No. It is a number. Write Math.LOG2E without parentheses.
Multiply a natural log by it: Math.log(x) * Math.LOG2E gives the base-2 log of x.
They are reciprocals. Math.LOG2E is about 1 / Math.LN2.
Usually yes. Math.log2(x) is easier to read and more exact for powers of 2.
All of them. It is part of the first JavaScript standard and works in every browser and in Node.js.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful