Math.log
Returns the natural logarithm (base e) of a number
Syntax
Math.log(x)Parameters
| Parameter | Type | Description |
|---|---|---|
| x | number | A positive number |
Return Value
The natural logarithm of x, or NaN if x < 0
Examples
console.log(Math.log(1)); // 0
console.log(Math.log(Math.E)); // 1console.log(Math.log(10)); // 2.302585092994046
console.log(Math.log(100) / Math.log(10)); // 2 (log base 10)console.log(Math.log(0)); // -Infinity
console.log(Math.log(-1)); // NaNUnderstanding Math.log
The Math.log method in JavaScript returns the natural logarithm (base e) of a number. It belongs to the Math object and is one of the most widely used methods for working with math values in modern JavaScript and TypeScript applications.
The method signature is Math.log(x). It accepts 1 parameter: x. When called, it returns the natural logarithm of x, or nan if x < 0. Understanding when and how to use log() helps you write more expressive, readable code.
Common use cases for Math.log include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like math-log2, math-log10, math-pow, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Math.log is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Math Methods
Other methods in the Math object
Related Tools
More Math Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.