What is the primary purpose of Promises in JavaScript?
To define object-oriented classes.
To create loops that iterate over arrays.
To handle synchronous operations more efficiently.
To manage asynchronous operations and their results.
What does the 'Fetch API' return as the result of a successful network request?
A callback function for handling the response.
An error object indicating a failed request.
The requested data directly as a JavaScript object.
A Promise that resolves to a Response object.
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() doesn't modify the original function, while call() and apply() do.
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.
What is the purpose of the response.json() method when using the Fetch API?
response.json()
It sends a JSON-encoded request to the server.
It sets the Content-Type header of the request to 'application/json'.
It parses the response body as JSON data.
It converts a JavaScript object into a JSON string.
Consider the code: const myFunc = (a, b) => a + b;. What type of function is myFunc?
const myFunc = (a, b) => a + b;
myFunc
Generator function
Method
Constructor function
Arrow function
How can you ensure that the 'this' keyword inside a callback function refers to the intended object, especially in asynchronous operations?
By invoking the callback function with 'call()' or 'apply()'.
By using the 'let' keyword to declare variables inside the callback.
By using arrow functions, which lexically inherit the 'this' value.
By wrapping the callback function in another function.
What is the primary purpose of constructor functions in JavaScript?
To create multiple instances of an object with shared properties and methods.
To handle asynchronous operations.
To define static methods for a class.
To define private variables within a function scope.
Which of these methods allows you to explicitly set the this value when calling a function in JavaScript?
this
.forEach()
.call()
.map()
.filter()
Which HTTP status code range generally indicates a successful request made with the Fetch API?
400-499
100-199
200-299
300-399
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').deleteChild(2);
document.getElementById('container').children[2].remove();
document.getElementById('container').removeChild(2);
document.getElementById('container').childNodes[2].remove();