Home > Web Front-end > JS Tutorial > Tutorial on using logarithmic Math.log() method in JavaScript_Basics

Tutorial on using logarithmic Math.log() method in JavaScript_Basics

WBOY
Release: 2016-05-16 15:54:58
Original
1466 people have browsed it

This method returns the natural logarithm of a number (the base is E). If the value of the number is negative, the return value is always NaN.
Grammar

Math.log( x ) ;

Copy after login

Here are the details of the parameters:

  • x : a number.

Return value:

  • Returns the natural logarithm of a number (base E).

Example:

<html>
<head>
<title>JavaScript Math log() Method</title>
</head>
<body>
<script type="text/javascript">

var value = Math.log(10);
document.write("First Test Value : " + value ); 
 
var value = Math.log(0);
document.write("<br />Second Test Value : " + value ); 

var value = Math.log(-1);
document.write("<br />Third Test Value : " + value ); 

var value = Math.log(100);
document.write("<br />Fourth Test Value : " + value ); 
</script>
</body>
</html>

Copy after login

This will produce the following results:

First Test Value : 2.302585092994046
Second Test Value : -Infinity
Third Test Value : NaN
Fourth Test Value : 4.605170185988092 

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template