Menu

1 / 4

What really happens when you run JavaScript? from a single line to a giant app

JavaScript in Plain English - Medium·Sujan Miah·12 days ago
#WftX4ecL
Reading 0:00
15s threshold

Member-only story

What really happens when you run JavaScript? from a single line to a giant app

Sujan Miah

6 min read6 hours ago

Why does this print A D C B ? And why does a 10,000-row dashboard freeze while a login page feels instant? The answer is the same.

Guess the output for below code

console.log('A');

setTimeout(() => console.log('B'), 0);

Promise.resolve().then(() => console.log('C'));

console.log('D');

Most developers guess A B C D . The real output is A D C B . By the end of this article you'll know why. More importantly, you'll understand what happens inside a real application with a login page, API calls, and a complex layout, and what goes wrong when that app gets big.

Part 1: The Four Pieces Behind Everything

JavaScript has one call stack , so it can only do one thing at a time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.