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
View all comments
Show parent comment
2
u/delventhalz Feb 18 '26
Seems like a distinction without a difference. The
supercall makesthisan instance of the Base class sure, but it is still the object which will be returned by the Derived constructor....oof. Well, it was news to me that ES modules have a different root-scope
thisthan strict mode and CJS modules have a different root-scopethisthan the Node console. So the complete (?) list of possible root-scopethisvalues would be:window(browser console, vanilla JS files run in browser, including when in strict mod)global(Node console)undefined(ES modules)exports(CJS modules)Fair enough. I studiously avoid thinking about
withblocks, but they maybe should have gotten their own entry above. If I had describedthismore conceptually (i.e. "the object the method is called on"), awithblock would be self-explanatory, but of course I decided to focus on how the literal code looks, andwithdoes indeed change the way the code is written.