# JavaScript - Math.log1p() Method

The JavaScript Math.log1p() method returns the natural logarithm of (1 + number), i.e., log(1+number).

### Syntax

```Math.log1p(x);
```

### Parameters

 `x` Specify the number.

### Return Value

Returns the natural logarithm of (1 + x), i.e., log(1+x).
If the x is less than -1, it returns NaN.
If the x is -1, it returns -Infinity.

### Example:

In the example below, Math.log1p() method is used to calculate the log(1+number).

```var txt;

txt = "Math.log1p(0) = " + Math.log1p(0) + "<br>";
txt = txt + "Math.log1p(10) = " + Math.log1p(10) + "<br>";
txt = txt + "Math.log1p(50) = " + Math.log1p(50) + "<br>";
txt = txt + "Math.log1p(-1) = " + Math.log1p(-1) + "<br>";
txt = txt + "Math.log1p(-2) = " + Math.log1p(-2) + "<br>";
```

The output (value of txt) after running above script will be:

```Math.log1p(0) = 0
Math.log1p(10) = 2.3978952727983707
Math.log1p(50) = 3.9318256327243257
Math.log1p(-1) = -Infinity
Math.log1p(-2) = NaN
```

❮ JavaScript - Math Object

5