 This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

Exponent operator in ES2016 - ES7 JavaScript

A brief introduction and review of the exponent operator in ES2016 and review previous methods being followed. We will also look at some examples that demonstrate the behaviour of the exponent operator. Code You must be a Member to view code

Access all courses and lessons, track your progress, gain confidence and expertise.

Become a Member
and unlock code for this lesson Discuss Transcript

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.