ES7 brings two new features

ECMAScript 2016 (more commonly known as ES7). ES7 brings two new features:

1. Array.prototype.includes()
2. New exponential operator: **.


Array.prototype.includes()

We used .indexOf() to know if an element existed in an array. For example:


['my','dad','hates','me'].indexOf('dad')  // 1
// I know it sounds confusing but the value 1 represents
// the index at which the string 'dad' appears in the array.

The key word is “exist.”

.indexOf() is fine if we want to know at which index a given element appears.
But if our goal is to know if a given element exists in an array, then .indexOf() is not the best option. And the reason is simple: When querying the existence of something we expect a boolean value, not a number.


Array.prototype.includes() does exactly that. It determines if a given element exists in an array, returning true if it does, false otherwise.


var life = ['mom', 'dad', 'brother']
life.includes('dad')          // true
life.includes('girlfriend')   // false


The Exponential Operator (**)

The operator ** behaves exactly the same way as Math.pow(). It returns the result of raising the first operand to the power of the second (e.g. x ** y).

# x ** y (aka Math.pow(x,y))
> 2 ** 3
8
> 2 ** 'operand'
NaN


That’s it!

You now have the power of ES7! Use it well!

Comments

Popular posts from this blog

Understanding Top line and Bottom line?

How to activate PF UAN account

Scrum Master vs Product Owner