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
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
Consider the following JavaScript code: document.addEventListener('keypress', function(event) { console.log('Key pressed:', event.key); }); What does this code do?
A). A. Adds a click event listener to the document
B). B. Adds a keypress event listener to the document
C). C. Removes a keypress event listener from the document
D). D. Checks if a key is pressed while hovering over an element
Which event is triggered when a user clicks on an HTML element?
A). A. onhover
B). B. onsubmit
C). C. onload
D). D. onclick
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 event occurs when a user submits an HTML form?
A). A. onsubmit
B). B. onmouseover
C). C. onkeydown
D). D. onclick
What is the primary purpose of JavaScript functions?
A). A. To style web pages
B). B. To provide structure to HTML elements
C). C. To create reusable code blocks
D). D. To define CSS styles for HTML
What is the purpose of parameters in a JavaScript function?
A). A. To return a value from the function
B). B. To define the function's name
C). C. To store variables within the function
D). D. To accept inputs into the function
What is the purpose of an event in JavaScript?
A). A. To add styles to HTML elements
B). B. To handle user interactions and browser actions
C). C. To define function names
D). D. To create animations on web pages
Which event is triggered when a web page finishes loading?
A). A. onload
B). B. onsubmit
C). C. onmouseover
D). D. onclick