The use of variables in JavaScript, like in many other languages, is pervasive. Assignments, arguments to function calls, and results of computations; variables are everywhere. Simply put, they allow us to store the “state” of a program.
JavaScript only offers one mechanism to declare variables, the ubiquitous var. However, as we will see in this chapter, var presents us with several semantic potholes. We will also see how the introduction of two new keywords, namely let and const, to declare variables helps us avoid subtle bugs, and often unintended side effects, as well as ...