DEV Community

Chinwendu Agbaetuo
Chinwendu Agbaetuo

Posted on

JavaScript Quiz - Part 1

The event object for a keydown event has a Boolean property called repeat that tells you if the current keydown was generated as a repeat from holding down the key. How could you modify the keydown handler to respond only to actual key presses, and not automatic repeats?

Solution

document.querySelector("html").addEventListener("keydown", event => {
     if (!event.repeat) {
        console.log(event); 
     } 

    return;
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)