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. Python系列之 - 前端总结

    1. python序列化: 字符串 = json.dumps(对象) 对象->字符串 对象 = json.loads(字符串) 字符串->对象 Javascript: 字符串 = JSON ...

  2. 使用 functional interface 和 lambda 表达式来优化代码

    ========================================原始代码========================================RoleService 类有删除 ...

  3. webpack 代码优化压缩方法

    在配置基于webpack的react单页面脚手架时,公共依赖库代码打包至vender.js中,页面逻辑代码打包至app.js中,使用webpack-bundle-analyzer分析发现,两个js中包 ...

  4. SpringBatch框架简介

    概观 轻量级,全面的批处理框架,旨在开发对企业系统日常运营至关重要的强大批处理应用程序. Spring Batch提供了可重复使用的功能,这些功能对于处理大量记录至关重要,包括记录/跟踪,事务管理,作 ...

  5. Django之restframework

    启动流程:引入rest_framework APP 在restframework中,GET数据可以通过request.query_params.get(xxx)获取,post数据可以通过request ...

  6. 「luogu2680」[NOIp2015] 运输计划

    题目大意:给定一棵n个节点的树,输入m组一条链的两个端点:把树上的某个边权改为0,求m条链长度的最大值的最小值: 一.考虑二分: 1.对于需要判断是否为可行方案的 mid,所有链长不大于 mid 的链 ...

  7. python学习第26天

    自定义模块和包 软件开发规范

  8. CentOS7上部署taiga项目管理软件

    作者:waringid 一.简介 Taiga 是一个免费开源,而且功能非常强大的项目管理平台,用于初创企业和敏捷开发团队.提供一个简单.漂亮的项目管理工具.Taiga 采用 Python Django ...

  9. HiveQl 基本查询

    1 基本的Select 操作 SELECT [ALL | DISTINCT] select_expr, select_expr, ...FROM table_reference[WHERE where ...

  10. win10 激活工具 Re-LoaderByR@1n.exe

    名字叫 Re-LoaderByR@1n.exe 无广告, https://pan.baidu.com/s/1MBix1cZxKpUTA6MUgL7uLQ 如果变成教育版,可以用以下激活码变成专业版:W ...