0% found this document useful (0 votes)
23 views4 pages

Prism - AI Driven Full Stack Digital Learning Experience Platform

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Prism - AI Driven Full Stack Digital Learning Experience Platform

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

3/1/23, 12:49 AM Prism - AI driven, full stack digital learning experience platform

Data Types & Structures Modules and Package Managers


Rows per page: 10 11-20 of 2
View all strengths View all Areas of Development

Contact Support Terms Privacy Program Policies Powered by Knowledgehut


Detail Report

Dashboard
What is not true about the event loop in JavaScript? Asynchronous JavaScript 3/3
Courses
It takes items from the task queue and puts it on the call stack
Sessions
It keeps running even if the call stack is not empty
Assessments

The oldest item in the task queue is picked first


Bookmarks

It is part of the mechanism that enables asynchronous programming


Social learning

Discussion
Reason
Messenger
The event loop will only run when the call stack is empty.

Identify features that enable you to implement asynchronous programming in Asynchronous JavaScript 1/1
JavaScript. (Select all that apply)
The for loop

Promises

setTimeout()

Async and Await

Reason
Promises, setTimeout(), and Async/Await enable you to implement asynchronous programming features in your code.

setTimeout() is a part of the EcmaScript language standard. Is this statement true Asynchronous JavaScript 2/2
or false?
True

False

Reason
setTimeout() and setInterval() are provided by the web browser's APIs and are not natively part of the EcmaScript (JavaScript) language standard.

The task queue that the event loop scours through is a _________ queue. (Fill in the Asynchronous JavaScript 3/3
blanks)
First-in-first-out

First-in-last-out

Last-in-first-out

Last-in-last-out

Reason

https://prism.knowledgehut.com/learner/program-detail/62e3ba9069d8461d65a97de0/milestone/reports 2/5
3/1/23, 12:49 AM Prism - AI driven, full stack digital learning experience platform
The task queue is a first-in-first-out queue, meaning that functions that are added first to the queue are removed first by the event loop for execution on the
call stack.

When using promises, which of the following is not a valid state? Asynchronous JavaScript 2/2
Dashboard
Pending
Courses
Fulfilled
Sessions
Rejected/Failed
Assessments

Partially successful
Bookmarks

Social learning
Reason
There is no such thing as partial success when working with promises in JavaScript. Promises have three states, namely, 'Pending', 'Fulfilled', and 'Rejected'.
Discussion

Messenger
What is a promise in JavaScript? Asynchronous JavaScript 1/1

It is a function that enables multiple synchronous functions to execute in parallel

It enables us to use setTimeout() to run code asynchronously

It is an intent to do something at a future time, be it successful or not

None of the listed

Reason
A promise is an intent to do something, such as fetch data from a remote API. It is an intent to do something tangible in the future, and it does not guarantee
success or failure.

What will be the outcome of the following code? Asynchronous JavaScript 3/3

function getPromise() { return new Promise((resolve,


reject) => { resolve(205); }); } const getNum = () =>
new Promise((resolve, reject) => resolve(205)); const augment
= (n) => new Promise((resolve, reject) => reject(n * 2));
getNum() .then(augment) .then((res) => console.log(res));

205

410

An error message would be shown - Uncaught (in promise)

No output on the console

Reason
The augment() function rejects the promise that doesn’t get caught using a catch() method. Hence, you will get an error 'Uncaught' (in promise).

What will be the output of the following code? Asynchronous JavaScript 3/3

const delayExec = (cb) => setTimeout(cb, 0); const promisify


= (str) => Promise.resolve(str); const promiseDel = (str,
delay) => new Promise((resolve, reject) => setTimeout(() =>

https://prism.knowledgehut.com/learner/program-detail/62e3ba9069d8461d65a97de0/milestone/reports 3/5
3/1/23, 12:49 AM Prism - AI driven, full stack digital learning experience platform
resolve(str), delay)); delayExec(function () {
console.log('Hi!'); }); promisify('It is a beautiful
day!').then((res) => console.log(res)); delayExec(function ()
{ console.log('How are you doing?'); }); promiseDel('What
should we do today?', 10).then((res) => console.log(res));
'Hi!'
Dashboard
'It is a beautiful day!'
Courses 'How are you doing?'

Sessions 'What should we do today?'

Assessments
'It is a beautiful day!'

'What should we do today?'


Bookmarks
'Hi!'

Social learning 'How are you doing?'

Discussion
'It is a beautiful day!'

'Hi!'
Messenger
'How are you doing?'

'What should we do today?'

None of the listed

Reason
The two instances of delayExec() will land up on the macro-task queue as a task no. #2 while the entire code is packaged and executed as macro-task #1.
Once macro-task #1 is executed, the micro-task queue is executed. This is why you see 'It is a beautiful day!' first. The promiseDel() function is delayed, so it
lands up as macro-task #2, which gets executed after the micro-task queue, and the macro-task #1 is cleared out.

What will be the outcome of the following code? Asynchronous JavaScript 2/2

const add = (a, b) => new Promise((resolve, reject) => {


setTimeout(() => { if ((a + b) % 2 === 0) {
resolve(a + b); } else { reject(); }
}, 4000); }); add(13, 4) .then((res) => console.log(res))
.catch(() => console.log('There was an error'));

17

There was an error

Undefined

None of the listed

Reason
Since 17 is not an even number, the add() function will reject the promise, which would be displayed on the console as 'There was an error'.

Observe the following code. When will the finally() block be executed? Asynchronous JavaScript 2/2

fetchStockRates() .then((res) => console.log(res))


.catch((err) => console.log(err)) .finally(() =>
console.log('Finally'));

After the promise is successfully resolved

After the promise is rejected

https://prism.knowledgehut.com/learner/program-detail/62e3ba9069d8461d65a97de0/milestone/reports 4/5
3/1/23, 12:49 AM Prism - AI driven, full stack digital learning experience platform

After the promise is either resolved or rejected

It will never be executed

Dashboard
Reason
As the name implies, the finally() block will be executed once the promise is resolved or rejected. It is not based on the nature of the outcome of the promise.
Courses

Sessions

Assessments
Rows per page: 10 1-10 of 25

Bookmarks

Social learning

Discussion

Messenger

https://prism.knowledgehut.com/learner/program-detail/62e3ba9069d8461d65a97de0/milestone/reports 5/5

You might also like