The exponent operator is a new addition in ES2016 specification. This operator allows us to write statements with exponent operator. Let us declare a variable X and make it equal to two. Let's declare another variable Y and make it equal to five.
Now, we'll use the exponent operator to raise X to the power of Y and set it equal to Z, so that essentially, Z is equal to X to the power of Y. As you might know from the elementary mathematics that two to power of five is equal to 32. Let's go and verify this. As you can see, the answer is 32, which exactly matches the mathematical solution.
Let's look at the previous method followed using ES2015. We use the math library and call the power function which basically expands to power, and passing two parameters with the first parameter X is the base and Y is exponent. This is X to the power of Y.
Let's console log this and check for the result. We've got the same output for X to the power of Y and Math.pow(X,Y). Now, let's take a look at some of the examples that we can make using the exponent operator.
A number raised to the power of zero will yield one. A number raised to the power of Not a Number will result in Not a Number. A Not a Number raised to Not a Number will result in Not a Number. Not a Number raised to zero will result in one.
This is an interesting output that you need to remember. A zero raised to Not a Number will result in Not a Number. Zero raised to zero is one. If you keep these examples in mind, it will help you while programming.