JavaScript · ES2016

ES7 Interactive Hub — ECMAScript 2016

A small release (2 features) but extremely practical: the exponentiation operator (**) and Array.includes replacing clunky indexOf.

Experience
0 XP
Course completion0%

Exponentiation (**)

Core topic

Easy3 min

💡 Concept summary

The exponentiation operator "**" replaces Math.pow(a, b) — shorter and more natural to read.

🤔 Why do you need this feature?

In ES5, raising to a power required the verbose Math.pow(a, b). ES7 adds the new "**" operator so you can write a ** b as intuitively as a math formula.

Before (old style)Verbose / clunky
// ES5 style using Math.pow
var square = Math.pow(2, 10);
console.log(square); // 1024

var x = 5;
x = Math.pow(x, 2);
console.log(x); // 25
ES7 (Modern)Optimal & recommended
// ES7 style using the ** operator
const square = 2 ** 10;
console.log(square); // 1024

let x = 5;
x **= 2; // Equivalent to x = x ** 2
console.log(x); // 25
Got it down? Try running real code or take the quiz!

ES7 Quick Reference

Quick syntax overview + copy snippets

Exponentiation (**)

The exponentiation operator "**" replaces Math.pow(a, b) — shorter and more natural to read.

const square = 2 ** 10;
console.log(square); // 1024
let x = 5;
...
Array.includes

The Array.prototype.includes() method checks whether an element exists in an array, returning a boolean.

const arr = [1, 2, 3, 4];
if (arr.includes(3)) {
    console.log("Contains the number 3");
...