Open In App

JavaScript Math log10() Method

Last Updated : 15 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Javascript Math.log10() is an inbuilt method in JavaScript that gives the value of base 10 logarithms of any number.

 Syntax:

Math.log10(p)

Parameters: This method 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

Let’s see some JavaScript code on this method:

Example: This example gives the log with the base 10 of various numbers using the Math.log10() method.

javascript




<script>
    // Different numbers are being taken
    // as the parameter of the method.
    console.log(Math.log10(1000));
    console.log(Math.log10(12));
    console.log(Math.log10(26));
    console.log(Math.log10(5));
</script>a


Output:

3
1.0791812460476249
1.414973347970818
0.6989700043360189

Example: In this example, a for loop is used for the numbers between 1 to 19 with an increment of 3 to get the value of their logs.

javascript




<script>
    // Taken parameter from 1 to 19 incremented by 3.
    for (i = 1; i < 20; i += 3) {
        console.log(Math.log10(i));
    }
</script>


Output:

0
0.6020599913279624
0.8450980400142568
1
1.1139433523068367
1.2041199826559248
1.2787536009528289

Example: This example returns Nan as a string is passed as a parameter.

javascript




<script>
    // Parameters for this method should always be a
    // number otherwise it return NaN i.e, not a number
    // when its parameter taken as string.
    console.log(Math.log10("gfg"));
</script>


Output:

NaN

Example: This method gives an error when its parameter is taken as a complex number because it accepts only integer value as the parameter. 

javascript




<script>
// Parameters can never be a complex number because
// it accept only integer value as the parameter.
    console.log(Math.log10(1 + 2i));
</script>


Output:

Error: Invalid or unexpected token

Application: Whenever we need the value of base 10 logarithms of any number that time we take the help of this method. Its value is needed many times in mathematics problems. 

Let’s see the JavaScript code for this application:

Example: This example demonstrates the above-explained approach.

javascript




<script>
    // taking parameter as number 14 and
    //calculated in the form of method.
    function value_of_base_10_logarithms_of_any_number()
    {
        return Math.log10(14);
    }
        console.log(value_of_base_10_logarithms_of_any_number());
</script>


Output:

1.146128035678238

We have a complete list of Javascript Math methods, to check those please go through this JavaScript Math Object Complete Reference article.

Supported Browsers: The browsers supported by JavaScript Math.log10( ) method are listed below:

  • Google Chrome 1 and above
  • Internet Explorer 3 and above
  • Firefox 1 and above
  • Opera 3 and above
  • Safari 1 and above


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads