JavaScript Events

Last Updated :
Discuss
Comments

Question 1

Which method is used to attach an event listener to an element?

  • A

    addEvent()

  • B

    addEventListener()

  • C

    attachListener()

  • D

    onEvent()

Question 2

What event is triggered when a user clicks on an element?

  • A

    change

  • B

    mouseover

  • C

    click

  • D

    keydown

Question 3

Which method prevents the default behavior of an event?

  • A

    stopDefault()

  • B

    preventDefault()

  • C

    cancelDefault()

  • D

    stopPropagation()

Question 4

What is event delegation?

  • A

    Adding multiple event listeners to child elements

  • B

    Using a single event listener on a parent element to handle events on its child elements

  • C

    Delaying an event listener

  • D

    Removing an event listener

Question 5

Which property determines the type of event that was triggered?

  • A

    event.type

  • B

    event.name

  • C

    event.trigger

  • D

    event.value

Question 6

What is the difference between event.target and event.currentTarget?

  • A

    event.target refers to the element that triggered the event, while event.currentTarget refers to the element the event listener is attached to

  • B

    Both refer to the element that triggered the event

  • C

    event.target refers to the event listener, while event.currentTarget refers to the triggering element

  • D

    Both refer to the parent element of the triggering element

Question 7

What is the purpose of throttling in event handling?

  • A

    To execute an event listener only once

  • B

    To control the frequency of event execution

  • C

    To cancel an event listener

  • D

    To delay event execution indefinitely

Question 8

Which event is fired when a key is pressed down?

  • A

    keyup

  • B

    keydown

  • C

    keypress

  • D

    keychange

Question 9

What does stopPropagation() do?

  • A

    Prevents the default action of an event

  • B

    Cancels the current event

  • C

    Delays the event execution

  • D

    Stops the event from bubbling up or down the DOM hierarchy

Question 10

What is the output of the following code?

JavaScript
document.addEventListener("click", () => {
    console.log("Document clicked");
});
document.body.addEventListener("click", () => {
    console.log("Body clicked");
});


  • A

    Document clicked

  • B

    Body clicked

  • C

    Body clicked, Document clicked

  • D

    Document clicked, Body clicked

There are 10 questions to complete.

Take a part in the ongoing discussion