Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73992

Can someone explain why hjk isn't printing everytime I click

$
0
0
   (https://jsbin.com/bovesapoyu/edit?html,js,console,output)-hjk isn't printing

Can someone explain why hgk isn't printing every time I click? When I click on button every time it should run debounce function and it should print 'hgk' ,but why this isn't printing it. Anyone of you can explain it to me with clear explanation?

const debounce=(fn,delay)=>{

let timer;
 console.log('hgk');
  return function(){
    console.log('nbm');
 clearTimeout(timer);
    timer= setTimeout(fn,delay);
}
}



document.getElementById('button').addEventListener('click',debounce(()=>{
  console.log('clicked')
},2000));
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>JS Bin</title></head><body></body></html>

Viewing all articles
Browse latest Browse all 73992

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>