What does the preventDefault() method do in JavaScript event handling?
A). A. Stops event propagation to parent elements
B). B. Prevents the default behavior associated with an event
C). C. Detaches event listeners from elements
D). D. Clears the event queue
What is the purpose of the onclick attribute in HTML elements?
A). A. To define styles for HTML elements
B). B. To attach event listeners for mouse clicks
C). C. To insert JavaScript code directly into HTML
D). D. To create animations for HTML elements
Which statement accurately describes JavaScript event bubbling?
A). A. It refers to the downward propagation of events from parent elements to child elements.
B). B. It refers to the upward propagation of events from child elements to parent elements.
C). C. It refers to the simultaneous firing of multiple events on the same element.
D). D. It refers to the automatic removal of event listeners after an event is triggered.
Which of the following correctly defines a JavaScript function?
A). A. function addNumbers(num1, num2) { return num1 + num2; }
B). B. function = addNumbers(num1, num2) { return num1 + num2; }
C). C. function addNumbers(num1 + num2) { return num1 + num2; }
D). D. function addNumbers(num1, num2) => { return num1 + num2; }
Which event is triggered when a user clicks on an HTML element?
A). A. onhover
B). B. onsubmit
C). C. onload
D). D. onclick
In JavaScript, what is the purpose of the addEventListener() method?
A). A. To create inline event handlers
B). B. To attach event listeners to HTML elements
C). C. To remove event listeners from HTML elements
D). D. To bind event handlers to parent elements
Which type of JavaScript function is defined without a name?
A). A. Named function
B). B. Anonymous function
C). C. Arrow function
D). D. Generator function
Which method is used to attach an event listener to an HTML element in JavaScript?
A). A. appendEvent()
B). B. addEventListener()
C). C. attachEvent()
D). D. bindEvent()
What is the purpose of the removeEventListener() method in JavaScript?
A). A. To add event listeners to HTML elements
B). B. To detach event listeners from HTML elements
C). C. To prevent event propagation in event handling
D). D. To modify HTML content dynamically
What is the purpose of the onmouseover event in HTML?
A). A. To detect when an element is hovered over
B). B. To track changes in form inputs
C). C. To determine when an element is loaded
D). D. To handle form submissions