Home >Web Front-end >JS Tutorial >How to use pow function

How to use pow function

不言
不言Original
2019-02-16 15:17:069256browse

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)

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>

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

729

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>

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

-729

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>

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

0.0013717421124828531

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!

Statement:
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