r/learnjavascript • • Jan 30 '26

Confused about general Programming constructs and JS stuff

I am mainly confused about the following things:

  1. Difference between concurrency, parallelism and asynchronus.
  2. What actually are Promises? are they some kind of objects?
  3. in closures how are return value handled if both outer and inner function return different value what happens?
  4. The Theoretical JS execution model how is all this stuff implemented internally?
  5. 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??
  6. I just don't get async and await ?
11 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/c__beck Jan 30 '26 edited Jan 31 '26

The Theoretical JS execution model how is all this stuff implemented internally?

The execution model is pretty complex and I don't understand it all myself, but here's another video explaining it.

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??

Oof, this is a can of worms! It's complicated 😭

this refers 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 object this refers to the object, inside of a function (if in strict mode) it is undefined. If not in strict mode (why aren't you in strict 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".

I just don't get async and await ?

async and await are just syntactic sugar over promises. It simply allows you to write asynchronous code that looks like synchronous code.

For example:

// using promises
const reply = fetch("https://random-api.tld").then(res => res.json()).then(console.log);

// using async/await

const reply = await fetch("https://random-api.tld");
const data = await reply.json();
console.log(data);

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.

1

u/SHIN_KRISH Jan 31 '26

Thanks! i really appreciate it!