Question of the Day: Event Handling in JavaScript 🚀

Erasmus Kotoka - May 23 - - Dev Community

Hey everyone! Let's dive into the world of JavaScript together. Here’s an interactive question to test your knowledge on event handling in JavaScript.

🧐 Question

What will be the output of the following code snippet when you click the button with the ID myButton?


<!DOCTYPE html>

<html>

<head>

  <title>Event Handling Example</title>

</head>

<body>

  <button id="myButton">Click Me!</button>



  <script>

    document.getElementById('myButton').addEventListener('click', function() {

      alert('Button clicked!');

    });



    document.getElementById('myButton').addEventListener('click', function() {

      console.log('Button was clicked!');

    });

  </script>

</body>

</html>

Enter fullscreen mode Exit fullscreen mode

Options:

A. Only an alert box with the message "Button clicked!" will appear.

B. Only "Button was clicked!" will be logged to the console.

C. Both the alert box and the console log will appear.

D. Neither the alert box nor the console log will appear.

Explanation:

Feel free to share your thoughts and explanations in the comments below! Let's learn together. 🌐💬

COdeWith #KOToka

KEEPCoding

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player