Exponent operator in ES2016 - ES7

Akash Gutha
InstructorAkash Gutha
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

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.

[00:00] 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.

[00:14] 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.

[00:51] 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.

[01:12] 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.

[01:39] 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.

[02:00] 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.

egghead
egghead
~ 23 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today