Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

The `this` Keyword – Binding Rule | JavaScript Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. JavaScript Course

Lesson 12 of 55

·javascript

The `this` Keyword – Binding Rules

12 mins

Course progress22%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `this` is **not** bound at function definition time – it’s determined when the function is *called*.
  • Arrow functions are ideal for callbacks that need the outer `this` (e.g., class methods).
  • Use `Function.prototype.bind` or `call`/`apply` to set `this` explicitly.

How this is set depends on call site:

  • Function call – this is undefined in strict mode, otherwise the global object.
  • Method call – obj.method() → this is obj.
  • Constructor (new) – this is the newly created object.
  • Arrow function – this is lexically inherited from the surrounding scope.
  • Event listeners – this points to the element the listener is attached to (unless an arrow function is used).

Example: Arrow vs normal function in an event listener

const btn = document.querySelector('button');
btn.addEventListener('click', function(){ console.log(this); }); // logs <button>
btn.addEventListener('click', () => { console.log(this); }); // logs Window (lexical this)
Make it stickPractice what you've learned1 quiz · 7 practical tests · Optional activities from JavaScript CourseBrowse activities
Previous lessonEvent Propagation – Capturing, Bubbling & `stopPropagation`Continue to lesson 13Modern JavaScript – ES6 ModulesBack to JavaScript Course curriculum