var limit = 200; const buddy = () => { console.log('buddy') } var control = false; window.onscroll = () => { if (window.scrollY >= limit) { if (control == false) { buddy(); } control = true; } else { control = false; } }