Javascript Fundamentals: ‘this’ keyword
I think the main reason &quot;this&quot; is considered confusing is that many programmers learning JS have already spent years coding in Java or C#. They expect it to work the same, then get frustrated when it doesn&#x27;t. But the reason it doesn&#x27;t is due to the fact that functions in JS are first-class, and don&#x27;t intrinsically belong to a particular class and object instance they way they do in those languages. As such, the context represented by &quot;this&quot; <i>has</i> to be more fluid in JS.<p>That&#x27;s not to say that the design of &quot;this&quot; is perfect. And it doesn&#x27;t help that JS&#x27; syntax was designed to resemble C-family languages that it differs from significantly. But nor it is some entirely arbitrary and illogical flaw. If you take the time, it&#x27;s possible to gain an intuitive grasp of how functions and &quot;this&quot; work in JS. But instead, learners are too often told that &quot;JS is quirky&quot; by others who also have come to it from Java &#x2F; C#, and never move past memorizing to a list of these &quot;quirks&quot; to genuine proficiency. They then grumble whenever they need to work on a JS codebase, because their incomplete understanding makes it feel like they&#x27;re standing on quicksand.<p>Soon such devs fall into a circular trap: They don&#x27;t like coding in JS because it feels weird and unintuitive. And they don&#x27;t take the time to learn about it more deeply because they don&#x27;t like coding with it, and don&#x27;t want to waste time learning about something they dislike. But since they <i>have</i> to code with it, because it&#x27;s part of their job, they just stumble along, hacking away and getting frustrated when things don&#x27;t work, then come onto Hacker News and blow off steam about what a garbage language JS is.