Categories
JavaScript Web development

JavaScript Math.log10()

JavaScript Math.log10()

The JavaScript Math.log10() returns the base-10 logarithm of a number.

Syntax:

Math.log10(x)

Note: A Number, representing the base-10 logarithm of a number.
If the number is negative, NaN is returned.
If the number is 0, -Infinity is returned.

Example:

Use the Math.log10() on different numbers:

<!DOCTYPE html>
<html>
<body>

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

<script>
function log10Function() {
  var a = Math.log10(3.234);
  var b = Math.log10(2);
  var c = Math.log10(1);
  var d = Math.log10(0);
  var e = Math.log10(-1);

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

</body>
</html>

Output:


Enjoy coding!

Read also:

JavaScript Math Object

JavaScript Math.log()

JavaScript Math Object Properties