codecademy quiz——JavaScript Promise

Evernote Export

  • What is the fulfilled value of Promise.all()?
 A Promise      An object      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);
 ‘success value’      reason      undefined
  • True or False: The .then() method returns a Promise.
 False      True
  • How many parameters does a Promise constructor take?
const example = new Promise( ? ? ? );
 2      1      3
  • What value is printed to the console?
const asyncHello = new Promise((resolve, reject) => { 
    setTimeout(resolve, 1000, 'Hello!'); 
}); 
 
console.log(typeof asyncHello);
 Promise      Object      Number      String
  • Which one of the following is NOT a state that a Promise resolves to?
 Rejected     Fulfilled      Undefined      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); 
        } 
    }); 
};
 Fulfilled      Rejected      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) => { 
    . . . 
});
 function1      function2      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);
 False      True
 

转载于:https://www.cnblogs.com/xiyouchen/p/10300266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值