jsguides

Math.E

Math.E is a static property of the Math object that represents the base of natural logarithms, approximately 2.718281828459045. It is a read-only constant; you cannot change its value.

This irrational constant, known as Euler’s number, appears frequently in mathematics, particularly in calculus, compound interest calculations, and exponential growth or decay problems.

Syntax

Math.E

Value

Math.E is a read-only constant on the Math object, always available without instantiation or importing anything. Accessing it returns the full double-precision approximation of Euler’s number, which you can use directly in any arithmetic or function call that expects a numeric value.

Math.E; // 2.718281828459045

The constant is just a number — you can log it, compare it against other values, or pass it to any function expecting a numeric argument. The simplest use is printing its value to verify it matches the expected approximation.

Examples

Basic Usage

console.log(Math.E);
// 2.718281828459045

Printing the constant confirms the value. Its defining mathematical property is that Math.log(Math.E) equals exactly 1, since the natural logarithm is the inverse of the exponential function with base e.

Calculating natural logarithm

The natural logarithm of Math.E is always exactly 1:

console.log(Math.log(Math.E));
// 1

The log-of-E identity confirms the constant’s mathematical correctness. The companion function Math.exp() goes the other direction — it raises e to any power, which is the fundamental operation behind every real-world application of Euler’s number.

Exponential Function

Math.exp(x) calculates e^x (e raised to the power of x):

console.log(Math.exp(1));
// 2.718281828459045 (Math.E)

console.log(Math.exp(2));
// 7.38905609893065 (Math.E squared)

console.log(Math.exp(0));
// 1

Math.exp() gives you raw exponential values. A practical application is modeling continuously compounded interest, where the formula P * e^(rt) calculates the future value of an investment growing at a constant rate without discrete compounding periods.

Compound interest calculation

Math.E is useful for calculating continuously compounded interest:

function continuousCompound(principal, rate, time) {
  return principal * Math.exp(rate * time);
}

// $1000 at 5% continuously compounded for 10 years
console.log(continuousCompound(1000, 0.05, 10));
// 1648.7212707001282

// $500 at 3% continuously compounded for 5 years
console.log(continuousCompound(500, 0.03, 5));
// 580.4594377253751

Continuous compounding is common practice in finance where interest accrues constantly. The same exponential pattern models natural growth processes — populations, bacteria cultures, or viral spread — where the growth rate stays proportional to the current size.

Population growth model

Exponential growth using Euler’s number:

function populationGrowth(initial, growthRate, time) {
  return initial * Math.exp(growthRate * time);
}

// Start with 100, grow at 2% per time unit
console.log(populationGrowth(100, 0.02, 10));
// 122.14039680188982

console.log(populationGrowth(100, 0.02, 50));
// 271.8281828459045

Growth models use a positive exponent. The same formula with a negative exponent handles decay — radioactive half-lives, cooling rates, or drug metabolism — where the quantity shrinks over time at a rate proportional to what remains.

Radioactive Decay

Exponential decay also uses Euler’s number:

function radioactiveDecay(initialAmount, halfLife, time) {
  const decayConstant = Math.log(2) / halfLife;
  return initialAmount * Math.exp(-decayConstant * time);
}

// 100g sample with 30 year half-life after 100 years
console.log(radioactiveDecay(100, 30, 100));
// 9.987321192567654e-2 (approximately 10% remaining)

Decay models round out the practical applications of Math.E. Beyond real-world modeling, Euler’s number sits at the heart of mathematical identities — the most famous being Euler’s identity, which ties together five fundamental constants in a single equation.

Common Patterns

Euler’s Identity

One of the most famous equations in mathematics combines the five fundamental constants:

// e^(i*π) + 1 = 0
// This is Euler's identity, but JS can't directly compute complex numbers
// However, we can show the relationship:
console.log(Math.exp(Math.PI));
// 23.140692632779267 (e^π)

Euler’s identity is more of a mathematical curiosity than a coding tool. A more practical pattern uses exponential functions to normalize or scale values — helpful for animation curves, audio processing, or data visualization where linear scaling isn’t appropriate.

Scaling values using exponential functions

function normalizeExponential(value, min, max) {
  const range = max - min;
  const normalized = (value - min) / range;
  return min + range * Math.exp(normalized);
}

console.log(normalizeExponential(0, 1, 10));
// 2.718281828459045

console.log(normalizeExponential(0.5, 1, 10));
// 6.064943780316895

console.log(normalizeExponential(1, 1, 10));
// 10

Why use Math.E instead of a literal

Using Math.E is a small choice that improves readability. A literal like 2.718281828459045 may be technically correct, but the named constant tells the reader that the code is working with the natural exponential base. That makes formulas easier to scan and reduces the chance that someone wonders whether the number came from a measurement or a magic constant.

It also keeps related code consistent. If one part of your code uses Math.log() and another uses Math.exp(), Math.E makes it obvious that the pieces belong together mathematically. That is especially helpful in calculations involving growth curves, probability, or compound interest, where the structure of the formula matters as much as the output.

Relationship to logs and exponents

Math.E appears most often beside Math.log() and Math.exp(). Math.log() returns the natural logarithm, which uses base e, and Math.exp(x) returns e raised to the power of x. That pairing gives you a clean way to move between multiplicative growth and additive log space.

When you read formulas in code, the constant can help anchor the algebra. If you see Math.exp(rate * time), it is immediately clear that the model is exponential. That clarity is often more valuable than shaving a few characters off the literal value.

Why use Math.E?

Using Math.E instead of hardcoding 2.718281828459045 provides several advantages:

  1. Precision — The constant is defined to full floating-point precision
  2. Readability — Code clearly expresses the mathematical concept
  3. Standardization — Matches mathematical notation in formulas
  4. Performance — The value is computed once by the JavaScript engine

See Also

  • Math.exp() — returns e raised to the power of a number
  • Math.log() — returns the natural logarithm of a number
  • Math.pow() — returns the base to the exponent power