When I read YDKJS(You Dont Know JS) book in there getify says "First, Compiler declares a variable (if not previously declared in the current scope)" - but I don't understand how compiler declare a variable? Compiler only turn code to machine code and engine run our code. My question is Engine Declare variable or Compiler declare our variable?
1. Encountering var a, Compiler asks Scope to see if a variable a already exists for that particular scope collection. If so, Compiler ignores this declaration and moves on. Otherwise, Compiler asks Scope to declare a new variable called a for that scope collection.How compiler can ask Scope?the same way you can figure out the scope while reading the code. The scope is nothing defined at runtime, it is already known before that.