Tags: ES, ECMAScript, JavaScript, ES2016, Array.prototype.includes, Exponentiation Operator

ECMAScript (ES) is the universal standard for JavaScript. In this guide, we’ll dive into everything you need to know about ECMAScript, with a specific focus on the features introduced in ES2016, also known as ES7.

ES2016, officially known as ECMAScript 2016, was finalized in June 2016. Unlike its predecessor ES2015, ES2016 is a relatively minor release, bringing only two new features to JavaScript.

Feature 1: Array.prototype.includes()

The Array.prototype.includes() feature introduces a more intuitive syntax for checking if an array contains a specific element. In previous versions of JavaScript, we had to use the indexOf() method to check for element existence, which returned -1 if the element was not found.

Here’s an example of the old approach:

if (![1, 2].indexOf(3)) {
 console.log('Not found');
}

With the new Array.prototype.includes() feature in ES2016, we can simplify the code:

if (![1, 2].includes(3)) {
 console.log('Not found');
}

By using the includes() method, we can check if an element exists in an array more directly and clearly.

Feature 2: Exponentiation Operator

The Exponentiation Operator (**) replaces the need for the Math.pow() function by making exponentiation more accessible within the language itself.

Math.pow(4, 2) == 4 ** 2

This operator is a valuable addition for JavaScript applications that involve complex mathematical calculations. It is standardized across multiple programming languages, including Python, Ruby, MATLAB, Lua, and Perl.

In summary, ES2016 brings only two new features to JavaScript: Array.prototype.includes() for easier array element existence checks and the Exponentiation Operator (**) for simplified exponentiation calculations.

By leveraging these new features, developers can enhance their JavaScript code and improve its readability and efficiency. Understanding ES2016 is essential for keeping up with the latest enhancements to the ECMAScript standard.