/ JS

Aug + Sep + Oct + Nov 2017 - ES6

What

ES6 aka ES2015. A newer version of JS (it's not the most recent one). ES2017 came out in June 2017.

Why

I am still writing in Vanilla JS and more and more js posts are in ES2015 around the web. It's time to understand all the PROs and CONS of the new syntax and take advantage of it.

As you've noticed that I've spent 4 months on this topic and most of it was not by design:

  • August was filled with adventures with the kiddos.
  • Changes to my morning routine with kids going back to school.
  • Time needed to evaluate Typescript as a possible replacement to ES6 (more on that below).
  • Increased workload at work which led to evening work reducing my personal study time.

How

What I learned

  • Installing, configuring, and using (Webpack||Gulp+Browserify) + Babel for ES6 transpiling.
  • New variable instantiation (let vs const).
  • Template literals.
  • The changes in the use of "this" for fat arrows and changes in scoping for functions and blocks.
  • Classes along with their constructor function and how that fits with NG1 $onInit function.
  • Module instantiation, import and export while working with ES5 and ES2015.
  • Object and Array destructuring.
  • Rest and Spread operators.
  • Generators and Iterators.

I wrote examples for most of these as I worked through them in this GitHub repo.

Learning resources for next time

Conclusion

This version of Javascript is not only cleaner but more powerful. I wish there weren't so many configuration steps to go through since not all browser support ES6 out of the box but it's worth the overhead in the end.

September was originally dedicated to TypeScript but when I read this post by Eric Elliott, we decided that implementing ES6 was a better short-term goal than TS. The overhead of TS over time didn't seem like a good trade-off once an experienced JS dev put it in terms we could understand. Namely that static types don't reduce bug density by much, but they offer benefits in terms of tooling which is a marginal benefit. We also factored in that static types can make several features of JS more tedious to use, such as polymorphism and object composition. This is the kind of problem you're normally not aware off until it's too late and when you're working with a large code base, it can really be tough to manage.