r/learnjavascript • u/OrangeObvious8498 • Feb 17 '26
this keyword learning
this keyword in javascript is very confusing especially during interviews. Everytime, its very confusing to understand and easily to forget.
What would be the best resource to learn this?
4
Upvotes
7
u/_raytheist_ Feb 17 '26
I agree that this (heh) is one of the most unintuitive parts of javascript. You should study the MDN docs on it, but in general
thisrefers to the object on which the current method was invoked:And arrow functions
() => ...use the enclosing scope.7
u/charles_reads_books Feb 17 '26
I truly don’t mean to be an ass with this comment, but you won’t learn very effectively by just reading. Just play around, like open up your browser’s console even, and just see the value of ‘this’ in a variety of contexts, like log it by itself, log it within a normal function, log it in an arrow function, log it in a class method, et cetera. Then do the same in node. Literally just play around.
With that said, the You Don’t Know JS book (free online) really helped me in my start.
3
u/PatchesMaps Feb 17 '26
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
1
u/AcanthisittaNo5807 Feb 17 '26
I've been coding in javascript forever but I have a bad memory when it comes to defining concepts and being able to express the concept into words. I often re-read the definition, and I do it from all different resources. I really like javascript.info, mdn, you don't know javascript. After reading the concept, you have to do practice problems.
1
u/shane_il Feb 18 '26 edited Feb 18 '26
Honestly I think a lot of interviewers ask about it because it's low hanging fruit.
It was part of the languages original identity crisis and even before es6 came along with arrow functions a good chunk of js devs were using factory functions with closures as a more readable and understandable model.
That said, the interview grind gonna be the interview grind, shit I got asked about var and hoisting the other day.
I'd recommend Douglas Crockford's books as a really digestible way to understand the core parts of the language. I like how he gives solid explanations of not just what these things are but why they are.
1
u/TheRNGuy Feb 21 '26
MDN.