This “compilation”, he further states, is a 3-step process which comprises:
Tokenizing/Lexing: involve chunking a string of characters into tokens.
Parsing: turning a stream of tokens into a tree of nested elements, a tree known as Abstract Syntax Tree, or AST for short.
Code Generation: The process of turning the AST into executable code.
He further asserts other important points which are bulleted below:
“Behind the scenes”, the following components do all the heavylifting of running our code:
There are generally two kinds of variable “lookups”:
For traversing a nested scope, the engine begins the lookup at the currently executing scope. If not found, the engine moves one level up and continues the lookup. If still not found, the engine keeps moving one level up the scope until it reaches the global scope. Finally, if the lookup still fails at the global level, the engine throws up an error.
When the engine is running in ‘relaxed’/’non-strict’ mode and an LHS lookup done within a nested scope fails - even after searching all scopes accessible to it (including the global scope) - a new variable would be implicitly created at the global level and the assignment would be done there.
For ‘strict’ mode, however, both RHS & LHS lookups return a “Reference Error” if the lookup fails after checking all accessible scopes. I.e. No implicit creation of variables in the global scope.
ReferenceError is scope resolution-failure related, whereas
TypeError implies that scope resolution was successfull but that there was an illegal/impossible action attempted.