Tuesday, 9 January, 2018 UTC

Summary

Development of new features for the core JavaScript language has really improved over the last five years, thanks in part to JavaScript frameworks pushing the limits and proving how important given functionality can be. My previous ES6 posts, Six Tiny But Awesome ES6 Features and Six More Tiny But Awesome ES6 Features, highlighted a dozen excellent features that were added to JavaScript to make our lives easier — and they certainly do. Let’s have a look at some of the “small” functionality that ES7 and ES8 brought us!

String.prototype.padStart/padEnd

padStart and padEnd allow us to pad a given string with any text of our choosing to ensure a string matches a given length:

indexOf has been used over the years to detect item presence in array, but the `0` index can lead to false negatives if not coded properly. I’m glad JavaScript has added a function that returns exactly what we need: a positive or negative answer!

The case of the Array length is one to keep in mind. ESLint has a comma-dangle rule you can use to ensure your comma dangle usage is consistent.

Bonus: async / await

Obviously async and await, the new method of handling async tasks, is no “tiny” addition, but it certainly is awesome! Read my async and await guide to transform your callback hell into a more elegant, top-down approach to async code!

With every iteration of JavaScript we’re solving problems that we’d been having with lack of functionality or bastardized usage of other functions. What’s your favorite recent addition to JavaScript?

The post Six Tiny But Awesome ES7 + ES8 Features appeared first on David Walsh Blog.