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

## Description

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.

## Syntax

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

`Math.log(number);`

Parameters or Arguments

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

## Returns

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.

## Note

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

## Example

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

For example:

```
console.log(Math.log(1));
console.log(Math.log(2.5));
console.log(Math.log(0));
console.log(Math.log(-4));
```

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:

```
0
0.9162907318741551
-Infinity
NaN
```

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.

## Leave a Review