Facebook Pixel

Debounce vs Throttle Interview Questions (Walmart)

Walmart asks about debounce vs throttle. Here are the questions and answers.

Debounce vs Throttle Interview Questions (Walmart)

Q1: What is the difference between debounce and throttle?

Debounce: delay until activity stops (last call wins). Throttle: limit to once per interval (rate-limited).

Q2: Implement both from scratch.

Debounce: clearTimeout + setTimeout. Throttle: Date.now() comparison.

Q3: When would you use debounce?

Search input, auto-save, form validation. When the action should happen after activity stops.

Q4: When would you use throttle?

Scroll, mousemove, rapid clicks. When the action should happen at a controlled rate during activity.

Q5: Can you combine debounce and throttle?

Yes. Some libraries offer a hybrid: throttle with a trailing debounce call. This rate-limits during activity and ensures the last call runs.

Q6: What delay would you use for a search input?

300ms (debounce). For scroll: 100ms (throttle). For auto-save: 1000ms (debounce).

The Takeaway

Walmart questions: difference (debounce=after stop, throttle=rate-limited), implement both, when to use each, combining them, and choosing delays. Practice implementing both from scratch and explaining the use cases.

Debounce delays execution until activity stops (only the last call runs, after a delay). Throttle limits to once per interval (executes at a fixed rate, ignoring calls in between).

Debounce: function debounce(fn, delay) { let timer; return function(...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; }. Throttle: function throttle(fn, delay) { let last = 0; return function(...args) { const now = Date.now(); if (now - last >= delay) { last = now; fn.apply(this, args); } }; }.

Debounce for search input (300ms), auto-save (1000ms), form validation (500ms). Throttle for scroll (100ms), mousemove (50ms), rapid button clicks (500ms). Debounce after activity stops; throttle during activity.

Yes. A hybrid approach: throttle during activity (rate-limited) plus a trailing debounce call (ensures the last call runs). Some lodash implementations offer this as the default throttle behavior.

300ms. It is fast enough to feel responsive and slow enough to skip intermediate keystrokes. For scroll throttle: 100ms. For auto-save debounce: 1000ms. Adjust based on the use case.

Ready to master React completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.