Check out a free preview of the full Introduction to JavaScript course
The "Global Objects" Lesson is part of the full, Introduction to JavaScript course featured in this preview video. Here's what you'd learn in this lesson:
Brian demonstrates usage of global objects, specifically the window object in the browser.
Transcript from the "Global Objects" Lesson
[00:00:00]
>> Brian Holt: So here, I'm talking about what this is can be in other settings, right? So that's a console.log like this is window and that's true, right? So in this particular case, whenever I'd call this, it is referring to the entire window. And you can see here that this .scroll which is how far down on the page scroll is exactly the same.
[00:00:24]
In fact, if I change it, it'll change based on where I am which is kind of cool, right? But if I land live in the same place, it won't change, right? I'm not scrolling anywhere. We can see I can access that both on this .scrollY and we know .scrollY, because they are the same thing.
[00:00:48]
Yep, so here, I kind of restate that. If you're inside an object, a good rule of thumb that this will be the object. If you are not inside of an object of some sort, this is gonna be window or whatever the global object is which for browsers is window.
[00:01:08]
>> Speaker 2: [COUGH] The attributes in the objects, do they have names? How we should, call them?
>> Brian Holt: Yeah, like the keys or properties?
>> Speaker 2: Keys, yeah, or just key in.
>> Brian Holt: This is the key. This is the value and the whole thing would be called up like a property.
[00:01:25]
>> Speaker 2: A property, okay.
>> Brian Holt: Yep.
>> Brian Holt: So in here, I have links to Kyle Simpson's which I link here, JavaScript foundations. He actually has a whole section here on learn this. So it is probably a pretty good place to go down, if you want understand it better. If you are doing in job interviews for JavaScript jobs, they love to ask questions about this, because it is so have to.
[00:02:00]
I have problems with JavaScript interviews.
>> Speaker 2: [LAUGH]
>> Brian Holt: It feels more like jeopardy than if feels like an interview. So that's actually, probably a pretty good one to figure out context and what this is and those sorts of things.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops