WEBVTT

00:01.430 --> 00:08.090
In previous lecture, you have introduced what the execution context is, so it's like a container that

00:08.090 --> 00:15.470
managed the code that is currently running and when something is running your brother, execution context

00:15.470 --> 00:16.310
is created.

00:16.850 --> 00:22.910
And at the same time, JavaScript engine prepares the environment for execution JavaScript code.

00:24.240 --> 00:30.240
Let's take a look on the screen and see together how it actually happens when a stimulus package is

00:30.240 --> 00:39.270
loaded in a Web browser, even without link for JavaScript file, the engine prepares the environment

00:39.270 --> 00:40.980
for running JavaScript code.

00:42.230 --> 00:49.220
At this time, the global execution context is created, which we have not discussed yet up until this

00:49.220 --> 00:49.580
point.

00:50.420 --> 00:51.410
So what is that?

00:52.250 --> 00:59.030
Global execution context is a base execution context that manages the code, which is not inside a function,

00:59.810 --> 01:02.810
and it is created immediately when the page is loaded.

01:03.790 --> 01:11.280
So the global execution context managed when the cold execution starts and ends and you will see deeper

01:11.290 --> 01:20.200
incoming videos before it actually starts to execute the code, it creates global object, which is

01:20.200 --> 01:22.030
the same as window object.

01:22.690 --> 01:29.680
A global object is an object that always exists in the global scope and simultaneously there is created

01:29.680 --> 01:35.450
a special keyword of this, which is equal to global object at the global level.

01:36.880 --> 01:40.000
I know that all this stuff sounds a little bit confusing.

01:40.640 --> 01:43.060
Therefore, I'm going to use some practical examples.

01:44.020 --> 01:45.220
Let's go back to your text.

01:45.220 --> 01:48.370
Ed, I want to show you something.

01:49.180 --> 01:51.830
You have our empty script, dodgiest file.

01:52.570 --> 01:59.950
Now let's go to index, not HTML, and post the link between index, e-mail and script digest files

02:00.550 --> 02:01.380
commented out.

02:03.100 --> 02:06.390
So it means that we have no longer connection with JS file.

02:06.400 --> 02:11.560
And as we said, the engine prepares the environment for run the codes.

02:12.160 --> 02:14.220
Even without loading JavaScript file.

02:15.040 --> 02:15.900
We can prove that.

02:15.910 --> 02:23.500
Now you remember that once we have used a method from document object model in previous videos, this

02:23.500 --> 02:26.650
method allows us to access on elements.

02:27.040 --> 02:30.090
I mean, document out that element by ID.

02:31.060 --> 02:38.380
So let's at first assigned the idea attribute for H1 element and call it header.

02:41.760 --> 02:46.380
Then use the immersion method and writing council document.

02:48.990 --> 02:58.230
Douget 11 by IID, then right here, the idea of the H1 element header and then use the property in

02:58.230 --> 02:59.060
her e-mail.

03:03.930 --> 03:07.450
So you see that we have content of one element.

03:08.490 --> 03:13.920
It means that everything is prepared in browser in order to run and execute JavaScript code.

03:15.300 --> 03:22.320
All right, let's type in console or window, as we said, one, the global execution context is created.

03:23.000 --> 03:29.370
Then it creates a global object, which is literally the same as a window object.

03:29.700 --> 03:32.190
You see that we have here a window object.

03:32.940 --> 03:39.960
If we drop down it, you will see here a list of multiple properties and methods which are already built

03:39.960 --> 03:40.110
in.

03:41.400 --> 03:45.670
So the window object represents an open window in the browser.

03:46.230 --> 03:51.960
In other words, when the original document is loaded, the browser creates a window object for it.

03:54.240 --> 03:56.460
If we write your key word this.

03:57.960 --> 04:04.700
Which is already created when the page was loaded, it will give us the exact same window object.

04:06.210 --> 04:08.600
So this is a special keyboard.

04:09.240 --> 04:10.980
It always refers to the object.

04:10.980 --> 04:14.220
And on a global level, it refers to global window object.

04:15.720 --> 04:21.360
The key word, this is frequently used in JavaScript and you will meet it a lot of times throughout

04:21.360 --> 04:21.900
the course.

04:23.230 --> 04:30.930
OK, so you see that all this stuff happens without any single line of code of JavaScript and even without

04:30.930 --> 04:34.110
linking JavaScript file to HTML document.

04:36.150 --> 04:44.310
All right, now let's get rid of these comments and make a link working, that is cryptologist file

04:44.330 --> 04:48.330
create variable name equals to John.

04:53.230 --> 04:57.790
Reload and now let's check a window object right window.

05:00.660 --> 05:10.150
Then drop down it scroll and you see that here we have our variable name and its value, John.

05:11.670 --> 05:16.860
So when the variable is created outside the function, it's on global level.

05:17.370 --> 05:21.940
And actually it is assigned to the global window object as a property.

05:23.280 --> 05:27.990
So if we write, name will get John.

05:30.120 --> 05:33.080
And who write it as a window name?

05:36.840 --> 05:38.400
Evalu will be the same.

05:40.670 --> 05:44.180
Also, the result will be the same if we use this key word.

05:46.960 --> 05:51.340
Because on a global level, this refers to global window object.

05:53.440 --> 06:02.680
All right, in the same way, we can create function on global level, so right here, function A.

06:04.760 --> 06:07.370
And then right return hello.

06:12.780 --> 06:16.080
Reload and type again or window.

06:20.260 --> 06:27.850
And you can see here that the function is attached to global window object as a method.

06:30.070 --> 06:35.910
In order to call this function, we need to write your function, name A with parentheses.

06:37.810 --> 06:39.250
So we got hello.

06:40.560 --> 06:47.130
And we can call this function as a method of global window object, for that, we need to write window

06:48.180 --> 06:48.660
dot.

06:50.030 --> 06:50.450
A.

06:53.330 --> 06:55.820
And you see that we have again, hello.

06:58.030 --> 07:04.270
OK, in order to make it clearer, let's create an object.

07:07.170 --> 07:08.430
With a property

07:10.830 --> 07:17.760
name and right here, Niek, then create the method.

07:19.240 --> 07:26.290
Might be function and then return hi.

07:31.240 --> 07:38.890
Reload the page, you know that if you want to access on the property or on the method of the object

07:39.610 --> 07:44.740
we have just created, it's mandatory to indicate at first the name of the object.

07:45.520 --> 07:47.170
So write object name.

07:50.850 --> 07:52.290
And then object.

07:53.450 --> 07:53.900
Dalts.

07:55.260 --> 07:58.050
B, which is the name of the method.

08:00.680 --> 08:07.520
But in case of the global level, JavaScript allows us to access on variables and functions without

08:07.520 --> 08:11.840
indicating a window object or QAD each time.

08:14.140 --> 08:20.900
All right, for summarizing this lecture, let's briefly recall what we have just learned.

08:21.970 --> 08:31.090
So when Actimel Page is loaded in a Web browser, then the global execution context is created, which

08:32.080 --> 08:42.670
then creates global object, which is a global window object and a special quixotes, which on global

08:42.670 --> 08:44.890
level refers to global window object.

08:47.750 --> 08:54.500
All right, I hope that everything was clear to know those details is very important and it will be

08:54.500 --> 08:57.050
very useful and helpful for you in the future.

08:58.340 --> 08:59.480
See you in the next video.
