JavaScript From Beginner To Advanced

0% completed

Previous
Next
Quiz
What is the primary purpose of asynchronous programming in JavaScript?
A
To allow a single operation to monopolize the JavaScript runtime
B
To increase the execution speed of scripts
C
To perform lengthy I/O operations without blocking the main thread
D
To synchronize server and client code execution
Consider the following JavaScript code:
function fetchData(callback) {
    setTimeout(() => {
        callback('Data loaded');
    }, 1000);
}

fetchData(result => {
    console.log(result);
});
What will this code output?
A
Data loaded
B
undefined
C
It will throw an error.
D
Nothing will be output.
What is wrong with using 'await' outside of an async function?
A
. It makes the code synchronous.
B
It's syntactically correct but discouraged.
C
It results in a syntax error.
D
The script will pause indefinitely.
What will the following code snippet display in the console?
    yield 1;
    yield 2;
    yield 3;
}

(async () => {
    for await (const num of generateNumbers()) {
        console.log(num);
    }
})();
A
1 2 3
B
undefined
C
It will throw an error.
D
0 1 2
What happens when an error occurs in an awaited function without a surrounding try-catch block?
A
The error is ignored, and the function continues execution.
B
The error triggers the closest error handler up the call stack.
C
The error causes the surrounding function to return undefined.
D
The script crashes.
Choose the best practice for managing a series of asynchronous operations that depend on the outcome of the previous operation.
A
Nesting multiple callbacks
B
Using a single promise
C
Chaining multiple promises
D
Using async/await for sequential execution

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next