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
 

codecademy quiz——JavaScript Promise的更多相关文章

  1. [Javascript] Promise

    Promise 代表着一个异步操作,这个异步操作现在尚未完成,但在将来某刻会被完成. Promise 有三种状态 pending : 初始的状态,尚未知道结果 fulfilled : 代表操作成功 r ...

  2. Javascript Promise 学习笔记

    1.     定义:Promise是抽象异步处理对象以及对其进行各种操作的组件,它把异步处理对象和异步处理规则采用统一的接口进行规范化. 2.     ES6 Promises 标准中定义的API: ...

  3. 【译】JavaScript Promise API

    原文地址:JavaScript Promise API 在 JavaScript 中,同步的代码更容易书写和 debug,但是有时候出于性能考虑,我们会写一些异步的代码(代替同步代码).思考这样一个场 ...

  4. JavaScript Promise:去而复返

    原文:http://www.html5rocks.com/en/tutorials/es6/promises/ 作者:Jake Archibald 翻译:Amio 女士们先生们,请准备好迎接 Web ...

  5. javaScript Promise 入门

    Promise是JavaScript的异步编程模式,为繁重的异步回调带来了福音. 一直以来,JavaScript处理异步都是以callback的方式,假设需要进行一个异步队列,执行起来如下: anim ...

  6. JavaScript Promise异步实现章节的下载显示

    Links: JavaScript Promise:简介 1.一章一章顺序地下载显示下载显示 使用Array.reduce()和Promise.resolve()将各章的下载及显示作为整体串联起来. ...

  7. codecademy课程笔记——JavaScript Promise

      Promise是一种表示异步操作最终的结果的对象,一个Promise对象有三种状态 Pending: 初始状态 ,操作还未完成 Fullfilled:操作成功完成,且这个promise现在有一个r ...

  8. Javascript - Promise学习笔记

    最近工作轻松了点,想起了以前总是看到的一个单词promise,于是耐心下来学习了一下.   一:Promise是什么?为什么会有这个东西? 首先说明,Promise是为了解决javascript异步编 ...

  9. Javascript Promise入门

    是什么? https://www.promisejs.org/ What is a promise? The core idea behind promises is that a promise r ...

随机推荐

  1. China-global view

    Good morning everyone. Everyone here would know this year Xia’Men held the BRICS business forum.In a ...

  2. How to learn PDE (怎么学偏微分方程)

    To learn PDE, you need some knowledge of physics (to build up the intuition), solid training of anal ...

  3. [物理学与PDEs]第2章第3节 Navier-Stokes 方程组

    1.  当流体的压力 $p$ 及温度 $T$ 改变时, 密度 $\rho$ 变化很小. 此时可近似地把流体看作是不可压的, 而 $\rho=\const$. 如此, 流体动力学方程组中的质量.动量守恒 ...

  4. win10自带邮箱添加网易企业邮箱

    开始-邮件-账户-添加账户-高级安装程序-internet电子邮件-然后输入网易企业邮箱的用户名和相关服务器设置就行了 接收服务器 pop.qiye.163.com发送服务器 smtp.qiye.16 ...

  5. C# Textbox 自动换行

    方法1 使用textbox的AppendText方法 方法2 textBox.ScrollToCaret(); this.textBox.Focus();//获取焦点 this.textBox.Sel ...

  6. PHP微信公众号JSAPI网页支付(下)

    上一篇PHP微信公众号JSAPI网页支付(上)中讲到了公众号平台的相关设置以及支付的大致流程. 这一篇重点讲支付后,异步接受回调通知,以及处理后同步通知微信服务器. 首先梳理下整个jsapi支付的流程 ...

  7. 阿里的fastJson.jar jsonArray 和 list 互转

    阿里的fastJson.jar: //list转换为json List<CustPhone> list = new ArrayList<CustPhone>(); String ...

  8. 【原创】大数据基础之Hive(1)Hive SQL执行过程之代码流程

    hive 2.1 hive执行sql有两种方式: 执行hive命令,又细分为hive -e,hive -f,hive交互式: 执行beeline命令,beeline会连接远程thrift server ...

  9. Python-Django 模型层-多表查询

    多表操作 基于对象的跨表查询(多次查询) 一对一: -正向查询按字段 -反向查询按表名小写 一对多: -正向查询按字段(正向查询一定会查出一个来) -反向查询按表名小写_set.all()(返回结果是 ...

  10. PDF怎样添加注释,PDF文件添加注释的方法

    Word文件跟纸质文件想要添加注释相信大家都知道该怎么添加,那么现在也使用频率挺高的PDF格式的文件要怎么添加注释呢?添加注释的方法有什么呢?有许多的小伙伴们都想知道吧,今天小编就来跟大家分享一下,想 ...