Ghost Together
1 min readDec 5, 2018

--

When in <script> tag we are in Global Scope. Basically, it’s like being inside the main Window object, which is instantiated when you arrive at a URL.

It’s similar to this idea:

// Create a constructor function
let x = function Window() { this.x = 1; }
// Instantiate the object
let window = new x();
// Output x
alert(window.x); // 1

However, there is a difference between this object and simply assigning variables with var. Basically this-binding and Variable Environment are part of the same scope { }

It’s a bit tricky to explain — as many things in JavaScript — because if you try this in strict mode (the preferred way) it won’t even work in the same way. But most people learning JavaScript don’t learn variable definitions in strict mode. Hence layers of confusion. At the end of the day… keep experimenting and absorbing… eventually it’ll start making sense.

--

--

Ghost Together
Ghost Together

Written by Ghost Together

Ghost Together @ https://semicolon.dev is an alternative to Twitter. Sign up to meet other makers of things.

No responses yet