Introducing ECMAScript 2016
As mentioned earlier in this chapter, ECMAScript 2016 is a small release with only a couple of new features. These are an includes
method for arrays and the exponentation operator **
.
You can write myArray.includes(value)
instead of myArray.indexOf(value) !== -1
. Note that these expressions are not quite equivalent. You can use includes
to check for the value NaN
within an array, which you can't do with indexOf
.
The exponential operator allows you to rewrite Math.pow(coefficient, exponent)
as coefficient ** exponent
.
You can also combine it with an assignment, as in myVariable **= 2
.