Exponentiation operator

The exponentiation operator may come in handy when working with math. Let's use the formula to calculate the area of a circle as an example:

const area = 3.14 * r * r; 

We could also use the Math.pow function to write the same code:

const area = 3.14 * Math.pow(r, 2); 

ES2016 introduced **, where ** is designed to be the new exponentiation operator. We can calculate the area of a circle using the exponentiation operator as follows:

const area = 3.14 * (r ** 2); 
This example can be executed at https://goo.gl/Z6dCFB.

ES2015+ also has some other functionalities; among them, we can list iterators, typed arrays, Set, Map, WeakSet, WeakMap, tail calls, for..of, Symbol, Array.prototype.includes, trailing commas, string padding, ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.