1 00:00:01,080 --> 00:00:02,310 Welcome back everybody. 2 00:00:02,310 --> 00:00:02,900 All right. 3 00:00:02,900 --> 00:00:08,800 So let's take a quick look at why the variable is in the function and why it is not inside the function. 4 00:00:08,820 --> 00:00:09,460 OK. 5 00:00:09,630 --> 00:00:13,660 So if we go ahead and meet we just copy or cut this out. 6 00:00:15,510 --> 00:00:16,780 And paste it here. 7 00:00:17,670 --> 00:00:25,770 And you can see that if we type in 23 or even you know anything like awesome like this it doesn't work 8 00:00:26,520 --> 00:00:28,260 and you're thinking well why is that. 9 00:00:28,260 --> 00:00:36,510 Well first of all there's this idea of something called scope K and it has to do with these brackets 10 00:00:36,510 --> 00:00:42,020 here and I'm just going to return that on this and just like that so we can see as a little bit better. 11 00:00:42,060 --> 00:00:47,840 So what it is is that if we were to have let's say another function here. 12 00:00:47,990 --> 00:00:58,610 OK if I just type in function you know fun k and i type in you know another thing here. 13 00:00:58,720 --> 00:01:05,800 All of these variables here can be used in both of these functions and for the most part there would 14 00:01:05,800 --> 00:01:12,910 be what we call quote unquote global variables meaning that you can see each of these variables within 15 00:01:12,910 --> 00:01:13,860 these functions here. 16 00:01:13,880 --> 00:01:18,510 K so variable number you can use it here you can use it here you can use it anywhere. 17 00:01:18,670 --> 00:01:25,060 When you put it inside a curly bracket at any given time it doesn't matter if it's a function or another 18 00:01:25,060 --> 00:01:30,070 kind of computer programming tool that we need. 19 00:01:30,070 --> 00:01:35,770 For example a for loop if we put a variable inside there that means you can't see it out there so change 20 00:01:35,770 --> 00:01:39,550 text variable is not able to see this outside here. 21 00:01:39,550 --> 00:01:46,330 Now the reason why it works in here and the reason why it doesn't work out here is because this document 22 00:01:46,330 --> 00:01:50,150 does get Elmont ID can only be used in a function. 23 00:01:50,370 --> 00:01:55,720 That's why it doesn't really work because it doesn't javascript doesn't necessarily see that as a viable 24 00:01:55,720 --> 00:01:58,050 command outside the functions. 25 00:01:58,060 --> 00:02:04,390 So remember the functions is where most of your computer programming is going to be gay and scope is 26 00:02:04,390 --> 00:02:11,080 really really important because at least when you're typing code like this what ends up happening is 27 00:02:11,080 --> 00:02:12,880 that you have different levels of scope. 28 00:02:12,880 --> 00:02:18,260 Now if you take in any one of my other courses for example the non-program courses for example Harmac 29 00:02:18,270 --> 00:02:22,170 ask the programming how many games though programming they several fathers down quite a bit. 30 00:02:22,180 --> 00:02:29,380 And this is a topic that beginner programmers tend to really struggle with is where you can see variables 31 00:02:29,380 --> 00:02:31,240 and where you can't see variables. 32 00:02:31,240 --> 00:02:35,190 So again if it's outside the function you can see them within every function. 33 00:02:35,200 --> 00:02:38,760 But if it's inside the function you can only see that within functions here. 34 00:02:38,980 --> 00:02:40,640 Now right now there's only two levels. 35 00:02:40,720 --> 00:02:46,280 There's a global which is these up here and a local which is in the function. 36 00:02:46,330 --> 00:02:47,320 And again there could be more. 37 00:02:47,320 --> 00:02:51,400 So it's better to think of these as just these two two kinds of variables. 38 00:02:51,400 --> 00:02:52,630 At this point in time. 39 00:02:52,660 --> 00:02:54,890 All right see you guys in next tutorial.