1 00:00:00,120 --> 00:00:05,700 Now we are on Section three coding basics, so we're going to get past the environment that we learned 2 00:00:05,700 --> 00:00:10,290 about in Section two, the history of JavaScript, into a lot of actual coding now. 3 00:00:10,890 --> 00:00:13,320 So first things first, Section three. 4 00:00:13,350 --> 00:00:15,740 Lesson one is about the execution context. 5 00:00:16,080 --> 00:00:17,850 This is more of an abstract idea. 6 00:00:18,150 --> 00:00:21,020 So we're not going to learn a whole lot of code in this lesson. 7 00:00:21,030 --> 00:00:25,140 The whole purpose of this lesson is to understand how JavaScript runs. 8 00:00:25,860 --> 00:00:31,620 And really, it's just the idea that whenever any code is run in JavaScript, it's run inside a specific 9 00:00:31,620 --> 00:00:32,910 execution context. 10 00:00:33,660 --> 00:00:36,260 So there are three that we'll learn about. 11 00:00:36,870 --> 00:00:43,980 There's the global execution context, the functional execution context and the evil execution context. 12 00:00:45,240 --> 00:00:47,040 So let's take a look at those in code. 13 00:00:48,180 --> 00:00:49,350 So we've looked at this before. 14 00:00:49,560 --> 00:00:54,630 We're looking at the example from the end of our coding challenge from section to. 15 00:00:55,910 --> 00:01:03,830 And we have a global execution context in this script that basically refers to anything that is set 16 00:01:03,830 --> 00:01:06,840 up and run at the highest level of the code. 17 00:01:07,760 --> 00:01:13,490 For example, this variable declaration right here, MSgt for message. 18 00:01:14,000 --> 00:01:16,610 This is run at the global execution level. 19 00:01:18,170 --> 00:01:21,230 There is also a function which is defined globally. 20 00:01:22,590 --> 00:01:29,490 But then the contents of this function are inside of another code block, and these are running in a 21 00:01:29,580 --> 00:01:35,100 functional execution context, that just means that they are running inside the function. 22 00:01:35,640 --> 00:01:40,430 And the purpose of execution context is more of a memory usage. 23 00:01:40,440 --> 00:01:46,020 So it's just saying that this is its own script within a script is what functions are. 24 00:01:46,290 --> 00:01:51,120 So it's a block of code that's going to run inside of this other larger script. 25 00:01:51,750 --> 00:01:52,620 So it's like. 26 00:01:53,490 --> 00:01:58,770 The global execution context is running on top of that, you may have a function that runs. 27 00:01:59,640 --> 00:02:06,660 And that it would be a second execution context and then a third execution context is eval. 28 00:02:08,320 --> 00:02:13,810 So evil, basically, you can use to evaluate JavaScript code and execute it. 29 00:02:14,080 --> 00:02:16,660 It's not recommended that we use this anymore. 30 00:02:19,050 --> 00:02:27,210 But you can it's not nobody's going to slap your wrist, but definitely it's something that is deprecated, 31 00:02:27,210 --> 00:02:34,420 mostly replaces functionality, better functionality that we use in the general context. 32 00:02:34,470 --> 00:02:37,040 So I would recommend not using eval. 33 00:02:37,560 --> 00:02:40,410 It's not necessary to run your proper code. 34 00:02:40,860 --> 00:02:47,400 And the reason it's not preferred is that because it runs in its own execution context, it runs its 35 00:02:47,400 --> 00:02:49,620 own set of memory. 36 00:02:49,650 --> 00:02:51,510 So it uses memory on your computer. 37 00:02:52,370 --> 00:03:00,020 And it does so with less efficiency than the global execution context and the functional execution context. 38 00:03:01,270 --> 00:03:09,070 So we can refresh this and it will execute that code for us and it will do it inside its own context, 39 00:03:09,400 --> 00:03:14,670 but generally it's understood that, you know, we don't prefer to use eval, OK? 40 00:03:15,930 --> 00:03:18,630 So we're going to go ahead and comment that out. 41 00:03:20,000 --> 00:03:21,640 And make a note here as well. 42 00:03:25,280 --> 00:03:35,630 Eval is not preferred in its six plus, which is the current version of JavaScript. 43 00:03:36,090 --> 00:03:40,400 OK, so that's pretty much it for lesson one, the execution context. 44 00:03:40,400 --> 00:03:45,950 We just wanted to show you the difference between the global execution context, where anything happens 45 00:03:45,950 --> 00:03:52,340 at this top level, the functional execution context, where anything inside a function will run it 46 00:03:52,340 --> 00:03:53,750 in its own process. 47 00:03:54,920 --> 00:04:02,810 And then this no longer used evil process, which you can use to run code in its own context as well. 48 00:04:03,440 --> 00:04:03,790 OK. 49 00:04:04,910 --> 00:04:11,720 How the order of these operations happened, when it's running the script, it will run the global context 50 00:04:11,720 --> 00:04:14,150 first, then it will run any functions. 51 00:04:14,690 --> 00:04:16,990 And if it has any events, it will run those as well. 52 00:04:18,090 --> 00:04:23,410 OK, that's it for lesson one on to listen to and to listen to. 53 00:04:23,430 --> 00:04:28,800 We're going to be talking about single line and multiline commenting and type coercion and variable 54 00:04:28,800 --> 00:04:29,370 mutation. 55 00:04:30,390 --> 00:04:32,000 OK, see you soon.