The Lightbulb moment: when a difficult concept to grasp finally makes sense to you. This moment is a favorite of anyone learning something new, whether they're in a traditional classroom setting or studying on their own.
The two big lightbulb moments I had over these last two weeks focused on hoisting and scope.
There are two phases to a function call: the creation phase and execution phase. The creation phase involves the creation of the variable object. Here, the argument object is created, which contains all the arguments that were passed into the function. As the code is scanned for function declarations, a property is created in the variable object pointing to the function. Likewise, the same process occurs for any variable declarations. For each variable, a property is created in the variable object and set to undefined. This can be avoided by assigning the variable the null value when it is first declared. When these properties are created in the variable object, hoisting occurs as the variables and function calls are available before the execution phase begins.
Scoping answers the following question: where can we access a certain variable?
Each new function creates a scope, which is the space in which any variables defined by the function are accessible. For example, if a function defines a variable called favoriteDog, the variable favoriteDog is accessible to that function and any functions written within (which is referred to as lexical scoping). However, the variable favoriteDog is not available to any other function in the global scope.