Home >>JavaScript Math Reference >JavaScript log() Method
The math log() method in JavaScript returns the natural logarithm of the given number i.e base e. if the number (parameter) x is negative, NaN is returned and if in case the parameter x is 0, -Infinity is returned. It is always used as Math.log () because log () is a static method.
Syntax:Math.log (value)
Parameter | Description |
---|---|
x | It required a number. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
log() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="mylog()">Click me</button> <p id="log"></p> <script> function mylog() { document.getElementById("log").innerHTML = Math.log(5); } </script> </body> </html>
<html> <body> <script type="text/javascript"> document.write("Output : " + Math.log(0)); </script> </body> </html>