JavaScript | Math.log10() function
The Math.log10() is an inbuilt function in JavaScript which give the value of base 10 logarithms of any number.
Syntax:
Math.log10(p)
Parameters:This function accepts a single parameter p which is any number whose base 10 logarithms is to be calculated.
Returns: It returns the value of base 10 logarithms of any number.
Examples:
Input : Math.log10(5) Output: 0.6989700043360189
Explanation:
Here value of base 10 logarithms of number 5 is 0.6989700043360189 as shown output.
Input : Math.log10(10) Output:1
Let’s see some JavaScript code on this function:
- Example 1:
<script>// Different numbers are being taken// as the parameter of the function.document.write(Math.log10(1000) +"<br>");document.write(Math.log10(12) +"<br>");document.write(Math.log10(26) +"<br>");document.write(Math.log10(5));</script>chevron_rightfilter_noneOutput:
3 1.0791812460476249 1.414973347970818 0.6989700043360189
- Example 2:
<script>// Taken parameter from 1 to 19 incremented by 3.for(i = 1; i < 20; i += 3) {document.write(Math.log10(i) +"<br>");}</script>chevron_rightfilter_noneOutput:
0 0.6020599913279624 0.8450980400142568 1 1.1139433523068367 1.2041199826559248 1.2787536009528289
- Example 1:
<script>// Parameters for this function should always be a// number otherwise it return NaN i.e, not a number// when its parameter taken as string.document.write(Math.log10("gfg"));<script>chevron_rightfilter_noneOutput:
NaN
- Example 2: This function gives error when its parameter taken as complex number because it accept only integer value as the parameter.
<script>// Parametes can never be a complex number because// it accept only integer value as the parameter.document.write(Math.log10(1 + 2i));chevron_rightfilter_noneOutput:
Error: Invalid or unexpected token
Errors and exceptions: Parameters for this function should always be a number otherwise it return NaN i.e, not a number when its parameter taken as string.
Application: Whenever we need the value of base 10 logarithms of any number that time we take the help of this function.Its value needed many times in mathematics problem.
Let’s see JavaScript code for this application:
- Example 1:
<script>// taking parameter as number 14 and//calculated in the form of function.functionvalue_of_base_10_logarithms_of_any_number(){returnMath.log10(14);}document.write(value_of_base_10_logarithms_of_any_number());</script>chevron_rightfilter_noneOutput:
1.146128035678238
Supported Browsers: The browsers supported by JavaScript Math.log10( ) function are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- JavaScript | Function Parameters
- JavaScript | Function Definitions
- JavaScript | toString( ) function
- JavaScript | Math.pow( ) Function
- JavaScript | Array every() function
- JavaScript | String() Function
- JavaScript | Function Apply
- JavaScript | Function Call
- Javascript | Number() Function
- JavaScript | Math.E() function
- JavaScript | Array some() function
- JavaScript | toFixed( ) Function
- JavaScript | Array.of() function
- JavaScript | Math.abs( ) function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



