Common this Keyword Interview Questions in JavaScript
this is asked in almost every JS interview. Here are the most common questions with clear answers and code.
Common this Keyword Interview Questions in JavaScript
this is one of the most asked interview topics. Here are the common questions, with answers and code you can practice.
Q1: What is the output?
function foo() { console.log(this); } foo();
Answer: window (non-strict) or undefined (strict mode). Plain call uses default binding.
Q2: What is the output?
const obj = { x: 10, foo() { console.log(this.x); }, }; obj.foo();
Answer: 10. Method call: this is obj.
Q3: What is the output?
const obj = { x: 10, foo() { console.log(this.x); }, }; const fn = obj.foo; fn();
Answer: undefined (strict) or window.x (non-strict). Detaching the method loses this.
Q4: What is the output?
const obj = { x: 10, foo: () => console.log(this.x), }; obj.foo();
Answer: undefined. Arrow inherits this from the enclosing scope, not obj.
Q5: What is the output?
function Person(name) { this.name = name; setTimeout(function () { console.log(this.name); }, 0); } new Person("Kunal");
Answer: undefined (or window.name). The callback is a plain call, so this is not the instance.
Q6: What is the output?
function Person(name) { this.name = name; setTimeout(() => { console.log(this.name); }, 0); } new Person("Kunal");
Answer: "Kunal". The arrow inherits this from Person's scope, where this is the instance.
Q7: What is the output?
const obj = { x: 10 }; function foo() { return this.x; } console.log(foo.call(obj));
Answer: 10. call sets this to obj.
Q8: What is the output?
const obj = { x: 10 }; function foo(y) { return this.x + y; } const bound = foo.bind(obj, 5); console.log(bound());
Answer: 15. bind presets this and the first argument.
Tips for Interviews
- Identify the call type: plain, method, call/apply/bind, new, or arrow.
- Apply precedence: new > bind > call/apply > method > default.
- For arrows, ignore call type;
thisis lexical. - Mention strict mode: plain calls give
undefined, notwindow.
The Takeaway
this interview questions test the five rules: default, implicit, explicit, new, and arrow (lexical). Identify the call type, apply precedence, account for strict mode, and remember arrows inherit this.
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.
new binding (highest) > explicit binding (bind/call/apply) > implicit binding (method call) > default binding (plain call). Arrow functions are an exception: they use lexical this and ignore all of these.
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.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

