Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Math:log

From MDC


Contents

[edit] Summary

Returns the natural logarithm (base E) of a number.

Method of Math

Static

Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

Math.log(x)

[edit] Parameters

x 
A number.

[edit] Description

If the value of number is negative, the return value is always NaN.

Because log is a static method of Math, you always use it as Math.log(), rather than as a method of a Math object you created.

[edit] Examples

[edit] Example: Using Math.log

The following function returns the natural log of the variable x:

function getLog(x) {
   return Math.log(x)
}

If you pass getLog the value 10, it returns 2.302585092994046; if you pass it the value 0, it returns -Infinity; if you pass it the value -1, it returns NaN because -1 is out of range.

[edit] See Also

exp, pow