1

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?

14
  • you declare our variable! #offtop Commented Aug 8, 2019 at 6:21
  • I declare variable only in code but who is declare a variable on ram? Commented Aug 8, 2019 at 6:22
  • 1
    That sentence is the summary of what is said before in 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. Commented Aug 8, 2019 at 6:35
  • @t.niese I Know this is summary of what is said before. But this is does not make sense. How compiler can ask Scope? This is not Compiler job this is Engine job? Is there wrong when I say? Commented Aug 8, 2019 at 7:00
  • 1
    This probably also be done later at execution time. But as it is already possible in the compiling step why shouldn't it be done there? 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. Commented Aug 8, 2019 at 7:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.