JavaScriptQuestion 24 of 36
Explain window and this keyword.
Answer out loud or in your head first, then compare.
Answer
window
The global object of the browser environment.
Examples:
JavaScript
window.document
window.location
window.history
window.setTimeoutthis
In a regular function it depends mainly on how the function is called.
JavaScript
const user = {
name: "Tom",
hello() {
console.log(this.name);
}
};
user.hello();Here:
JavaScript
this === userAn arrow function doesn't create its own this.
It takes this from the surrounding lexical scope.
How did it go? Be honest — “Not yet” puts the question on your review list.