Search w3schools.com:

SHARE THIS PAGE

JavaScript log() Method

Math Object Reference JavaScript Math Object

Example

Return the natural logarithm of the number "2":

Math.log(2);

The result will be:

0.6931471805599453

Try it yourself »

Definition and Usage

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

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

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The log() method is supported in all major browsers.


Syntax

Math.log(x)

Parameter Values

Parameter Description
x Required. A number

Return Value

Type Description
Number The natural logarithm of a specified number

Technical Details

JavaScript Version: 1.0


More Examples

Example

Use the log() method on different numbers:

var a=Math.log(2.7183);
var b=Math.log(2);
var c=Math.log(1);
var d=Math.log(0);
var e=Math.log(-1);

The result of a,b,c,d, and e will be:

1.0000066849139877
0.6931471805599453
0
-Infinity
NaN

Try it yourself »


Math Object Reference JavaScript Math Object

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The HTML5 Certificate documents your knowledge of advanced HTML5.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]