Languages
[Edit]
EN

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

3 points
Created by:
Root-ssh
68600

In ECMAScript 2016 Exponentiation Operator (**) has been introduced. This article shows how to use the feature.

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 brackets must be used becase of syntax error, e.g.

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

See also

  1. JavaScript - Math.pow() method example
Native Advertising
50 000 ad impressions - 449$
ūüöÄ
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

‚̧ԳŹūüíĽ ūüôā

Join