(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>