Opened the examples folder and then open the global scope sub folder. Now let's look at the exe example global scope one. Here I have a global variable called speed, I know that's global because it's not in a function is defined outside of a function. So I declare the the variable speed, which is equal to 25. And then I have a console log statement outputting, that variable, and we should get 25 in the console. So if I click show examples, and then global scope, example one, we can see we get global speed 25 not a big surprise.
So let's look at global scope number two. So once again, I have the global variable speed, which is equal 25. But then I have this function inside of the function. I also output in the console speed from foo, which is the global speed variable defined on line three. And then on line nine, I have the console log statement to output, the value the global variable and online 10 execute foo, which also outputs that global variable. So let's take Look at show examples global scope two.
And I see the two messages speed from global scope 25 speed one through 25. Pretty simple stuff. But the point here is that a global variable is one is defined in the global scope. And we know we're in in global scope if we're not in a function, because variable speed is not defined in a function, which means it's global, even though we access it in a function on line six. This speed variable right here is still referencing the global speed. And then we're outputting it here.
So just remember that a global variable is one that is defined outside of a function