codecademy quiz——JavaScript Promise

时间:2021-03-03 16:18:41

Evernote Export

  • What is the fulfilled value of Promise.all()?
codecademy quiz——JavaScript Promise A Promise    codecademy quiz——JavaScript Promise An object    codecademy quiz——JavaScript Promise An array
  • What is value of the argument that is passed to the onReject()?
let onFulfill = value => {console.log(value)}; 
let onReject = reason => {console.log(reason)}; 
const promise = new Promise( (resolve, reject) => { 
    if (false) { 
        resolve('success value'); 
    } else { 
        reject(); 
    } 
}); 
 
promise.then(onFulfill, onReject);
codecademy quiz——JavaScript Promise ‘success value’    codecademy quiz——JavaScript Promise reason    codecademy quiz——JavaScript Promise undefined
  • True or False: The .then() method returns a Promise.
codecademy quiz——JavaScript Promise False    codecademy quiz——JavaScript Promise True
  • How many parameters does a Promise constructor take?
const example = new Promise( ? ? ? );
codecademy quiz——JavaScript Promise 2    codecademy quiz——JavaScript Promise 1    codecademy quiz——JavaScript Promise 3
  • What value is printed to the console?
const asyncHello = new Promise((resolve, reject) => { 
    setTimeout(resolve, 1000, 'Hello!'); 
}); 
 
console.log(typeof asyncHello);
codecademy quiz——JavaScript Promise Promise    codecademy quiz——JavaScript Promise Object    codecademy quiz——JavaScript Promise Number    codecademy quiz——JavaScript Promise String
  • Which one of the following is NOT a state that a Promise resolves to?
codecademy quiz——JavaScript Promise Rejected    codecademy quiz——JavaScript Promise Fulfilled    codecademy quiz——JavaScript Promise Undefined    codecademy quiz——JavaScript Promise Pending
  • What state will this promise be in after 0 seconds?
const examplePromise = () => { 
    return new Promise((resolve, reject) => { 
        if (true) { 
            setTimeout( () => resolve('success'), 3000); 
        } else { 
            setTimeout( () => resolve('failed'), 5000); 
        } 
    }); 
};
codecademy quiz——JavaScript Promise Fulfilled    codecademy quiz——JavaScript Promise Rejected    codecademy quiz——JavaScript Promise Pending
  • What will be printed to the console after running the code provided?
let link = state => { 
    return new Promise(function(resolve, reject) { 
        if (state) { 
            resolve('success'); 
        } else { 
            reject('error'); 
        } 
    }); 
 
let promiseChain = link(true); 
 
promiseChain 
.then( data => {
    console.log(data + " 1"); 
    return link(true); 
})
.then( data => { 
    console.log(data+ " 2"); 
    return link(true); 
});
Your Answer: 
 
 
 
  • Which of the executor function’s parameter is called if the asynchronous task completes successfully?
const example = new Promise( (function1, function2) => { 
    . . . 
});
codecademy quiz——JavaScript Promise function1    codecademy quiz——JavaScript Promise function2    codecademy quiz——JavaScript Promise function1 or function2
  • True or False: promise1 and promise2 both produce the same output.
const examplePromise1 = new Promise((resolve, reject) => {
    reject('Uh-oh!') 
}); 
 
const examplePromise2 = new Promise((resolve, reject) => { 
    reject('Uh-oh!') 
}); 
 
const onFulfill = value => {
    console.log(value)
}; 
 
const onReject = reason => {
    console.log(reason)
}; 
 
const promise1 = examplePromise1.then(onFulfill, onReject); 
const promise2 = examplePromise2.then(onFulfill).catch(onReject);
codecademy quiz——JavaScript Promise False    codecademy quiz——JavaScript Promise True
 

相关文章