Math.exp()

Math.exp(x)
Returns: number · Updated March 13, 2026 · Math
math exponential logarithm

The Math.exp() function returns e (the base of natural logarithms) raised to the power of the argument x. This is equivalent to e^x, where e is Euler’s number, an irrational constant approximately equal to 2.718281828459045. This function is the inverse operation of Math.log(), which computes the natural logarithm.

Syntax

Math.exp(x)

Examples

Basic usage

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

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

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

Negative exponents

console.log(Math.exp(-1));
// 0.36787944117144233

console.log(Math.exp(-2));
// 0.1353352832366127

Using with variables

const calculateGrowth = (years) => {
  const principal = 1000;
  const rate = 0.05; // 5% annual growth
  const amount = principal * Math.exp(rate * years);
  return amount;
};

console.log(calculateGrowth(10));
// 1648.7212707001282

console.log(calculateGrowth(20));
// 2718.281828459045

Exponential decay

const calculateDecay = (initial, halfLife, time) => {
  const decayConstant = Math.log(2) / halfLife;
  return initial * Math.exp(-decayConstant * time);
};

// Carbon-14 half-life is about 5730 years
console.log(calculateDecay(100, 5730, 5730));
// 50

console.log(calculateDecay(100, 5730, 11460));
// 25

Common Patterns

Compound interest calculation

const compoundInterest = (principal, rate, time, compoundsPerYear) => {
  return principal * Math.exp(rate * time);
};

console.log(compoundInterest(5000, 0.07, 10));
// 10065.30 (approximately)

Population growth model

const populationGrowth = (initial, growthRate, time) => {
  return initial * Math.exp(growthRate * time);
};

const initialPopulation = 1000;
const growthRate = 0.025; // 2.5% growth per unit time

console.log(populationGrowth(initialPopulation, growthRate, 20));
// 1648.72 organisms

Gaussian (normal) distribution

const gaussian = (x, mean, sigma) => {
  const coefficient = 1 / (sigma * Math.sqrt(2 * Math.PI));
  const exponent = -Math.pow(x - mean, 2) / (2 * Math.pow(sigma, 2));
  return coefficient * Math.exp(exponent);
};

console.log(gaussian(0, 0, 1));
// 0.3989422804014327

See Also