What is Math.log10() in JavaScript?
Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains the log10() function, which is used to compute the base 10 logarithm of a specified number.
Syntax
Math.log10(param);
Parameter
param: This is the input value of typeNumberfor which we want to find thelog10().
Numberin JavaScript is a 64-bit double-precision value that is the same asdoublein C# or Java.
Return value
-
Number: It returns the base 10 logarithm of the input parameterparam. It is of typeNumber. -
-Infinity: The function returns this if the input parameterparam= 0. -
+Infinity: The function returns this if the input parameterparam=+Infinity. -
NaN: The function returns this if the input parameterparam< 0 orparam=-Infinity.
Example
console.log("log10(-1) = " + Math.log10(-1));console.log("log10(0) = " + Math.log10(0));console.log("log10(1) = " + Math.log10(1));console.log("log10(20) = " + Math.log10(20));console.log("log10(∞) = " + Math.log10(Infinity));console.log("log10(-∞) = " + Math.log10(-Infinity));