Javascript Arithmetic Operator Exponentiation Operator

Introduction

In Javascript 7, Math.pow() now gets its own operator, which behaves identically.

console.log(Math.pow(3, 2));     // 9 
console.log(3 ** 2);            // 9 
console.log(Math.pow(16, 0.5);  // 4 
console.log(16** 0.5);          // 4 

The operator gets its own exponentiate assignment operator, =.

It performs the exponentiation and subsequent assignment of the result:

let squared = 3; 
squared **= 2; //w  ww  .jav  a2 s  .c  om
console.log(squared);  // 9 
              
let sqrt = 16; 
sqrt **= 0.5; 
console.log(sqrt);     // 4 



PreviousNext

Related