Complete the code to run two functions one after the other (sequentially).
function first() {
console.log('First');
}
function second() {
console.log('Second');
}
first();
[1]();Complete the code to run two asynchronous functions in parallel using Promise.all.
function task1() {
return new Promise(resolve => setTimeout(() => resolve('Task 1 done'), 1000));
}
function task2() {
return new Promise(resolve => setTimeout(() => resolve('Task 2 done'), 500));
}
Promise.[1]([task1(), task2()]).then(results => {
console.log(results);
});Fix the error in the async function to run tasks sequentially using await.
async function runTasks() {
const result1 = task1();
const result2 = task2();
console.log(await result1);
console.log(await result2);
}
runTasks();
// Fix the line: const result1 = [1];Fill both blanks to create a function that runs two tasks in parallel and logs their results.
async function runParallel() {
const [result1, result2] = await Promise.[1]([task1(), task2()]);
console.log(result1);
console.log([2]);
}
runParallel();Fill all three blanks to create a function that runs tasks sequentially using await and logs results.
async function runSequential() {
const result1 = await [1]();
console.log(result1);
const result2 = await [2]();
console.log([3]);
}
runSequential();