Home >>JavaScript Math Reference >JavaScript log() Method

JavaScript log() Method

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 Values

Parameter Description
x It required a number.

Browser Support

Method Chrome Edge Firefox Safari Opera
log() Yes Yes Yes Yes Yes
Here is an example of JavaScript log() Method
<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>
Output:

Example 2:
<html>
<body>
<script type="text/javascript"> 
document.write("Output : " + Math.log(0)); 
</script> 
</body>
</html>
Output:

No Sidebar ads