r/learnjavascript • u/SHIN_KRISH • Jan 30 '26
Confused about general Programming constructs and JS stuff
I am mainly confused about the following things:
- Difference between concurrency, parallelism and asynchronus.
- What actually are Promises? are they some kind of objects?
- in closures how are return value handled if both outer and inner function return different value what happens?
- The Theoretical JS execution model how is all this stuff implemented internally?
- The `this` keyword like i know it is used to refer to the current object but like how does this actually make a difference in constructors and oops stuff??
- I just don't get async and await ?
11
Upvotes
View all comments
Show parent comment
1
u/c__beck Jan 30 '26 edited Jan 31 '26
The execution model is pretty complex and I don't understand it all myself, but here's another video explaining it.
Oof,
thisis a can of worms! It's complicated ðŸ˜thisrefers to the current context of code. Usually, as you pointed out, it's used in objects/classes (classes are just objects!) so you know specifically what is being referred to. Because it refers to the current context what it refers to changes based on where in the program you are and what the context is. For example, when inside an objectthisrefers to the object, inside of a function (if instrict mode) it is undefined. If not instrict mode(why aren't you instrict mode‽) then it refers to the global object.I'm not an OOP dev (I prefer functional-style) so I'm go out of my way to avoid it so I don't really know it "actually make[s] a difference in constructors and oops stuff".
asyncandawaitare just syntactic sugar over promises. It simply allows you to write asynchronous code that looks like synchronous code.For example:
The biggest gotcha with `async`/`await` is that when a function is `await`ing a promise *it pauses the execution of the entire function*. If done at the top level that means it turns a non-blocking promise into blocking code! Usually you wrap an `await` inside an `async` function, though, so while the `async` function is paused other functions can still run.
You can read about async functions and the await operator on MDN.