Identify the call type (plain, method, call/apply/bind, new, or arrow), apply the precedence rules, account for strict mode (plain calls give undefined), and remember that arrows use lexical this regardless of call type.
Common this Keyword Interview Questions in JavaScript
How do you approach this questions in a JavaScript interview?
The answer
More FAQs in Common this Keyword Interview Questions in JavaScript
In non-strict mode, this is the global object (window). In strict mode, this is undefined. This is default binding, the lowest precedence rule.
this is lost. Calling const fn = obj.method; fn() is a plain call, so this is the global object or undefined, not obj. Fix with .bind(obj) or an arrow wrapper.
An arrow inside a constructor inherits this from the constructor's scope, where this is the new instance. This is why arrows fix the setTimeout-in-constructor bug.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.