What is Math.pow() in JavaScript?

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains the pow() function, which is used to compute the power of a specified number with a specified value.

Syntax

Math.pow(base, power);

Parameter

  • base: This represents the number to be raised with power. It is of Number type.

  • power: This represents the power value. It is of Number type.

Number in JavaScript is a 64-bit double-precision value which is the same as double in C# or Java.

Return value

  • Number: It returns a base raised to the power, and its type is Number.

  • NaN: The function returns this if base < 0 and power is fractional.

Example

console.log("pow(-0.16,2) = " + Math.pow(-0.16,2));
console.log("pow(0,0) = " + Math.pow(0,0));
console.log("pow(-2,-4) = " + Math.pow(-2,-4));
console.log("pow(2,4) = " + Math.pow(2,4));
console.log("pow(-2,0.4) = " + Math.pow(-2,0.4));

Free Resources