FrontendDeveloper.in

ECMAScript question detail

Exponentiation Operator

The older versions of javascript uses Math.pow function to find the exponentiation of given numbers. ECMAScript 2016 introduced the exponentiation operator, **(similar to other languages such as Python or F#) to calculate the power computation in a clear representation using infix notation.

//Prior ES7
const cube = x => Math.pow(x, 3);
console.log(cube(3)); // 27

//Using ES7
const cube1 = x => x ** 3;
console.log(cube1(3)); // 27

ES2017 Or ES8

Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399