JavaScript Variables, Constants, and Assignment - tdkehoe/blog GitHub Wiki

Variables are symbolic names for values in an application. Variables are like politicians: their values change every time they turn around.

#Creating a Variable

Variables can be created in three ways, depending on whether you want a local variable, global variable, or a variable that can be local or global.

  • let myLocalVar = 37; declares a local variable in a block statement.
  • myGlobalVar = 42; declares a global variable.
  • var myFavoriteVar; declares a variable that can be local or global. The value is undefined.

#Variable Assignment

Describe in precise terms what’s happening with variable assignment using “var keyword”, “identifier”, “value”, “assign” etc…

#Variable Hoisting

Functions can access variables that are declared later in the program. This is called variable hoisting.

#Constants

const prefix = '212'; declares a constant.

let, var, and const are keywords.

A variable's identifier is its name.

A variable's value is its value.

#Assignment Operators

Variables use a single equals sign = to assignment a value to an identifier.