Math log() Method - Javascript Math

Javascript examples for Math:log

Description

The log() method returns the natural logarithm (base E) of a number.

If the parameter x is negative, NaN is returned.

If the parameter x is 0, -Infinity is returned.

Syntax

Math.log(x)

Parameter Values

Parameter Description
x Required. A number

Return Value:

A Number, representing the natural logarithm of a specified number

The following code shows how to return the natural logarithm of the number "2":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w w w . j av  a 2  s  .  c  o m*/
    document.getElementById("demo").innerHTML = Math.log(2);
}
</script>

</body>
</html>

Related Tutorials