ES7: a simple and useful guide to master it

Flávio H. Freitas
2 min readApr 17, 2017

--

After exploring all the new features from ES6 (ES2015), installation, history and name pattern in this article, I will tell you about the releases of ES7 (ES2016). And if you are afraid that it will be as big as the first one, don't worry; it is much smaller.

TC39 (the Technical Committee that writes the spec) released ES7 in June 2016, and it came with two new features that will make your life a little bit easier. Let's see them:

ES2016

Tip: try to open the console of your browser and test these examples. Super cool!

Array.prototype.includes

We got used to looking for elements in an array with array.indexOf(el) !== -1, but now this is a thing of the past. We can look for them in a simpler way:

['a', 'b', 'c'].includes('b');      // true
['a', 'b', 'c'].includes('d'); // false
['a', 'b', 'c'].includes('c', 2); // true
['a', 'b', 'c'].includes('c', 3); // false
['a', 'b', 'c'].includes('c', 'g'); // true
['a', 'b', NaN].includes(NaN); // true
# also a string
'a123b'.includes('123') // true

The syntax of this function is:

element.includes(searchElement[, fromIndex])
  • searchElement — the element that you are looking for
  • fromIndex — from which position the search will start. Default: 0

Exponentiation Operator (**)

This function returns the result of the mathematical expression baseⁿ, where n is the exponent. In Javascript the exponentiation symbol is ** and can be used like so:

base ** exponent

Some examples:

2 ** 3         // 8
3 ** 2 // 9
3 ** 0.5 // 1.7320508075688772
10 ** -1 // 0.1
NaN ** 2 // NaN

3 ** (2 ** 4) // 43046721
(3 ** 2) ** 4 // 6561

And that's it. ES7 is simpler to learn. Now you master it ;)

If you enjoyed this article, be sure to like it (← a ❤️ on the left) — as a writer it means the world 😘

Thank you for the revision, Shawn McCarthy and Chris de Graaf.

If you enjoyed this article, be sure to like it give me a lot of claps — it means the world to the writer 😘 And follow me if you want to read more articles about Culture, Technology, and Startups.

Flávio H. de Freitas is an Entrepreneur, Engineer, Tech lover, Dreamer and Traveler. Has worked as CTO in Brazil, Silicon Valley and Europe.

--

--