How do you get the variable from the function?



  • Hi. If I create a function

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

    qwe();

    how to get a variable x? When the function is in operation (if the breikpoint is inserted), it can be obtained - written in the consoles x; But if I write, window.x; - I'll be there. undefinedalthough records x; and window.x; It means the same thing.

    What is execution context? Would you write in your own words, as you can see, how execution context relates to scope? Is that different or not?



  • Unfortunately, there's no way. Modified, internalized functions are available only within it and within the functions assumed (closure).

    If I write window,x;

    A comma? Syntaxically correct, but that's not what you want to write. You probably want a point. But it won't work anyway. x and window.x means the same (and not exactly) only if the current scoop did not declare a name variable x♪ It was in your code.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2