How is this determined in JavaScript?
By how the function is called, not where it is defined. A plain call gives this as the global object (or undefined in strict mode). A method call gives the object. call, apply, and bind set this explicitly. new creates a fresh object as this.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in The this Keyword in JavaScript: The Basics
call and apply invoke the function immediately with a specific this (call takes comma-separated args, apply takes an array). bind returns a new function with this permanently bound, to be called later.
Arrow functions do not have their own this. They inherit this from the enclosing lexical scope at definition time. call, apply, and bind cannot change an arrow's this.
In a plain function call under strict mode, this is undefined instead of the global object. This prevents accidental pollution of the global object.
Still have questions?
Browse all our FAQs or reach out to our support team
