1

In JavaScript; does a let variable declared outside of a block become a global scope?

let letVariable = 2;
console.log(letVariable);
HomTom
  • 558
  • 1
  • 4
  • 12
  • 3
    Does this answer your question? [Do let statements create properties on the global object?](https://stackoverflow.com/questions/28776079/do-let-statements-create-properties-on-the-global-object) – evolutionxbox Jan 06 '21 at 16:39
  • Not really. I can see that the letVariable is accessible but not bind to the window object. Does it mean that the letVariable is a global variable but not a property of the window object? – HomTom Jan 06 '21 at 16:43
  • @HomTom have a read of all the answers. They talk specifically about whether let outside any blocks is equivalent to a var. – evolutionxbox Jan 06 '21 at 16:45
  • 1
    Defining it outside of a block will make it accessible to other functions. It is not shoved onto the window object. So it is global in the sense anything can access it. – epascarello Jan 06 '21 at 16:51

1 Answers1

1

I don't know if I understand you correctly.

There is no "outside of a block", because even if you use it on the blank page, it is in the "main/global block" but only in the same script. its not available from other scripts.

TheMo
  • 109
  • 1
  • 4