What is Math.log() in JavaScript?

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains the log() function, which is used to compute the natural log of a specified number. Natural log is the log to the base e.

Syntax

Math.log(param);

Parameter

  • param: This is the input value of the Number type for which we want to find the log().

Number in JavaScript is a 64-bit double-precision value which is the same as double in C# or Java.

Return value

  • Number: It returns the natural logarithm of the input parameter param. It is of type Number.

  • -Infinity: The function returns this if the input parameter param = 0.

  • +Infinity: The function returns this if the input parameter param = Infinity.

  • NaN: The function returns this if the input parameter param < 0.

e is known as the Euler Number, and its value is equal to approximately 2.71828.

Example

console.log("log(-1) = " + Math.log(-1));
console.log("log(0) = " + Math.log(0));
console.log("log(1) = " + Math.log(1));
console.log("log(20) = " + Math.log(20));
console.log("log(∞) = " + Math.log(Infinity));
console.log("log(-∞) = " + Math.log(-Infinity));

Free Resources