In previous lecture, you have introduced what the execution context is, so it's like a container that
managed the code that is currently running and when something is running your brother, execution context
is created.
And at the same time, JavaScript engine prepares the environment for execution JavaScript code.
Let's take a look on the screen and see together how it actually happens when a stimulus package is
loaded in a Web browser, even without link for JavaScript file, the engine prepares the environment
for running JavaScript code.
At this time, the global execution context is created, which we have not discussed yet up until this
point.
So what is that?
Global execution context is a base execution context that manages the code, which is not inside a function,
and it is created immediately when the page is loaded.
So the global execution context managed when the cold execution starts and ends and you will see deeper
incoming videos before it actually starts to execute the code, it creates global object, which is
the same as window object.
A global object is an object that always exists in the global scope and simultaneously there is created
a special keyword of this, which is equal to global object at the global level.
I know that all this stuff sounds a little bit confusing.
Therefore, I'm going to use some practical examples.
Let's go back to your text.
Ed, I want to show you something.
You have our empty script, dodgiest file.
Now let's go to index, not HTML, and post the link between index, e-mail and script digest files
commented out.
So it means that we have no longer connection with JS file.
And as we said, the engine prepares the environment for run the codes.
Even without loading JavaScript file.
We can prove that.
Now you remember that once we have used a method from document object model in previous videos, this
method allows us to access on elements.
I mean, document out that element by ID.
So let's at first assigned the idea attribute for H1 element and call it header.
Then use the immersion method and writing council document.
Douget 11 by IID, then right here, the idea of the H1 element header and then use the property in
her e-mail.
So you see that we have content of one element.
It means that everything is prepared in browser in order to run and execute JavaScript code.
All right, let's type in console or window, as we said, one, the global execution context is created.
Then it creates a global object, which is literally the same as a window object.
You see that we have here a window object.
If we drop down it, you will see here a list of multiple properties and methods which are already built
in.
So the window object represents an open window in the browser.
In other words, when the original document is loaded, the browser creates a window object for it.
If we write your key word this.
Which is already created when the page was loaded, it will give us the exact same window object.
So this is a special keyboard.
It always refers to the object.
And on a global level, it refers to global window object.
The key word, this is frequently used in JavaScript and you will meet it a lot of times throughout
the course.
OK, so you see that all this stuff happens without any single line of code of JavaScript and even without
linking JavaScript file to HTML document.
All right, now let's get rid of these comments and make a link working, that is cryptologist file
create variable name equals to John.
Reload and now let's check a window object right window.
Then drop down it scroll and you see that here we have our variable name and its value, John.
So when the variable is created outside the function, it's on global level.
And actually it is assigned to the global window object as a property.
So if we write, name will get John.
And who write it as a window name?
Evalu will be the same.
Also, the result will be the same if we use this key word.
Because on a global level, this refers to global window object.
All right, in the same way, we can create function on global level, so right here, function A.
And then right return hello.
Reload and type again or window.
And you can see here that the function is attached to global window object as a method.
In order to call this function, we need to write your function, name A with parentheses.
So we got hello.
And we can call this function as a method of global window object, for that, we need to write window
dot.
A.
And you see that we have again, hello.
OK, in order to make it clearer, let's create an object.
With a property
name and right here, Niek, then create the method.
Might be function and then return hi.
Reload the page, you know that if you want to access on the property or on the method of the object
we have just created, it's mandatory to indicate at first the name of the object.
So write object name.
And then object.
Dalts.
B, which is the name of the method.
But in case of the global level, JavaScript allows us to access on variables and functions without
indicating a window object or QAD each time.
All right, for summarizing this lecture, let's briefly recall what we have just learned.
So when Actimel Page is loaded in a Web browser, then the global execution context is created, which
then creates global object, which is a global window object and a special quixotes, which on global
level refers to global window object.
All right, I hope that everything was clear to know those details is very important and it will be
very useful and helpful for you in the future.
See you in the next video.