YDKJS — Types & Grammar
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.
- Use the ~ coercible somewhere
- Use a !! to ensure the intended Boolean is returned
- Coerce a string with a var + “”;
- 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!