
Why Do Clicks “Stack Up” When JavaScript Blocks the UI?
I recently noticed something interesting while experimenting with JavaScript. I wrote a simple synchronous loop that runs for about 10 seconds: const start = Date . now (); while ( Date . now () - start < 10000 ) { // Block for 10 seconds } During those 10 seconds, the UI completely freezes. That part makes sense. But here’s the interesting part: While the loop was running, I kept clicking a button on the page. Nothing happened. No console logs. No UI updates. Then the loop finished… And suddenly, all my clicks fired at once. It felt like the browser had “saved” them somewhere. So what’s actually happening? The Short Answer: OS Input Buffering When JavaScript runs a heavy synchronous task, the main thread (Call Stack) is blocked. But JavaScript freezing does not mean your entire system freezes. Let’s break it down: 1️ Hardware Level When you click your mouse, the hardware sends an interrupt signal to the Operating System. 2️ OS Level The OS records that click in its input buffer. Even
Continue reading on Dev.to Webdev
Opens in a new tab

