log()  Math  class method JS Home  <<  JS Reference  <<  Math  <<  log()

Description

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

  • Like all class methods log() should be used on the class rather than an instance of the class.

Syntax

Signature Description
Math.log(value)Returns the natural logarithm of a number (base E).

Parameters

Parameter Description
valueThe value you wish to find the log() of:
  • Negative numbers returns NaN.
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null or 0 returns -Infinity.

Examples

The code below displays log() usage.


// Store results in an array.
var logValues = new Array(5);

logValues[0] = Math.log(-1);
logValues[1] = Math.log(0);
logValues[2] = Math.log('0.75');
logValues[3] = Math.log('a string');
logValues[4] = Math.log();
logValues[5] = Math.log(null);

alert(logValues);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math