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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 12 of 55 · javascript

The `this` Keyword – Binding Rules

Duration: 12 mins

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)
Previous: Event Propagation – Capturing, Bubbling & `stopPropagation`Next: Modern JavaScript – ES6 Modules