What does the 'Fetch API' return as the result of a successful network request?
A Promise that resolves to a Response object.
An error object indicating a failed request.
The requested data directly as a JavaScript object.
A callback function for handling the response.
How can you ensure that a piece of code runs only after a Promise has been rejected?
By using the '.catch()' method.
By placing the code immediately after the Promise is created.
By using the '.then()' method.
By using the 'setTimeout()' function.
What is the primary difference between 'nextSibling' and 'nextElementSibling' in DOM traversal?
There is no difference; they are interchangeable.
'nextSibling' traverses upwards in the DOM, while 'nextElementSibling' traverses downwards.
'nextSibling' might return a text node or comment, while 'nextElementSibling' only returns element nodes.
'nextSibling' only works with elements, while 'nextElementSibling' works with any node type.
Which method allows you to move up from a child element to its direct parent in the DOM?
parentElement
parentNode
closest()
previousSibling
How do modules enhance code organization and reusability in JavaScript?
They allow developers to group related code into separate files and control their visibility and accessibility, reducing global scope pollution.
They are used for creating user interfaces and handling user interactions.
Modules enable asynchronous programming, improving the performance of web applications.
Modules primarily handle data persistence in JavaScript applications.
What is the primary purpose of constructor functions in JavaScript?
To handle asynchronous operations.
To define static methods for a class.
To define private variables within a function scope.
To create multiple instances of an object with shared properties and methods.
What is a higher-order function in JavaScript?
A function that uses arrow syntax.
A function that does not have a return statement.
A function that takes another function as an argument or returns a function.
A function that can only be called once.
You have a form with client-side validation. What is the recommended approach to prevent form submission if validation fails?
Use event.stopPropagation() to stop the submission event.
event.stopPropagation()
Use event.preventDefault() and handle the submission logic manually.
event.preventDefault()
Remove the 'submit' attribute from the form element dynamically.
Set the form's 'action' attribute to an empty string.
Which principle of object-oriented programming focuses on hiding internal implementation details and exposing only necessary information?
Polymorphism
Abstraction
Inheritance
Encapsulation
What is the impact of long-running JavaScript tasks on the browser's responsiveness?
They can block the main thread, leading to a frozen UI and unresponsive interactions.
They enhance user experience by providing smoother animations and transitions.
They improve rendering performance by allowing the browser to optimize resource allocation.
They have no significant impact on browser responsiveness, as JavaScript execution is asynchronous.