JavaScript 2016 - New Features

ECMAScript 2016(ES7) : New Capabilities

Exponent Operator

The exponent operator is represented by **(double asterix). It is used for computing the exponent(power of) of the expression.

let a=10;
let b=3;
let c = a**b;
console.log("powerof", c); //1000
console.log("**", 3**2,2**5); // 9 32

In the above code the power of is computed using the exponent operator.

Array.includes() function

The includes() function is used to search for a value in the array entries. it returns a value true if found.

// Array - includes() method 
let names = ["ram","hari","gopi","ramesh"];
console.log(names.includes("gopi"), names.includes("mahesh")); 
// true false

In the above code the value gopi is found but mahesh is not found.

The programmer can also specify the starting index of the search in includes() function.

let  cities = ['Bangalore', 'Mumbai', 'Hubli', 'Mysore','Pune', 'Kolkata'];

console.log(cities.includes('Mumbai', 1)); // true
console.log(cities.includes('Kolkata', 4)); // true
console.log(cities.includes('Hubli', 4)); // false
console.log(cities.includes('Bangalore', 1)); // false

In the above code the search is based index i.e from where the search should start.

Complete Code Listing

let a=10;
let b=3;
let c = a**b;
console.log("powerof", c); //1000
console.log("**", 3**2,2**5); // 9 32 

// Array - includes() method 
let names = ["ram","hari","gopi","ramesh"];
console.log(names.includes("gopi"), names.includes("mahesh"));  // true false

let  cities = ['Bangalore', 'Mumbai', 'Hubli', 'Mysore','Pune', 'Kolkata'];
console.log(cities.includes('Mumbai', 1)); // true
console.log(cities.includes('Kolkata', 4)); // true
console.log(cities.includes('Hubli', 4)); // false
console.log(cities.includes('Bangalore', 1)); // false