Understanding this — JS Technical Interview Questions & Answers

How this is resolved differently by call site.

Understanding this

  • Understanding this (js keyword) is a JS topic. In plain words you use it for class Student in a tiny OOP file. Don’t start with a slogan — start with that picture.
  • Smallest example: class Student { constructor(name) {} }. Type it, run it, and say what you see. If you can do that from memory, you know Understanding this (js keyword).
  • From the example next to this theory: How this is resolved differently by call site.
  • Trap: arrow function for a method that needs this. Fix that before you talk about advanced JS.
  • Viva: what is Understanding this (js keyword)? Then show class Student { constructor(name) {} }. Then name the trap.

Technical Interview Tip: What is Understanding this (js keyword)? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.

Code Examples for Understanding this

Understanding this — working example

const user = {
  name: "Ada",
  greet() {
    return "Hi " + this.name;
  },
};

console.log(user.greet());

function greet() {
  return "Hi " + this.name;
}
console.log(greet.call({ name: "Lin" }));
console.log(greet.apply({ name: "Riya" }));
const bound = greet.bind({ name: "Sam" });
console.log(bound());

Understanding this — this depends on how a function is called; call/apply/bind set it explicitly.

How to Explain Understanding this to an Interviewer

What is Understanding this (js keyword)?

Used for class Student a tiny OOP file Not just the heading

Give one small example of Understanding this (js keyword).

class Student { constructor(name) {} } How this is resolved differently by call site

What mistake do beginners make with Understanding this (js keyword)?

arrow function for a method that needs this Show the fix

Where do you use Understanding this (js keyword)?

a tiny OOP file class Student