YDKJS — Types & Grammar

Another weekend spent curled up with everyone’s favorite journey through JavaScript ignorance — You Don’t Know JS by Kyle Simpson. This was an interesting entry into the series as it started off with me actually thinking I understood a bit of what was going on. That quickly fell by the wayside however and I was plunged back into the confusing and thrilling depths of completely new knowledge. I’m growing to really love this series not merely for the nuggets of insights it provides, but the hints at further wisdom which are to come on repeat readings. I can’t wait to go back to these posts 6–9 months from now. I imagine it will be like walking down the streets of your hometown years after you first learned them and had time to build many many more memories on top of the originals. Enough of the sentiment though…On to the learnings!


Having had some previous exposure to types from CS50, there was immediately certain terminology and convention I was familiar with. However, that initial familiarity masked and intricate capability that was soon expounded on to my confusion and delight. At the highest level, typing allows certain values to have core capabilities shared across other values of its type. Along with those capabilities also come restrictions in many cases, but these built-ins allow programmers to manipulate the information in standard ways, freeing them up to focus on the more unique sides of their program rather than reinventing a wheel most people generally agree is a good one. The most interesting thing to me regarding JS and types is that a variable doesn’t hold the type, but rather the value which occupies it at that time. This offers the flexibility of being able to move new values through the same variable without having to recast or recreate the thing. Additionally, learning about the peculiarities of NaN really put into context some of the issues I had with an earlier FCC program. I was trying to test for all falsy values, but without knowing that NaN != NaN I was failing. I’ll know to be more on guard now whenever testing a NaN value.

Lastly, two things I am definitely not getting so far are Symbols and the ~ corcian. I wonder how much of this is Simpson’s explanation as I similarly felt like I was reading ancient engyptian when Kyle began throwing around the ‘?’, but after 3 minutes of googling I got a much better understanding of ternary’s than the section in YDKJS. I’ll have to remember outside sources can definitely supplement these books.


This section was a bit less useful to me and I suspect will come into its own as I get better with code structures and thinking linearly through how a section will unfold. I valued the breakdown of the && and || sections in helping me see instances where JS would uninuitively work through my code, but I struggled with the “so what” of this section. It seemed here Kyle had many more examples of how NOT to write code, and a breakdown of how JS worked on a given expression, but not much of the why’s or what to do with it. I’ve written before on how this overtly conceptual emphasis makes it difficult for me to internalize these ideas and practices, but this section in particular felt the most academic compared to others. I liked the examination of coercion and the breakdowns of explicit and implicit types and their use/avoidance of use, but beyond that I really didn’t get much from this portion of the book. Perhaps its secrets will be reviewed further down the line, but for now I’ll have to make due with the few exercises I’ve extracted and come back from more in a few months.


Given my professed preference for learning by doing, I’m attempting to extract a few exercises from each chapter to force myself to work into my Javascript. These are the first:

  1. Use the ~ coercible somewhere
  2. Use a !! to ensure the intended Boolean is returned
  3. Coerce a string with a var + “”;
  4. Use && to gaurd a function call by ensuring some pre-requirement is present.

Any other ideas and pointers? While this is more a journal at this point, I’d love to help y’all get some value out of my rantings and ravings too. Let me know what you like, hate and would like to see more of.

Until next time!