⏱️ Throttle Function in JavaScript
Category: js / utils
Difficulty: medium
Interview Importance: 🔴 Critical — Often asked alongside debounce. Understanding the difference between throttle and debounce is essential for any frontend interview. 1️⃣ What is Throttle? Throttle ensures a function is called at most once in a specified time period. Unlike debounce (which waits for silence), throttle guarantees regular execution during continuous events. Real-World Analogy Think of a machine gun with a rate limiter: It can only fire once per second, no matter how fast you pull the trigger Even if you hold the trigger continuously, it fires at regular intervals [code example] 2️⃣ Why Use Throttle? Common Use Cases Problem Without Throttle Hundreds of events per scroll Layout calculations on every pixel Tracking every pixel movement Overwhelming server with requests Inconsistent frame rates Performance Comparison [code example]