Home > Web Front-end > JS Tutorial > body text

How to use pow function

不言
Release: 2019-02-16 15:35:54
Original
9204 people have browsed it

The Math.pow() function in How to use pow function is used to represent the power of a number, which can return the value of x raised to the y power. Let’s take a look at the specific use of the pow function.

How to use pow function

Let’s take a look at the basic syntax of the pow function

Math.pow(base, exponent)
Copy after login

base represents the base.

exponent represents the index.

Description: If the result is an imaginary or negative number, this method will return NaN. If a floating point overflow occurs due to an exponent that is too large, this method returns Infinity.

Let’s take a look at an example of pow function application

When both base and exponent are positive numbers passed as parameters:

The code is as follows

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
</head>
<body>
<script type="text/javascript"> 
    document.write(Math.pow(9, 3)); 
</script> 
</body>
</html>
Copy after login

The execution result is as follows: 9 to the third power

729
Copy after login

When the base value is negative and exponent is positive:

The code is as follows

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
</head>
<body>
<script type="text/javascript"> 
    document.write(Math.pow(-9, 3)); 
</script> 
</body>
</html>
Copy after login

The execution result is as follows: -9 raised to the third power

-729
Copy after login

When the base value is positive and exponent is negative:

The code is as follows

<script type="text/javascript"> 
    document.write(Math.pow(9, -3)); 
</script>
Copy after login

The execution result is as follows: 1/9 to the third power

0.0013717421124828531
Copy after login

This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use pow function. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!