Welcome back everybody.
All right.
So let's take a quick look at why the variable is in the function and why it is not inside the function.
OK.
So if we go ahead and meet we just copy or cut this out.
And paste it here.
And you can see that if we type in 23 or even you know anything like awesome like this it doesn't work
and you're thinking well why is that.
Well first of all there's this idea of something called scope K and it has to do with these brackets
here and I'm just going to return that on this and just like that so we can see as a little bit better.
So what it is is that if we were to have let's say another function here.
OK if I just type in function you know fun k and i type in you know another thing here.
All of these variables here can be used in both of these functions and for the most part there would
be what we call quote unquote global variables meaning that you can see each of these variables within
these functions here.
K so variable number you can use it here you can use it here you can use it anywhere.
When you put it inside a curly bracket at any given time it doesn't matter if it's a function or another
kind of computer programming tool that we need.
For example a for loop if we put a variable inside there that means you can't see it out there so change
text variable is not able to see this outside here.
Now the reason why it works in here and the reason why it doesn't work out here is because this document
does get Elmont ID can only be used in a function.
That's why it doesn't really work because it doesn't javascript doesn't necessarily see that as a viable
command outside the functions.
So remember the functions is where most of your computer programming is going to be gay and scope is
really really important because at least when you're typing code like this what ends up happening is
that you have different levels of scope.
Now if you take in any one of my other courses for example the non-program courses for example Harmac
ask the programming how many games though programming they several fathers down quite a bit.
And this is a topic that beginner programmers tend to really struggle with is where you can see variables
and where you can't see variables.
So again if it's outside the function you can see them within every function.
But if it's inside the function you can only see that within functions here.
Now right now there's only two levels.
There's a global which is these up here and a local which is in the function.
And again there could be more.
So it's better to think of these as just these two two kinds of variables.
At this point in time.
All right see you guys in next tutorial.