Sometimes scope and context may feel like the same thing. So you may ask yourself, are scoping context ever the same thing? And the answer is no. Except there are times when scope and context may feel like the same thing. Let's talk about implied Global's and implied global is something that happens when you omit the var keyword. So for example, on the left side, I'm creating this function called foo, and I create a speed variable by saying var speed equals five.
So when I do that speed is in the private scope of the Foo function speed is now a private variable. On the right, I'm creating the Foo function again, but I'm just saying speed equals five I omitted the var keyword. Well by omitting the var keyword speed is now a global variable. Because the var keyword was omitted In fact, not only is speed a global variable, it's what's called an implied global, we're implicitly creating a global variable by omitting the var keyword. And in addition to that, speed is now a property of the window object. That's right.
When you create a global variable, either implicitly or explicitly, you create a property on the window object. So by saying speed equals five inside of a function, I'm also saying window dot speed equals five, they both accomplish the exact same thing. In fact, I can also say var speed equals five in the global scope, and it accomplishes the exact same thing. In fact, I can even say speed equals five in the global scope, and that accomplishes the exact same thing. So it's super important to know that what we're doing on the right by saying speed equals five when we omit the var keyword, we're doing two things. We're creating an implied global word Creating a global variable called speed.
And we're also creating a property on the window object called speed. Because any variable that is global also becomes a property of the window object. And this is an example of when scoping and context start to feel like the same thing. Because we're, we're creating a variables that scope, but we're working with an object or giving an object properties. And if we were to create a function or method called window dot get speed, we could say, return this dot speed and it would work. So it's getting into this fuzzy area where scope and context will not being the same thing can sometimes feel like the same thing.
And it's important to understand that they are not, but we're getting into a gray, a gray area where it does feel a little bit confusing. Now if I were to put the var keyword back in this function and say var speed equals five speed is now back in the private scope of the Foo function again. And it is there's no longer a global variable called speed and speed is no longer a property of the window object. Now let's talk about the JavaScript this keyword inside of global functions. So a heavy disclaimer here. For the next couple of minutes, we're talking about JavaScript in the browser.
There's other contexts such as node. But for now, we're just talking about JavaScript as it runs in the browser. And also, there's something called strict mode, which can dramatically change the conversation we're about to have. So just be aware of this. We'll definitely learn more about strict mode and a couple of minutes, we look at the code examples, but just for the next minute or two to try to forget about strict mode and just keep in mind that we're talking about JavaScript running in the browser. Okay.
And if disclaimer, now, this inside of global functions, so inside of the global function, the JavaScript these, this key word is equal to the window object. So on the right side, I'm creating this function called foo, and I reference This and when I referenced this, I'm really referencing a window inside of a global function, the JavaScript, this keyword will always reference the window object. So if I say this dot speed, it's like saying window dot speed. If I say this dot speed equals five, I'm really saying window dot speed equals five. And not only that, I'm also creating a global variable. Because saying we know that the P equals five is like saying in the global scope, var speed equals five, or speed equals five.
This is one of those situations where the lines between scope and context get a little blurry and it can be confusing. They're not the exact same thing, but they come very close in this situation. So just keep in mind that in a globally declared function, or defined function, the JavaScript this keyword references the window object, and you're essentially also creating when you add a property to the window object, you're still creating global variable. I think this will make a little more sense when we look at some code examples. So let's look at some code.