Member-only story
JavaScript Concepts That Finally Made Sense After I Saw These Examples
Dr Abdullah Azhar
10 min readJust now
Press enter or click to view image in full size Image by ChatGPT
Initially, I considered JavaScript an easy language to learn.
You just declare variables, write functions, work with arrays, and create something useful. All seems clear and simple until you get to the point where you need to work with such things as closures, prototypes, promises, this, and the event loop.
Suddenly, your code starts acting in unexpected ways.
Why is this variable referring to a different object in a different function? Why is a promise executed before a setTimeout() callback, even if the delay parameter is set to zero? How is a function capable of remembering the variables of its outer scope?
And I realized that the problem was not in the concepts.…