A look back at ES2016
Last updated: November 2, 2021.
As a result, the upgrades introduced in ES7 were far more modest in number. Here we review the two new features introduced: a new exponentiation operator on the
Math object and a handy
.includes() array method.
Before the introduction of the exponentiation operator (
**), one could only calculate an exponential in using the native
Math object. The syntax for calculating an exponential in this way is
Math.pow(baseNumber, exponent). For example, to calculate 2 to the power of 3, the syntax would be:
Math.pow(2, 3); // output: 8
The exponentiation operator introduces a simpler syntax for making such a calculation:
2 ** 3 // output: 8
When used with the
Number type, both provide the same outcome.
However, in light of the introduction of BigInt in ES11, there is now an important practical difference between the two: BigInt calculations can be made with the exponentiation operator but not with Math.pow():
Math.pow(2n, 3n); //TypeError: Cannot convert a BigInt value to a number 2n ** 3n // 8n
The .includes() array method
.includes() method can help us to quickly identify whether a value exists in array. One simply applies it to an array while passing in the value to search for as an argument inside the parentheses. For example:
const numbers = [1, 2, 3, 4, 5]; numbers.includes(1); // true numbers.includes(6); // false
The method returns a boolean value of true or false, depending on whether the value was found or not.
Note that true is only returned in if the value search for is an exact match:
const strings = ['One', 'Two', 'Three']; strings.includes('One'); // True strings.includes('Two'); // True strings.includes('hree'); // False strings.includes(' Three '); // False strings.includes('Three'); // True