jsguides

Math.LN10

Math.LN10 is a static property of the Math object that holds the natural logarithm of 10 — approximately 2.302585092994046. It is a read-only constant; you cannot change its value.

Syntax

Math.LN10

Value

Math.LN10 holds the pre-computed value 2.302585092994046. You read it directly as a property — no function call required. Using the constant instead of Math.log(10) avoids a runtime computation each time the value is needed, and it guarantees the same bit pattern in every conforming JavaScript engine.

Math.LN10; // 2.302585092994046

This is equivalent to Math.log(10), but using the constant avoids a function call and is guaranteed to be the same value across all JavaScript engines.

Examples

The examples below progress from simply reading the constant to using it for base-10 conversions. Each pattern shows a different way Math.LN10 fits into real numerical code — from one-liners to multi-step formulas.

Accessing the constant

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

Reading the constant directly is the simplest use, but its real value appears when you convert between logarithm bases. The natural log of any number x divided by Math.LN10 gives you log base 10 of x. This is the standard change-of-base formula applied to the natural logarithm.

Converting natural log to log base 10

// log base 10 of x = ln(x) / ln(10)
function log10(x) {
  return Math.log(x) / Math.LN10;
}

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

console.log(log10(1000));
// 3

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

The log10() function defined above shows the change-of-base pattern in its simplest form. The relationship works both ways — you can verify that Math.LN10 equals Math.log(10), which confirms the conversion formula is mathematically sound.

Equivalent to Math.log(10)

Math.LN10 === Math.log(10);
// true (they hold the same value)

Knowing that Math.LN10 equals Math.log(10) is useful for verifying your understanding, but the constant’s real purpose is to avoid the function call inside formulas. The next example generalizes the change-of-base pattern to any base, not just 10, and then shows how Math.LN10 makes the base-10 case shorter.

Converting between logarithm bases

// General base conversion: log_b(x) = ln(x) / ln(b)
function logBase(x, base) {
  return Math.log(x) / Math.log(base);
}

// Same as log base 10:
logBase(1000, 10); // 3

// Using the constant directly for base 10:
function log10fast(x) {
  return Math.log(x) / Math.LN10;
}

console.log(log10fast(10000));
// 4

The general logBase() function works for any base, but log10fast() is more direct for the common base-10 case because it avoids the extra Math.log(base) call in the denominator. Once you are comfortable dividing by Math.LN10, you can apply it to practical tasks that appear in data analysis and signal processing.

Common Patterns

Normalising values on a log scale

const values = [1, 10, 100, 1000, 10000];

const logScaled = values.map(v => Math.log(v) / Math.LN10);
console.log(logScaled);
// [0, 1, 2, 3, 4]

Normalizing data onto a log scale compresses wide-ranging values into a compact range, making trends easier to spot in plots and tables. The same division by Math.LN10 also answers a simpler question: how many digits does a number have? A number’s digit count is one plus the floor of its base-10 logarithm.

Estimating number of digits

function numberOfDigits(n) {
  if (n === 0) return 1;
  return Math.floor(Math.log(Math.abs(n)) / Math.LN10) + 1;
}

console.log(numberOfDigits(9));       // 1
console.log(numberOfDigits(99));      // 2
console.log(numberOfDigits(12345));   // 5

The digit-count formula uses Math.abs() to handle negatives and special-cases zero because log(0) is -Infinity. Beyond digit counting, the base-10 logarithm appears in physics and engineering for expressing ratios that span many orders of magnitude. Decibels, for example, multiply the base-10 log of a power ratio by 10.

Working with decibels

// Decibels: dB = 10 * log10(power ratio)
function toDecibels(powerRatio) {
  return 10 * (Math.log(powerRatio) / Math.LN10);
}

console.log(toDecibels(100));
// 20

console.log(toDecibels(1000));
// 30

The decibel conversion is another case of dividing a natural log by Math.LN10 to get a base-10 result, then scaling. Each of the patterns above — normalizing, counting digits, computing decibels — relies on the same core operation. Knowing when to reach for the constant versus the dedicated Math.log10() method helps you pick the right tool for each context.

When to use Math.LN10 vs Math.log10()

For base-10 logarithms, Math.log10(x) is more concise and often more accurate than Math.log(x) / Math.LN10. The division introduces an extra floating-point operation and can accumulate rounding error. Prefer Math.log10() when the convenience method covers your use case.

// Equivalent, but log10 is cleaner and slightly more accurate
Math.log(100) / Math.LN10;  // 1.9999999999999998
Math.log10(100);             // 2 (exact)

Math.LN10 is most useful when you are building a formula that needs the constant explicitly, or when you are doing a conversion that mixes natural logs and base-10 logs in the same expression.

The Math object exposes several pre-computed logarithm constants to avoid redundant computations:

  • Math.LN10 — natural log of 10 (~2.302585)
  • Math.LN2 — natural log of 2 (~0.693147)
  • Math.LOG10E — log base 10 of e (~0.434294), the reciprocal of Math.LN10
  • Math.LOG2E — log base 2 of e (~1.442695)

These constants are especially useful in tight numerical loops where calling Math.log(10) repeatedly would waste cycles.

When Math.LN10 helps

Math.LN10 is most useful when a formula already uses natural logarithms but needs a base-10 conversion factor. It keeps the algebra visible and avoids repeating the same numeric literal in several places. That makes it easier to review formulas, copy them into other code, and spot when a calculation has switched from base e to base 10.

The constant also works well for teaching and documentation because the relationship between ln(x) and log10(x) stays visible in the source. If you only need a plain base-10 logarithm in application code, Math.log10() is usually the simpler option. But for mixed-base formulas, Math.LN10 keeps the conversion explicit and the code self-documenting.

Precision

Math.LN10 is a 64-bit IEEE 754 double-precision floating-point approximation of the true value ln(10). It is guaranteed to be the same bit pattern across all conforming JavaScript engines. Computations derived from it (like dividing by Math.LN10 to obtain a base-10 logarithm) may accumulate small rounding errors, which is why Math.log10() is preferred when available — it can apply a more accurate internal implementation.

See Also