EN
JavaScript - Math.pow() method example
13 points
Math.pow()
is a static method that returns a base raised to the power of the exponent (value^exponent
operation).
xxxxxxxxxx
1
// base exponent
2
console.log( Math.pow( 1 , 2 ) ); // 1
3
console.log( Math.pow( 2 , 2 ) ); // 4
4
console.log( Math.pow( 3 , 2 ) ); // 9
5
6
console.log( Math.pow( 0 , 3 ) ); // 0
7
console.log( Math.pow( 0.5, 0.3 ) ); // 0.8122523963562356
8
console.log( Math.pow( -1 , 4 ) ); // 1
9
10
console.log( Math.pow( 0 , -0.4 ) ); // Infinity
11
console.log( Math.pow( -0.5, -2 ) ); // 4
12
console.log( Math.pow( -2.0, -2 ) ); // 0.25
13
console.log( Math.pow( 2.0 , 0.5 ) ); // 1.4142135623730951
Syntax | Math.pow(base, exponent) |
Parameters |
The method takes integer or float number arguments (primitive values).
|
Result |
|
Description | pow is a static method that returns a base raised to the power of the exponent (value^exponent operation). |
xxxxxxxxxx
1
console.log( 1 ** 2 ); // 1
2
console.log( 2 ** 2 ); // 4
3
console.log( 3 ** 2 ); // 9
4
5
console.log( 0 ** 3 ); // 0
6
console.log( 0.5 ** 0.3 ); // 0.8122523963562356
7
console.log( (-1) ** 4 ); // 1
8
9
console.log( 0 ** -0.4 ); // Infinity
10
console.log( (-0.5) ** -2 ); // 4
11
console.log( (-2.0) ** -2 ); // 0.25
12
console.log( (-2.0) ** 0.5 ); // NaN
Note: this feature has been introduced in ES2016.