Using Math log() function to coding in Javascript/JS

This JavaScript tutorial explains how to use the math feature referred to as log() with syntax and examples.


In JavaScript, log() is a function that is used to return the natural logarithm of a number. Because the log() function is a static function of the Math object, it have to be invoked via the placeholder object referred to as Math.


In JavaScript, the syntax for the log() characteristic is:


Parameters or Arguments

number The wide variety to use in the calculation. It need to be a fee that is larger than 0


The log() feature returns the natural logarithm of a number.

If the number is 0, the log() feature will return -Infinity.

If the quantity is a terrible value, the log() feature will return NaN.


Math is a placeholder object that contains mathematical features and constants of which log() is one of these functions.


Let’s take a seem to be at an example of how to use the log() characteristic in JavaScript.

For example:


In this example, we have invoked the log() characteristic the use of the Math class.

We have written the output of the log() feature to the net browser console log, for demonstration purposes, to show what the log() feature returns.

The following will be output to the web browser console log:


In this example, the first output to the console log back 0 which is the natural logarithm of 1.

The 2d output to the console log lower back 0.9162907318741551 which is the herbal logarithm of 2.5.

The second output to the console log again -Infinity on account that the quantity provided was zero

The 2d output to the console log back NaN since the variety supplied was a bad value.