Which HTTP status code range generally indicates a successful request made with the Fetch API?
300-399
200-299
400-499
100-199
What is a primary method for avoiding memory leaks in JavaScript?
Minimizing function calls
Using 'async/await' for all asynchronous operations
Dereferencing unused objects and variables
Using 'const' for all variable declarations
How do ES6 classes simplify object-oriented programming in JavaScript compared to constructor functions?
ES6 classes introduce a completely new inheritance model unrelated to prototypes.
ES6 classes are primarily used for working with the DOM and have limited object-oriented capabilities.
Classes eliminate the need for prototypes, making object creation more efficient.
Classes offer a more concise and familiar syntax for defining objects and inheritance, though they still utilize prototypes under the hood.
What does the await keyword do inside an asynchronous function?
await
It defines a new Promise object.
It logs an error message to the console.
It sets a timeout before executing the next line of code.
It pauses execution until the Promise it's used with resolves or rejects.
In what scenario would you typically use a callback function?
To log data to the console for debugging purposes.
To create a loop that iterates a specific number of times.
To define a constant variable.
To perform an action after an asynchronous operation completes, like fetching data from an API.
Consider the code: const myFunc = (a, b) => a + b;. What type of function is myFunc?
const myFunc = (a, b) => a + b;
myFunc
Arrow function
Method
Generator function
Constructor function
What is the purpose of 'event.preventDefault()' in JavaScript?
It stops an event from being handled by any further listeners.
It removes an event listener from an element.
It triggers a custom event on an element.
It prevents the default behavior of an element, like a form submission.
In the context of higher-order functions, what does it mean for a function to be passed as an argument to another function?
The function is executed before being passed as an argument.
A reference to the function is passed, allowing it to be invoked later.
The function's return value is passed as the argument.
The function's code is copied into the receiving function.
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()
Set the form's 'action' attribute to an empty string.
Remove the 'submit' attribute from the form element dynamically.
How do modules enhance code organization and reusability in JavaScript?
They are used for creating user interfaces and handling user interactions.
Modules primarily handle data persistence in JavaScript applications.
Modules enable asynchronous programming, improving the performance of web applications.
They allow developers to group related code into separate files and control their visibility and accessibility, reducing global scope pollution.