A look back at ES2016

OpenJavaScript 0
Reading Time: 2 minutes 🕑

Last updated: November 2, 2021.

In 2015, the ES6 upgrade to JavaScript introduced a whole range of new features in one go. Following this major update, JavaScript has been updated more incrementally on an annual basis. ES7 thus marked the start of a new era in how JavaScript is updated.

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.

Exponentiation operator

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

The .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

Summary

In this article, we have reviewed the two major updates introduced to the JavaScript language by ES7 (ECMAScript 2016).

Interested in learning more about JavaScript updates from ES6 until the present? Check out our ES6+ section, where we provides in-depth reviews of new features.