Menu

Post image 1
Post image 2
1 / 2
0

Understanding `this` in JavaScript: The Complete Guide

DEV Community·Maxim Logunov·24 days ago
#ualrVn34
#regular#arrow#in#old#use#fullscreen
Reading 0:00
15s threshold

The this keyword is one of the most important — and most misunderstood — concepts in JavaScript. Many developers memorize rules like: “Arrow functions don’t have their own this ” “Regular functions depend on how they are called” “Use arrow functions in callbacks” But without understanding why JavaScript behaves this way internally, confusion quickly appears in real projects. This article explains everything step by step: how this works in regular functions, how arrow functions “capture” this , what “lexical binding” actually means, how call , apply , and bind affect this , why classes behave differently, common mistakes, advantages and disadvantages of each approach. After reading this guide, you should have a complete mental model of this in JavaScript. 1. What Is this ? In JavaScript, this is a special keyword that refers to an object associated with the current function execution. The important thing is: this is determined differently depending on the type of function.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More