Hey. If I create a function

function qwe() { var x=10; console.log(x); } qwe(); 

how can you get the variable x ? When the function fulfills (if you set a breakpoint), you can get it - write x in the console; However, if I write window.x; - will be already undefined , although the record x; and window.x; mean the same thing.

What is the execution context? Write, please, in your own words - as you understand. How does the execution context relate to scope? are they different things or not?

  • one
    return, for example. return x at the end of the function. - Nofate
  • 2
    although x entries; and window.x; mean the same thing - this is obvious nonsense and false. - Alexey Ten
  • nothing obvious here - Dimon
  • If in the function you declare the variable x without the avar keyword, that is, simply: x = 10; , then x will be in the global scope. - Don2Quixote

1 answer 1

Unfortunately, no way. Variables declared inside a function are available only inside it and within nested functions (via a closure).

if i write window,x;

Comma? Syntactically correct, but this is not what you want to write. Probably you want a point. But it still does not work. x and window.x mean the same thing (and even then not quite) only if a variable with the name x was not declared in the current scoping. And in your code, it was declared.

  • instead of a comma put a comma. wanted to write window.x; - Dimon
  • what is scop? and how is it different from the executable context? - Dimon
  • @Dimon, available variables. Context is like this . Although there are some more contexts. Unprincipled. - Qwertiy
  • As far as I understand, the execution context is an object. so write in the articles - Dimon
  • Terminology must be dealt with. The standard describes as an object - yes. But there is no access from outside to it. - Qwertiy