Math.log()

Math.log(x)
Returns: number · Updated March 13, 2026 · Math
math logarithm natural-log

The Math.log() function returns the natural logarithm of a number. The natural logarithm is the logarithm to the base e (Euler’s number), where e is an irrational constant approximately equal to 2.718281828459045. This function is the inverse operation of Math.exp() — if you compute Math.log(Math.exp(x)), you get x back (within floating-point precision).

Syntax

Math.log(x)

Examples

Basic usage

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

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

console.log(Math.log(Math.E * Math.E));
// 2

Values greater than 1

console.log(Math.log(2));
// 0.6931471805599453

console.log(Math.log(10));
// 2.302585092994046

console.log(Math.log(100));
// 4.605170185988092

Values between 0 and 1

console.log(Math.log(0.5));
// -0.6931471805599453

console.log(Math.log(0.1));
// -2.302585092994046

console.log(Math.log(0.01));
// -4.605170185988092

Special values

console.log(Math.log(0));
// -Infinity

console.log(Math.log(-1));
// NaN

console.log(Math.log(Infinity));
// Infinity

Common Patterns

Change of base formula

const logBase10 = (x) => Math.log(x) / Math.log(10);
const logBase2 = (x) => Math.log(x) / Math.log(2);

console.log(logBase10(100));
// 2

console.log(logBase2(8));
// 3

Logarithmic scale conversion

const toDecibels = (ratio) => 20 * Math.log10(ratio);
const fromDecibels = (db) => Math.pow(10, db / 20);

console.log(toDecibels(2));
// 6.0206 dB

console.log(fromDecibels(6));
// 1.9953 (approximately 2)

Solving exponential equations

const solveExponential = (a, b, y) => {
  // Solve for x: a * e^(b*x) = y
  return Math.log(y / a) / b;
};

console.log(solveExponential(5, 0.1, 10));
// 6.9315...

See Also