I expect the code below to increment the variable counter
each time the event is fired i.e., when the down key is pressed, however it does not. The code increments only once and then nothing happens even if I press the down key.
Can you explain why is it happening?
Also the Firefox's tab keeps showing the loading circle when the event fires, why is that?
Moreover is there a lifetime for the event listener i.e., does it expire when the </script>
is reached?
<html>
<head>
<body>
<script>
var counter=0;
addEventListener("keydown",function(){
counter++;
document.write(counter);
});
</script>
</body>
</html>