Mastering `this` in JavaScript

JavaScript developers—new and experienced—constantly rate the variable this
as a major pain of the language. The this
variable, which represents a function’s context, plays an important role in everyday JavaScript programming, so understanding how it works is critical. This blog post gives an overview of this
and its many quirks and forms. We will lay out the four ways to set a function’s this
value, as well as discuss some common use cases and pitfalls.