Recall & Review
beginner
What does
this refer to inside a regular object method?this refers to the object that owns the method. It points to the object before the dot when the method is called.Click to reveal answer
beginner
How does
this behave inside a function called without an object?In non-strict mode,
this refers to the global object (like window in browsers). In strict mode, this is undefined.Click to reveal answer
intermediate
What happens to
this when using arrow functions inside objects?Arrow functions do not have their own
this. They inherit this from the surrounding code where they are defined.Click to reveal answer
intermediate
How can you explicitly set
this when calling a function?You can use
call(), apply(), or bind() methods to set this explicitly.Click to reveal answer
intermediate
What is a common mistake when using
this inside callbacks in objects?Callbacks often lose the original
this context because they are called as regular functions. Using arrow functions or binding this fixes this.Click to reveal answer
Inside an object method, what does
this refer to?✗ Incorrect
this inside an object method points to the object that owns the method.What does
this refer to inside an arrow function defined in an object?✗ Incorrect
Arrow functions inherit
this from their surrounding context, not from the object.Which method can you use to explicitly set
this when calling a function?✗ Incorrect
call() lets you specify what this should be inside the function.What happens if you call a regular function (not a method) in strict mode without setting
this?✗ Incorrect
In strict mode,
this is undefined in a regular function call without an object.Why might
this lose its expected value inside a callback function?✗ Incorrect
Callbacks are often called as regular functions, so
this does not point to the original object unless handled.Explain how
this works inside an object method and how it differs in arrow functions inside objects.Think about how the function is called and where arrow functions get their this.
You got /3 concepts.
Describe ways to control or change the value of
this when calling functions in JavaScript.Remember the three methods that let you set this explicitly.
You got /3 concepts.