📜  javascript math.pow - Javascript (1)

📅  最后修改于: 2023-12-03 15:16:05.816000             🧑  作者: Mango

JavaScript Math.pow

The Math.pow() function in JavaScript is used to compute the power of a base number raised to an exponent. It takes two arguments: the base and the exponent.

Syntax
Math.pow(base, exponent)
Parameters
  • base: The base number.
  • exponent: The exponent which the base number will be raised to.
Return Value

The result of the base number raised to the exponent.

Examples
console.log(Math.pow(2, 3)); // Output: 8
console.log(Math.pow(10, 2)); // Output: 100
console.log(Math.pow(8, 0)); // Output: 1

In the first example, we use Math.pow() to compute 2 raised to the power of 3, which returns 8. In the second example, we compute 10 raised to the power of 2, which returns 100. In the third example, we compute 8 raised to the power of 0, which returns 1.

Notes
  • If the exponent is 0, the result is always 1.
  • If the base is negative and the exponent is a decimal, the result will be NaN.
  • If the base is negative and the exponent is an integer, the result will be either positive or negative depending on whether the exponent is even or odd.