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

How to implement power calculation in javascript

青灯夜游
Release: 2021-10-20 15:34:50
Original
12302 people have browsed it

In JavaScript, you can use the pow() method of the Math object to implement power calculations. "Math.pow()" is an exponentiation function, and the syntax is "Math.pow(x,y)" , can return the value of x raised to the power of y.

How to implement power calculation in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In JavaScript, if you want to perform power calculations, you can use the pow() method of the Math object. Math.pow() is the exponentiation function

The syntax is

Math.pow(x,y)
Copy after login
  • x Required. base. Must be a number.​

  • #y Required. Power number. Must be a number.

can return a value representing x raised to the power of y.

Example:

console.log(Math.pow(0, 1));
console.log(Math.pow(1, 0));
console.log(Math.pow(1, 1));
console.log(Math.pow(1, 10));
console.log(Math.pow(3, 3));
console.log(Math.pow(-3, 3));
console.log(Math.pow(2, 4));
Copy after login

How to implement power calculation in javascript

Note: 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.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to implement power calculation in javascript. 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