JavaScript New Features | ES7 (ECMA script 2016)

Amar
2 min readJun 30, 2021

--

New Features

So, We all know that ES6 features very well. Most of the people are not able to identify the features introduced in later version of ES6. If you ask ES6 features they are saying all features introduced ES7, ES8 and ES9 as well.

Let’s ask question yourself, is it necessary to differentiate features across ECMA versions. If you ask this question to me then I would say Yes. The reason is, there are libraries using Javascript they do not support all latest ECMA latest features. Usually, they start support these features once a latest version released. Normally, the latest version of ECMA features will not support by NodeJs recent version. For instance Node 10 does not support static variable assignment.

So, I have decided to publish a series of articles on each of ECMA version new features. In this article we are going to discuss about two major features of ES7. They are

Array.prototype.include Array.prototype.include

Exponentiation operator **

Array.prototype.include
This is an alternative method to Array.prototype.indexOf that introduced in ES6. This method overcomes drawbacks of indexOf method. The indexOf method returns the index of the element if it exists. If does not exists it returns -1 which is a problem if we directly put this method inside the if condition.
Let’s have a look at the below example.

const arr = [2,3,4,6];if (arr.indexOf(5)) {    console.log('arr has element 5'); 
// It will print the console message as if condition considers -1 as true.
}

Here is the same example with includes.

const arr = [2,3,4,6];if (arr.includes(5)) {   console.log('arr has element 5');    //In this case the console.log message will not print.}

Exponentiation operator (**)

Exponentiation operator is an arithmetic operator equals to Math.pow. It is a higher order precedence operator than unary + and unary -. In most of the languages such as PHP, Python and other languages the exponentiation operator is a higher order precedence operator. But, in bash it is a lower precedence operator.

2 ** 2 (4) \n
-(2 ** 2) // -4
-2 ** 2 // Invalid
2 ** -2 // 0.25
(-2) ** 2 // 4
(-2) ** 3 // -8

In the above list of examples, there is an invalid expression. -2 ** 2

Javascript does not allow any unary operators (+/-/!/delete/void/typeof) immediately before a base number.

NodeJs compatibility

Exponentiation(**) operator supports from NodeJs version 7.5.0

Array.prototype.includes supports from NodeJs version 6.4.0

--

--