Course contentsShow
← JavaScript
Lesson 534 of 2,72314. The 'this' KeywordFree lesson

What is 'this'?

Understanding 'this' as a context reference that points to an object at runtime, not at author time.

What is 'this'?

You'll learn what this is and why it's fundamentally different from regular variables.

A Context Reference, Not a Variable

In JavaScript, this is a special keyword that points to an object—but unlike the variables you've worked with so far, you don't get to decide what it points to when you write your code. Instead, JavaScript determines what this refers to when the function runs, based on how that function was called.

Think of this like a pronoun in English. When someone says "I am hungry," the word "I" refers to whoever is speaking—the context matters. Similarly, this refers to different objects depending on the execution context.

Runtime Binding, Not Author-Time

This is crucial: this isn't determined by where you write the function (lexical scope), but by how and where the function is invoked (runtime context). The same function can have this point to completely different objects across different calls.

Consider a real-world analogy: imagine a reusable name tag that says "Hello, my name is THIS PERSON." Whoever wears the tag becomes "this person" at that moment. The tag doesn't belong to anyone permanently—it represents whoever is currently wearing it.

Why This Exists

this allows functions to operate on different objects without rewriting the function for each object. It's a way to write reusable methods that adapt to whatever object they're working with at runtime.

Key Takeaway: this is a context reference that points to an object determined at runtime based on how a function is called, not where it's written in your code.