Languages
[Edit]
EN

ES7 / ES2016 / ECMAScript 2016 - Exponentiation operator (**) example

3 points
Created by:
Root-ssh
175400

In this article, we would like to show you how to use Exponentiation Operator (**) that has been introduced in ECMAScript 2016.

1. 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:

For negative literal base values we need to use brackets becase of the syntax error, e.g.

  • (-2.0) ** 0.5 - correct syntax
  • -2.0 ** 0.5 - incorrect syntax

See also

  1. JavaScript - Math.pow() method example
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.
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