Which method is used to attach an event listener to an element?
What event is triggered when a user clicks on an element?
Which method prevents the default behavior of an event?
What is event delegation?
Adding multiple event listeners to child elements
Using a single event listener on a parent element to handle events on its child elements
Delaying an event listener
Removing an event listener
Which property determines the type of event that was triggered?
What is the difference between event.target and event.currentTarget?
event.target refers to the element that triggered the event, while event.currentTarget refers to the element the event listener is attached to
Both refer to the element that triggered the event
event.target refers to the event listener, while event.currentTarget refers to the triggering element
Both refer to the parent element of the triggering element
What is the purpose of throttling in event handling?
To execute an event listener only once
To control the frequency of event execution
To cancel an event listener
To delay event execution indefinitely
Which event is fired when a key is pressed down?
What does stopPropagation() do?
Prevents the default action of an event
Cancels the current event
Delays the event execution
Stops the event from bubbling up or down the DOM hierarchy
What is the output of the following code?
JavaScript
document . addEventListener ( "click" , () => {
console . log ( "Document clicked" );
});
document . body . addEventListener ( "click" , () => {
console . log ( "Body clicked" );
});
Body clicked, Document clicked
Document clicked, Body clicked
Ready to go from coding beginner to development pro? Our DSA to Development Coding Guide has everything you need to crush coding interviews and ace real-world projects! Limited spots available!Enroll Now and Transform Your Coding Skills! Also get 90% fee refund on completing 90% of the course in 90 days ! Take the Three 90 Challenge today.
There are 10 questions to complete.
Take a part in the ongoing discussion View All Discussion