10.
What is a necessary condition for using the await keyword in JavaScript ES6?
The await keyword must be used inside a promise.
The await keyword must be used inside an asynchronous function denoted by async.
The await keyword can be used anywhere in the code.
The await keyword must be inside a for loop.
Correct: B
The await keyword can only be used inside a function declared with async. It will cause the async function to pause and wait for the Promise's resolution or rejection, and to resume the execution of the async function after fulfillment. When resumed, the value of the await expression is that of the fulfilled Promise.
async function fetchData() {
const response = await fetch('https://example.com/api/users');
const users = await response.json();
console.log(users);
}
fetchData();