YDKJS 6: ES6 & Beyond

So…it has come to this… The end of Kyle Simpson’s awesome You Don’t Know JavaScript series. I ended this saga still feeling like there is a ton about JS I don’t know, and I remain certain that I will be returning to these volumes a number of times until everything really clicks, but Kyle has provided me with a rich understanding of the capabilities of the language, even if I won’t necessarily get every specific right way. I highly recommend this series to anyone looking to know more about JS. Don’t be intimidated if you have little to no experience with JS (I didn’t). It will be a challenge, but a good one. Just remember to try all of the examples out, take notes and put concepts into some kind of parking lot to try later.

The 6th edition was the most different from other entries in the series. Rather than introduce a few concepts and dig deeply into them, vol. 6 is more of a rapid fire update on the newly official (at that time) and potential features of the JS language. It was definitely a useful view into these things, but if you’re not coming to these books with at least a decent understanding of the JS language, I recommend starting with the other 5 first.

The first chapter dealt primarily with shims and other methods for allowing access to these newer features across browsers that may not yet support them (I’m looking at you IE). Useful stuff, but Kyle mainly points you to existing tools rather than start from scratch. Smart move.

Following that we dive into syntactical updates to the language. What new ways can we say things? ES6 has some cool updates, one of which is block scoping which allows much easier and clearer scope restricting for purposes like APIs. In conjunction with the {} needed for block scope, using the let declaration binds the variable to that scope specifically. It’s a good idea to keep those declarations to the top of the section too so no one gets confused. Other additions are the const variable which keeps the value constant. This doesn’t mean it is a constant value, just a constant reference to that value. So a const array could still have values pushed to it, for example. We also learn about for…of loops, a new syntax for getting all the values of whatever you are iterating over (an array for example) as opposed to just the index. This cleans up a lot of the code you’d previously need to write to first get the index then use it to access a value. Destructuring is another big addition which can be used to manually bind values returned by a function. In conjunction with the new … operator, this can be powerful. The …, known as the rest/gather operator is, in short, a method of either packing the remaining values into an array or unpacking them depending on which way it points.

This actually transitions us nicely into the next chapter, dealing with the new aways ES6 gives you to organize your information. A lot of this was actually a familiar rehash of generators, iterators & promises. For the first time in this series I actually did know some JS…but only because Kyle already taught me. This however was a good overview of the new capabilities if you already understand a bit about iterators and asynchronous programming. There is then a bit about Maps, which was my first exposure to the unordered key/value structure. They seem mostly to be less useful Objects which Kyle confirms when he says “You’ll probably want to continue to use normal objects for maps unless some or all of the keys need to be objects, in which case Map is more appropriate.” Good advice. Additionally there are a whole bunch of new array methods built in as well as a useful comparison method for Objects, Object.is(). Object.is is very strict, so Number.isNaN(x) might be better for NaN testing.

After that it starts to get a little deeper than my capability at this point. For instance, I could not for the life of me understand what a typed array was. Additionally, there is a lot of focus on Proxies and Reflect which I did not grasp in the slightest. I will have to build my base of knowledge and re-visit at a later date.

The last bit turns the language inward and focuses on meta-programming. While much of it went over my head, understanding the capability JS has to reference and build on itself seems incredibly powerful (and dangerous). I couldn’t think of any immediate uses off of the top of my head, but will remember this section when I reach an impasse that may need JS to alter itself a slight bit.

Overall, this has been an incredible starting point on my journey to competent junior dev and self-taught computer scientist. I could not recommend it more and will look fondly at the books on my shelf for years to come. Please share your thoughts, questions or feedback in the comments. Thanks for joining me on this journey through JS!