What is the this keyword in JavaScript?

Answer

The this keyword refers to the object that is executing the current function — its value depends on how the function is called, not where it is defined. In a regular function call: this is undefined in strict mode or the global object (window) in sloppy mode. In a method call: this is the object before the dot. With new: this is the newly created object. In an event handler: this is the DOM element. With call(), apply(), bind(): this is explicitly set. Arrow functions inherit this from their lexical enclosing scope and cannot be rebound. bind(obj) creates a new function with this permanently bound to obj. Understanding this is one of the most common JavaScript interview topics.