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
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu Agarwal
He works on Frontend Technologies like Javascript, Angular, HTML, CSS, jQuery.