Skip to content

Instantly share code, notes, and snippets.

View elhamzeinodini's full-sized avatar

Elham Zeinodini elhamzeinodini

  • Finca
View GitHub Profile
@elhamzeinodini
elhamzeinodini / 1.md
Last active October 31, 2025 18:39
You don't know JS / Async & Performance / CH 3

in ajax('url', callback) inversion of control happens, what if instead of a third party calling your callback function, there was a way that the third party can tell you when the async operation (its task) is finished and your program decides to what to do next? that's the idea behind promises and async await


suppose I order a cheeseburger and the cashier promises me to get it after a while (that we don't know exactly when);

  • the cashier gives me a receipt, I hold on to the receipt and in the meantime I text my friend (pending state of promise)
@elhamzeinodini
elhamzeinodini / 1.md
Last active October 31, 2025 21:11
You don't know JS / Async & Performance / CH 1-2
  • even if your js code is in a single *.js file, it mostly constitues of several chunks. a chunk is a piece of code that runs from top to bottom without being interrupted by other code.

  • async is about the gap between now and later, now is the code that gets executed immediately and later is the code that is scheduled to get executed in the future, like a setTimeout , a Promise , ...

  • take a look at the example below and guess which chunks are executed now and which chunks are gonna be executed later ?

function now() {