Introducing The ES7 Features

Posted By : Himanshu Agarwal | 31-Jan-2018

1) Exponentiation Operator


Javascript already had operators like =,-,*.
ES7 introduced exponentiation operator, **.
It works same as Math.pow(). Basically returning the first argument which is 
raised to the power of second argument.


 

var base = 3;
var exponent = 4;
var result = base*exponent;

console.log(result); // 81

2) Array.prototype.includes()


Array.prototype.includes() checks the array for the passed value as argument.
We get true if

an array contains value else we get a false.

Earlier we use to have Array.prototype.indexOf() to check if the given array
has an element or is empty.


 

var numbers = [1,2,3,4]

if(numbers.indexOf(3) !== -1) {
  console.log('Array has value');
}

Now in ES7 we can write like this

if(numbers.includes(3)) {
  console.log('Array has value');
}

Why we needed .includes() when we already had .indexOf()?
The prime reason for this being handling of NaN. .includes() handle NaN in a better way.
Suppose our array has NaN, then .indexOf() does not return the index while searching for it
whereas this is not the case with .includes().

var numberss = [1, 2, 3, 4, 5, 6 NaN];
console.log(numbers.includes(NaN)); //returns true
console.log(numbers.indexOf(NaN)); //returns -1

 

About Author

Author Image
Himanshu Agarwal

He works on Frontend Technologies like Javascript, Angular, HTML, CSS, jQuery.

Request for Proposal

Name is required

Comment is required

Sending message..