Getting started with ESNext — Exponentiation

You may have seen all the hype around ES6 and hopefully are already taking advantage of some of the cool syntactic sugar that ES6 has to offer. But, you don’t need to be satisfied with just doing the next cool thing. With Babel, we can already start using ESNext features in our code.

Now, to get started you need to have node and npm installed on your local machine. So, if you don’t have that, head over to nodejs.org to get that installed. Once you have npm installed, you should be able to install babel at the command line using npm.

npm install -g babel-cli

Once that is done, we will need to create a .babelrc file to tell babel what we want to do. In this case, we are going to use the stage-0 preset because that preset will include all of the ESNext features we want to use. So once you get into a new directory, we will create our preset using the command line.

echo ‘{ “presets”: [“stage-0”] }’ > .babelrc

Once that is all setup, we are free to start using ESNext features in our code. So let’s try one out and see if everything is working…


The Exponentiation operator is a great place to start because it is just pure sugar on top of the Math.pow function. The exponentiation operator allows us to use ** to set exponents. So, for example…

console.log(2**3);

This would be the equivalent of saying Math.p0w(2,3) and would print 8 to the console.

Now, in order to use this in our application, we need to put this line in our app.js file and run it through babel. At the command line we run:

babel app.js -o esNext.js

That will create a new file with the following line in it:

console.log(Math.pow(2, 3));

See, just pure sugar over the Math.pow function. But it gives us a good starting point for using the rest of the ESNext features. We can also use this operator during assignment just like ++ and — . In app.js add this:

var y = 2;
var x = 3;
y **= x;
console.log(y);

Now run that back through babel

babel app.js -o esNext.js

and you will now get 8 written out to the command line.

Congrats! you are now working on the bleeding edge of JavaScript features….

Like what you read? Give Jonathan Mills a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.