ECMAScript 2016 (ES7)¶
Array.prototype.includes()¶
This feature introduces a more readable syntax for checking if an array contains an element.
With ES6 and lower, to check if an array contained an element you had to use indexOf
, which checks the index in the array, and returns -1
if the element is not there.
With this feature introduced in ES7 we can do
if (![1, 2].includes(3)) {
console.log("Not found");
}
Exponentiation Operator¶
The exponentiation operator **
is the equivalent of Math.pow()
, but brought into the language instead of being a library function.
Math.pow(4, 2) == 4 ** 2;