Recall & Review
beginner
What does
this refer to in the global scope in JavaScript?In the global scope,
this refers to the global object. In browsers, this is usually the window object.Click to reveal answer
intermediate
How does
this behave differently in strict mode in the global scope?In strict mode,
this in the global scope is undefined instead of the global object.Click to reveal answer
intermediate
What is the global object in Node.js when using
this in the global scope?In Node.js, the global object is
global, but this in the top-level global scope of a module is not global; it is an empty object {}.Click to reveal answer
beginner
Code snippet:
console.log(this);What will this print in a browser's global scope?
It will print the
window object, which is the global object in browsers.Click to reveal answer
beginner
Why is understanding
this in the global scope important?Because it helps you know what object your code is referring to, avoiding bugs and unexpected behavior especially when switching between strict mode and non-strict mode or different environments.
Click to reveal answer
In a browser, what does
this refer to in the global scope (non-strict mode)?✗ Incorrect
this in the global scope refers to the global object, which is window in browsers.What is the value of
this in the global scope when running JavaScript in strict mode?✗ Incorrect
In strict mode,
this in the global scope is undefined.In Node.js modules, what does
this refer to at the top-level global scope?✗ Incorrect
In Node.js modules,
this at the top-level is an empty object, not the global object.Which of the following is true about
this in the global scope?✗ Incorrect
In strict mode,
this in the global scope is undefined; otherwise, it refers to the global object.What will
console.log(this === window); output in a browser's global scope (non-strict mode)?✗ Incorrect
In the browser global scope,
this is the window object, so the comparison is true.Explain what
this refers to in the global scope in JavaScript and how strict mode changes it.Think about what object <code>this</code> points to when you run code outside any function.
You got /4 concepts.
Describe how
this behaves differently in the global scope between browser and Node.js environments.Consider the global objects and module system in both environments.
You got /4 concepts.