JavaScript Math.LOG2E Constant

Beginner
5 min read
Updated: Nov 2026
3 examples
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.

JavaScript
Math.LOG2E
UsageWhat it does
Math.LOG2ERead 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
JavaScript
Math.LOG2E

Parameters

None. Math.LOG2E is a constant (a fixed value), not a function. Do not add parentheses.

Return Value

Return ValueDescription
NumberAbout 1.4426950408889634.

JavaScript Examples

Example 1 — Read the Value of Math.LOG2E

No parentheses are needed.

JavaScript
console.log(Math.LOG2E); // 1.4426950408889634
console.log(Math.LOG2E.toFixed(4)); // 1.4427
console.log(typeof Math.LOG2E); // number
Try It Yourself

How It Works

  1. Plain property. Math.LOG2E is a value, not a function.
  2. Short form. toFixed(4) keeps 4 decimals.
  3. Type. typeof says it is a number.
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Change of base. Math.log(x) * Math.LOG2E is the base-2 log of x.
  2. 8. 2 × 2 × 2 is 8, so the answer is 3.
  3. 32. 2 to the power of 5 is 32, so the answer is 5.
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Base-2 log. Math.log(n) * Math.LOG2E tells how many times you can halve n.
  2. Round up. Math.ceil() gives a whole number of bits.
  3. Examples. 5 choices need 3 bits. 100 need 7. 1000 need 10.
  4. Careful. Exact powers of 2 can be off by one because of rounding. Use Math.log2() for those.

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 support
Math.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.

Next: PI

Learn about the number pi, about 3.14159.

PI tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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