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 ofNumbertype. -
power: This represents the power value. It is ofNumbertype.
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
-
Number: It returns abaseraised to thepower, and its type isNumber. -
NaN: The function returns this ifbase< 0 andpoweris 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));