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. A Basic Course in Partial Differential Equations

    A Basic Course in Partial Differential Equations, Qing Han, 2011 [下载说明:点击链接,等待5秒, 点击右上角的跳过广告后调至下载页面, ...

  2. 数据库之数据库管理篇[mysql]

    管理数据库 1.mysql开闭使用篇 mariadb在Linux中首次进入mysql(因为此时还没有创建任何用户,mysql的root并不等效于linux中的root用户) sudo mysql 进入 ...

  3. a标签跳页传参,以及截取URL参数

    <a href="dd.index?aa=1&&bb=2"></a> //截取URL参数 // console.log(window.loc ...

  4. python之用unittest实现接口参数化示例

    示例中获取参数的方法有三种: 1. 从文件(txt)中读取参数 2. 从Excel中读取参数 3. 在代码中直接写参数 def login(username,password): return 'ok ...

  5. zabbix通过php脚本模拟业务访问redis验证nosql的可用性

    背景: redis通过shell脚本进行监控,没有问题,应用报警连不上redis,此时需要通过php模拟web环境进行redis的操作来确认web服务器是否能正常和redis通信 .配置nginx,让 ...

  6. Error: Could not find or load main class Test

    问题描述 Linux 环境下运行 Java 程序时,执行 javac Test.java 生成 Test.class 文件,再执行 java Test 时报错:Error: Could not fin ...

  7. AI数据分析(一)

    安装Spyder+PyQt5 在python36目录下,使用cmd打开,切换到Scripts文件下 pip install spyder pip install PyQt5 python中的库 Num ...

  8. 配置 Docker 加速器:适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1

    天下容器, 唯快不破 Docker Hub 提供众多镜像,你可以从中自由下载数十万计的免费应用镜像, 这些镜像作为 docker 生态圈的基石,是我们使用和学习 docker 不可或缺的资源.为了解决 ...

  9. spring boot 2.0 neo4j 使用

    参考文档 官方文档 http://spring.io/projects/spring-data-neo4j#learn https://docs.spring.io/spring-data/neo4j ...

  10. 数据库链接池c3p0的配置

    由于我看的是远古教程,所以里面各种驱动jar包还有c3p0包都是远古版本,对于最新版本的jdbc已经失去的作用,所以我在这里重写一下! 1.首先是c3p0的位置,package的外面,src的里面 2 ...