JavaScript - ECMAScript 2016
JavaScript - ECMAScript 2016
TheECMAScript 2016version of JavaScript was released in 2016. Previously the old versions of JavaScript are named by numbers for example ES5 and ES6. Since 2016 the versions are named by the year they are released for example ECMAScript 2016, ECMAScript 17, etc. Lets discuss the featues added in ECMAScript 2016.
New Features Added in ECMAScript 2016
Here are the new methods, features, etc., added to the ECMAScript 2016 version of JavaScript.
- Array includes() method
- Exponentiation Operator (**)
- Exponentiation Assignment Operator (**
=)
Here, we have explained each feature in detail.
JavaScript Array includes() Method
The JavaScript array includes() methods is used to check whether the array contains a particular element.
Syntax
The syntax of Array includes() method in JavaScript is as follows β
arr.include(searchElement, fromIndex);Herearris the original array, thesearchElementis to be search from. The fromIndex is an optional argument if passed, the searching will start from thefromIndexindex.
Example
In the below code, we use the array includes() method to check whether the watches array contains the βNoiseβ brand.
Output
Does watches array include Noise? trueExample
In the below code, we use the array includes() method to check whether the subjects array contains the βPythonβ subject searching from index 1.
Output
Does subjects array include Python fromIndex 1? trueJavaScript Exponentiation Operator
The JavaScript exponentiation operator is used to find the power of the first operand raised to the second operand.
Syntax
The syntax of expponentiation operator is as follow β
x ** y;It returns the result of raising the first operand (x) to the power of the second operand (y).
Example
In the below code, we find the 22 using the exponentiation operator and store the resultant value in the βresβ variable.
Output
The resultant value for 2 ** 2 is: 4Exponentiation Assignment Operator
The JavaScript exponentiation assignment operator raises the power of the first operand by the second operand and assigns it to the first operand.
Syntax
The syntax of exponentiation assignment operator is as follows β
x **= y;It assigns the result of raising the first operand (x) to the power of the second operand (y) to x.
Example
In the below code, we find the 102and assign the resultant value to the βnumβ variable using the exponentiation assignment operator.
Output
The resultant value for 10 ** 2 is: 100ECMAScript 2016 Browser Support
Most modern browsers support the ECMAScript 2016 version of JavaScript
ChromeFirefoxMicrosoft EdgeOperaSafariFirefox AndroidYesYesYesYesYesYes