Let's consider this code snippet
xvar = "inder";
yvar is not defined explicitly but if you run above code, it will give a
reference undefined error. Why can't it just create
an empty variable and console log
undefined instead? What's the difference here?
The difference is
xvar had an LHS (Left Hand Side) assignment where as
yvar had a RHS (Right hand assignment) assignment.
Whenever the variable name is on left hand side of assignment operator
= it's called LHS assignment. When the variable is on right hand side
and create a variable even if it's not defined earlier BUT in RHS assignment it would throu a
reference undefined errror.