In Javascript if you want to rise a number to a power then you have to use one of the functions from Math module: Math.pow()
The Math.pow()
function returns the base
to the exponent
power, that is, base exponent
.
Syntax
Math.pow(base, exponent)
Parameters
base
- The base number.
exponent
- The exponent used to raise the
base
.
Description
Because pow()
is a static method of Math
, you always use it as Math.pow()
, rather than as a method of aMath
object you created (Math
has no constructor).
Examples:
Math.pow(4,3); // 4 * 4 * 4 = 48