Getting Started with JavaScript for Web Development: Lesson 17 of 23

Scroll Progress

Up Next

Floating Input

Autoplaying in 7 seconds!


Table of Contents

    Debounce Function

    function debounce(func, wait = 15, immediate) {
      var timeout;
      return function() {
        var context = this, args = arguments;
        var later = function() {
          timeout = null;
          if (!immediate) func.apply(context, args);
        var callNow = immediate && !timeout;
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);

    Chris Sevilleja

    176 posts

    Founder of Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.