0

Because I am not using the var keyword why is the variable 'local' not in the global scope in the chrome console?

function test(){ local = true; }; console.log(local);//Uncaught ReferenceError: local is not defined 
2
  • 2
    In your snippet, the function hasn't been called/invoked – test();. Its body, including the assignment, local = true;, won't be evaluated until then. Commented Oct 10, 2016 at 22:04
  • Thanks @Jonathan Lonowski you are correct. Commented Oct 10, 2016 at 22:09

2 Answers 2

4

It is simply because the test function is never called so the local variable is never created due to which it throws error

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

It will be available once test() is invoked

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.