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 theNumbertype for which we want to find thelog().
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
-
Number: It returns the natural logarithm of the input parameterparam. It is of typeNumber. -
-Infinity: The function returns this if the input parameterparam= 0. -
+Infinity: The function returns this if the input parameterparam=Infinity. -
NaN: The function returns this if the input parameterparam< 0.
eis 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));