Languages
[Edit]
EN

JavaScript - Math.pow() method example

13 points
Created by:
Kia-H
546

Math.pow() is a static method that returns a base raised to the power of the exponent (value^exponent operation).

// ONLINE-RUNNER:browser;

//                     base  exponent
console.log( Math.pow(  1  ,  2       ) ); // 1
console.log( Math.pow(  2  ,  2       ) ); // 4
console.log( Math.pow(  3  ,  2       ) ); // 9

console.log( Math.pow(  0  ,  3       ) ); // 0
console.log( Math.pow(  0.5,  0.3     ) ); // 0.8122523963562356
console.log( Math.pow( -1  ,  4       ) ); // 1

console.log( Math.pow(  0  , -0.4     ) ); // Infinity
console.log( Math.pow( -0.5, -2       ) ); // 4
console.log( Math.pow( -2.0, -2       ) ); // 0.25
console.log( Math.pow(  2.0 , 0.5     ) ); // 1.4142135623730951

1. Documentation

SyntaxMath.pow(base, exponent)
Parameters

The method takes integer or float number arguments (primitive values).

  • base - base of power
  • exponent - exponent used with a base
Result

number value (primitive value) calculated as base raised to the power of exponent or NaN if the operation can not be executed.

Descriptionpow is a static method that returns a base raised to the power of the exponent (value^exponent operation).

2. Exponentiation operator (**) example

// ONLINE-RUNNER:browser;

console.log(   1    **  2   ); // 1
console.log(   2    **  2   ); // 4
console.log(   3    **  2   ); // 9

console.log(   0    **  3   ); // 0
console.log(   0.5  **  0.3 ); // 0.8122523963562356
console.log( (-1)   **  4   ); // 1

console.log(   0    ** -0.4 ); // Infinity
console.log( (-0.5) ** -2   ); // 4
console.log( (-2.0) ** -2   ); // 0.25
console.log( (-2.0) **  0.5 ); // NaN

Note: this feature has been introduced in ES2016.

Alternative titles

  1. JavaScript - Math.pow() documentation with examples
  2. js - Math.pow() method documentation with examples
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Math documentation (EN)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join