⏱️ Debounce Function in JavaScript
Category: js / utils
Difficulty: medium
Interview Importance: 🔴 Critical — One of the most commonly asked JavaScript interview questions. Expected at every level from junior to senior. 1️⃣ What is Debounce? Debounce is a technique that delays the execution of a function until a certain amount of time has passed since the last time it was invoked. If the function is called again before the delay completes, the timer resets. Real-World Analogy Think of an elevator door: When someone enters, the door waits a few seconds before closing If another person enters during that wait, the timer resets The door only closes after no one has entered for the full delay period [code example] 2️⃣ Why Use Debounce? Common Use Cases Problem Without Debounce API call on every keystroke Layout calculation on every pixel Multiple submissions on rapid clicks Save on every character Hundreds of events per scroll Performance Impact [code example]...