Latest

recent

JavaScript log() Method

Definition and Usage

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

Syntax

Math.log(x)

Parameter Description
x Required. A number


Tips and Notes

Note: If the parameter x is negative, NaN is returned.

Example

In the following example we will use the log() method on different numbers:

<script type="text/javascript">
document.write(Math.log(2.7183) + "<br />");
document.write(Math.log(2) + "<br />");
document.write(Math.log(1) + "<br />");
document.write(Math.log(0) + "<br />");
document.write(Math.log(-1));
</script>

The output of the code above will be:

1.0000066849139877
0.6931471805599453
0
-Infinity
NaN
JavaScript log() Method Reviewed by 1000sourcecodes on 02:36 Rating: 5
Powered by Blogger.