What's new in ECMAScript 2016 (ES7)
In June 2015 the TC39 (Technical Committee 39) officially released a spec of ECMAScript 2015 (colloquially known as a ES6). In parallel to the new spec, a new naming system within the language was introduced which is related with the new yearly release process. The plan is to release a new version of the language every year, and ship it with features that are ready at the time. ES2015 added a lot of amazing features. If you are not familiar with these fresh add-ons yet, check “ES6 Overview in 350 Bullet Points” by Nicolás Bevacqua. It’s the best summary that I have seen so far. Luckily we shouldn’t expect updates as huge every year which give us a chance to follow the spec.
The final list of features that we’re going to see in ECMAScript 2016 is ready and as expected, it is just a small update. Let’s have a look!
Array.prototype.includes
This feature proposed by Domenic Denicola and Rick Waldron checks if the array includes an element and returns a boolean value. The syntax is super simple.
['a', 'b', 'c'].includes('a'); // true
['a', 'b', 'c'].includes('d'); // false
Previously we did it like this which is not as self explanatory.
['a', 'b', 'c'].indexOf('a') >= 0 ? true : false; // true
['a', 'b', 'c'].indexOf('d') >= 0 ? true : false; // false
This new feature also solves the problem of checking for NaN
in an array. Compare these two examples and results.
['a', 'b', 'c', NaN].includes(NaN); // true
['a', 'b', 'c', NaN].indexOf(NaN) >= 0 ? true : false; // false
Exponentiation Operator
Proposed by Rick Waldron, Claude Pache and Brendan Eich, this feature brings a much nicer notation to exponentiation. It uses infix notation which is much cleaner than function notation (Math.pow()
). We can find the same notation in other programming languages like: Python, Ruby or Pearl. Have look at the examples.
2 ** 4; // 16
let a = 2;
a **= 4; // 16
Previously…
Math.pow(2, 4); // 16
why not just 2^4 instead of the strange **
That is already used in the language. It is the bitwise XOR operator.
Exactly. Thanks for answer @searsaw:disqus. @aaalsubaie:disqus have a look. https://developer.mozilla.o...
That looks fantastic and really useful on someone's part in learning. through this, there will be a lot of people who could do something great with this tool that might be a perfect fit on their projects or on their studies.