1
00:00:02,090 --> 00:00:06,080
Let's have a look at this interpreted on-the-fly compile thing.

2
00:00:06,080 --> 00:00:08,320
How is the Javascript code in our browser

3
00:00:08,330 --> 00:00:15,410
executed and not just in our browser but typically in any environment where you run Javascript? Let's

4
00:00:15,410 --> 00:00:20,160
say you write your Javascript code and you want it to have some effect on the web page

5
00:00:20,180 --> 00:00:26,930
if we talk about the browser as the environment where we run our script. Then you have one important

6
00:00:27,230 --> 00:00:32,680
thing built into any environment where you want to run Javascript code

7
00:00:32,680 --> 00:00:34,890
and that's a Javascript engine.

8
00:00:34,940 --> 00:00:39,860
It's built into the browser as I said, there in Chrome for example, in the Chrome browser,

9
00:00:39,920 --> 00:00:41,060
it's v8,

10
00:00:41,060 --> 00:00:43,580
that's the name of the engine, in Firefox

11
00:00:43,580 --> 00:00:45,230
the name would be spider monkey

12
00:00:45,230 --> 00:00:50,520
and of course other browsers also either reuse these engines or have their own engines.

13
00:00:50,540 --> 00:00:58,920
Now the job of the engine is to parse code, so parse, read and understand your Javascript code,

14
00:00:58,970 --> 00:01:05,660
then on the fly compile it to machine code because machine code executes faster,

15
00:01:05,660 --> 00:01:12,050
so it reads your code but it does not necessarily execute it like that but instead, it now takes that code

16
00:01:12,050 --> 00:01:18,920
and compiles it to code which is faster to execute by the machine and then it executes that machine

17
00:01:18,920 --> 00:01:19,310
code.

18
00:01:19,310 --> 00:01:24,700
This all happens in the browser with the help of the Javascript engine

19
00:01:24,830 --> 00:01:29,330
and then when that code is executed, we have that effect on our web page.

20
00:01:29,330 --> 00:01:33,700
Now important, modern engines have a lot of optimizations there,

21
00:01:33,710 --> 00:01:40,160
they might start executing your uncompiled code and then compile the code whilst they're also already

22
00:01:40,160 --> 00:01:46,280
executing it to get started executing faster and then switch to the compiled code dynamically and so on,

23
00:01:46,280 --> 00:01:51,620
so we have a lot of optimizations going on here and we will dig a bit deeper into what the Javascript

24
00:01:51,680 --> 00:01:52,730
engine is

25
00:01:52,730 --> 00:01:53,360
exactly

26
00:01:53,360 --> 00:01:58,670
in a separate module in the course, for now this is all we need to know, the browser has a built-in tool

27
00:01:58,670 --> 00:02:02,930
that takes our code, compiles it, optimizes it and executes it

28
00:02:03,080 --> 00:02:09,640
and also a bit more technical side note, all of that happens on a single thread.

29
00:02:09,710 --> 00:02:17,570
Now this is very technical but you might know that in a computer, you have certain tasks that are executed,

30
00:02:17,630 --> 00:02:23,630
for example the browser you opened is a task or actually might consist of multiple different tasks

31
00:02:23,930 --> 00:02:25,910
that are executed together.

32
00:02:25,910 --> 00:02:32,120
The Javascript code is also yet another task which your operating system in the end has to take care

33
00:02:32,120 --> 00:02:32,430
of

34
00:02:32,450 --> 00:02:34,950
and this runs on a single thread.

35
00:02:35,210 --> 00:02:41,210
Of course we have multi-threading on modern machines so that they can do multiple tasks at the same time

36
00:02:41,330 --> 00:02:46,100
but the Javascript code execution runs on one single thread there,

37
00:02:46,100 --> 00:02:51,860
so the Javascript code execution always happens in one single thread on your operating system.

38
00:02:51,860 --> 00:02:53,300
Right now this doesn't really matter,

39
00:02:53,300 --> 00:02:58,490
it will become more important later in the course though when I will come back to this concept of single

40
00:02:58,490 --> 00:03:03,050
threading and which implications this has for Javascript.

41
00:03:03,200 --> 00:03:10,130
But with that we know what interpreted means, what compilation means and how the Javascript code is executed.

42
00:03:10,130 --> 00:03:12,740
What does dynamic and weakly type mean then?
