LHS references result from assignment operations. Scope-related assignments can occur either with the operator or by passing arguments to (assign to) function parameters.
The JavaScript Engine first compiles code before it executes, and in so doing, it splits up statements like var a = 2;
into two separate steps:
Both LHS and RHS reference look-ups start at the currently executing Scope, and if need be (that is, they don’t find what they’re looking for there), they work their way up the nested Scope, one scope (floor) at a time, looking for the identifier, until they get to the global (top floor) and stop, and either find it, or don’t.
Unfulfilled RHS references result in s being thrown. Unfulfilled LHS references result in an automatic, implicitly-created global of that name (if not in “Strict Mode” [^note-strictmode]), or a ReferenceError
(if in “Strict Mode” [^note-strictmode]).
Identify all the RHS look-ups (there are 4!).
foo(2..
,= a;
,a + ..
and
[^note-strictmode]: MDN: