Categories
Web development

JavaScript Math.log1p()

JavaScript Math.log1p()

The JavaScript Math.log1p() returns the natural logarithm (base E) of 1 + a defined number.

Syntax:

Math.log1p(number)

Note: A Number, representing the natural logarithm (base E) of 1 + the defined number.
If the number is -1, -Infinity is returned.
If the number is less than -1, it returns NaN.

Example:

<!DOCTYPE html>
<html>
<body>

<button onclick="log1pFunction()">Try it</button>
<p id="example"></p>

<script>
function log1pFunction() {
  var a = Math.log1p(2.254);
  var b = Math.log1p(2);
  var c = Math.log1p(1);
  var d = Math.log1p(0);
  var e = Math.log1p(-1);
  var f = Math.log1p(-2);

  var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f;
  document.getElementById("example").innerHTML = x;
}
</script>

</body>
</html>

Output:

Return the natural logarithm (base E) of 1 + different numbers:


Enjoy coding!

Read also:

JavaScript Math Object

JavaScript Math Object Properties

JavaScript Math.log()