Chapter 5: Grammar

The last major topic we want to tackle is how JavaScript’s language syntax works (aka its grammar). You may think you know how to write JS, but there’s an awful lot of nuance to various parts of the language grammar that lead to confusion and misconception, so we want to dive into those parts and clear some things up.

Note: The term “grammar” may be a little less familiar to readers than the term “syntax.” In many ways, they are similar terms, describing the rules for how the language works. There are nuanced differences, but they mostly don’t matter for our discussion here. The grammar for JavaScript is a structured way to describe how the syntax (operators, keywords, etc.) fits together into well-formed, valid programs. In other words, discussing syntax without grammar would leave out a lot of the important details. So our focus here in this chapter is most accurately described as grammar, even though the raw syntax of the language is what developers directly interact with.