KEY NOT FOUND: coverImgAlt
See All Photos
Best Places to Work 2022


Engaged Employer


Add an Interview

Interview Question

Front End Engineer Interview

-Waterloo, ON


Related to question 1, how could you implement debouncing? Say you wanted the `handleScroll` function to be called only after 200ms has passed between scroll events.

AnswerAdd Tags

Interview Answers

4 Answers


const debounce = (callback, time) => { let timeout = null; return () => { clearTimeout(timeout); timeout = setTimeout[() => { callback(); }, time); } } const logger = (e) => { console.log('server called with'); } window.addEventListener('scroll', debounce(logger, 400));

ela pou sai on


This should really called as throttling instead of deboucing.

Anonymous on


You should use keep track of the time at which the previous scroll was called. var recentScrollTime = 0; var currentScrollEvt = undefined; delayedHandleScroll( delayedHandleScroll = (timeCalled) => { RecentScrollTime = timeCalled; if (timeCalled - recentScrollTime > 200) { ClearTimeout(currentScrollEvt) // check if currentScroll isn’t undefined first though handleScrollFn() } else { if (currentScrollEvent) { ClearTimeout(currentScrollEvt); } // Set the scroll event to fired after the 200ms // this solves the case when the next scroll was called less than 200ms after without dismissing it completely currentScrollEvt = setTimeout[handleScrollFn, timeCalled-recentScrollTime) } }

Anonymous on


(function waitHandleScroll(){ handleScroll(); setTimeout[waitHandleScroll, 200); })();

Osvaldo on

Add Answers or Comments

To comment on this, Sign In or Sign Up.

Meta Careers

Cover image for Meta

Meta builds technologies that help people connect, find communities, and grow businesses. When Facebook launched in 2004, it changed the...More

  • Our Mission
  • Diversity & Inclusion
  • Meta Careers
  • Our Principles
This is the employer's chance to tell you why you should work for them. The information provided is from their perspective.