Execution Context(Global)

Whenever code is run in Javascript, it is run in the Execution Context, which is a wrapper.

The base execution context is your global execution context.

The _Global Execution Context _creates two things for you by the JS Engine:

  1. Global Object (window)
  2. 'this'

Example 1:

If we run the execute 'this' in the console:

'this' is added automatically by the JS Engine. What is it? It is the window object.

If we run it on Node.js it is not the window object.

Window {stop: function, open: function, alert: function, confirm: function, prompt: function…}

At the global level:

Global Object(window) = 'this'

Global - Means not inside a function

Example 2:

var a = 'Hello World!';

function b() {

}

If we look at window object, we have a and b attached to the Global Object.

In Javascript when you create variable and function, and you are not inside a function,
those variable and function get attached to the Global Object

So we can do (On Chrome Dev Console):
> a
< "Hello World!"

And also do :
> window.a
< "Hello World"

Summary:

results matching ""

    No results matching ""