How to get the natural logarithm (base E) of a number in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To return the natural logarithm of a number, use the JavaScript Math.log() method. If the value of a number is negative, the return value is always NaN. 

Example

You can try to run the following code to get the natural logarithm of a number −

<html>
   <head>
      <title>JavaScript Math log() Method</title>
   </head>
   <body>
      <script>
         var value = Math.log(10);
         document.write("First Value : " + value );
         
         var value = Math.log(0);
         document.write("<br />Second Value : " + value );
         
         var value = Math.log(-1);
         document.write("<br />Third Value : " + value );
         
         var value = Math.log(100);
         document.write("<br />Fourth Value : " + value );
      </script>
   </body>
</html>
raja
Published on 16-Feb-2018 07:10:35
Advertisements