Math.log Function (JavaScript)

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

Syntax

Math.log(number)   

Parameters

number
A number.

Return Value

If number is positive, this function returns the natural logarithm of the number. If number is negative, this function returns NaN. If number is 0, this function returns -Infinity.

Example

The following code shows how to use this function.

var numArr = [ 45.3, 69.0, 557.04, 0.222 ];  

for (i in numArr) {  
    document.write(Math.log(numArr[i]));  
    document.write("<br/>");  
}  

// Output:   
// 3.8133070324889884  
// 4.23410650459726  
// 6.322637050634291  
// -1.5050778971098575  

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: Math Object

See Also

Math.sqrt Function