Which of the following is NOT a valid HTTP method used with the Fetch API?
GET
CONNECT
DELETE
POST
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').removeChild(2);
document.getElementById('container').childNodes[2].remove();
document.getElementById('container').deleteChild(2);
document.getElementById('container').children[2].remove();
What is the primary purpose of Promises in JavaScript?
To define object-oriented classes.
To manage asynchronous operations and their results.
To create loops that iterate over arrays.
To handle synchronous operations more efficiently.
What is the purpose of the response.json() method when using the Fetch API?
response.json()
It converts a JavaScript object into a JSON string.
It sets the Content-Type header of the request to 'application/json'.
It parses the response body as JSON data.
It sends a JSON-encoded request to the server.
Which keyword is used to define an asynchronous function in JavaScript?
sync
async
promise
await
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
bind() can only be used with object methods, while call() and apply() can be used with any function.
bind() immediately invokes the function, while call() and apply() don't.
bind() creates a new function with a bound 'this' context, while call() and apply() invoke the function immediately.
bind() doesn't modify the original function, while call() and apply() do.
What is the purpose of the .catch() method in Promise chaining?
.catch()
To filter the results of a Promise.
To handle Promise rejections (errors).
To handle successful Promise resolutions.
To transform the resolved value of a Promise.
What is the primary purpose of constructor functions in JavaScript?
To define static methods for a class.
To create multiple instances of an object with shared properties and methods.
To define private variables within a function scope.
To handle asynchronous operations.
How do modules enhance code organization and reusability in JavaScript?
They are used for creating user interfaces and handling user interactions.
They allow developers to group related code into separate files and control their visibility and accessibility, reducing global scope pollution.
Modules enable asynchronous programming, improving the performance of web applications.
Modules primarily handle data persistence in JavaScript applications.
How can you ensure that the 'this' keyword inside a callback function refers to the intended object, especially in asynchronous operations?
By using arrow functions, which lexically inherit the 'this' value.
By using the 'let' keyword to declare variables inside the callback.
By wrapping the callback function in another function.
By invoking the callback function with 'call()' or 'apply()'.