What is the purpose of 'event.preventDefault()' in JavaScript?
It stops an event from being handled by any further listeners.
It prevents the default behavior of an element, like a form submission.
It triggers a custom event on an element.
It removes an event listener from an element.
What will be logged to the console in this code snippet: console.log((function(a) { return a * a; })(5));?
console.log((function(a) { return a * a; })(5));
25
10
5
undefined
Which of the following is NOT a valid HTTP method used with the Fetch API?
DELETE
POST
GET
CONNECT
You need to add an event listener to a dynamically created element. What technique should you use?
Event delegation: attach the listener to a parent element that already exists in the DOM.
Attach the listener to the element's parent using event bubbling.
Use setTimeout to delay the listener attachment until after the element is added to the DOM.
setTimeout
Directly attach the listener to the element before appending it to the DOM.
You want to remove the third child element from a parent element with the ID 'container'. What is the correct JavaScript code?
document.getElementById('container').children[2].remove();
document.getElementById('container').deleteChild(2);
document.getElementById('container').childNodes[2].remove();
document.getElementById('container').removeChild(2);
What does the 'Fetch API' return as the result of a successful network request?
An error object indicating a failed request.
The requested data directly as a JavaScript object.
A Promise that resolves to a Response object.
A callback function for handling the response.
In JavaScript's event loop, what is the role of the 'microtask queue'?
It handles user interactions like clicks and scrolls.
It manages network requests and responses.
It processes promises and other tasks with higher priority than the main task queue.
It executes tasks that have been explicitly delayed with setTimeout.
What is a primary method for avoiding memory leaks in JavaScript?
Dereferencing unused objects and variables
Using 'const' for all variable declarations
Minimizing function calls
Using 'async/await' for all asynchronous operations
Which principle of object-oriented programming focuses on hiding internal implementation details and exposing only necessary information?
Abstraction
Inheritance
Polymorphism
Encapsulation
Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
apply()
spread()
bind()
call()