Interview Hub
Sign in

Q4: How does `this` get bound in JavaScript?

MidJavaScript 29

Answer

In non-strict mode, this in a plain function call is the global object (browser: window; strict: undefined). Method calls set this to the receiver. call/apply/bind set it explicitly. Arrow functions inherit this from the enclosing lexical scope. In classes, this in instance methods refers to the instance (watch unbound methods passed as callbacks — need arrow or .bind).

Having a tech or coding interview? Check 29 JavaScript & Node.js interview questions.

EditorJavaScript · local only