当前位置:网站首页>JS written test question: asynchronous
JS written test question: asynchronous
2022-06-21 14:27:00 【Advanced mathematics volume II half price】
const myPromise = Promise.resolve(Promise.resolve("Promise!"));
function funcOne() {
myPromise.then(res => res).then(res => console.log(res));
setTimeout(() => console.log("Timeout!", 0));
console.log("Last line!");
}
async function funcTwo() {
const res = await myPromise;
console.log(await res);
setTimeout(() => console.log("Timeout!", 0));
console.log("Last line!");
}
funcOne();
funcTwo();
answer : Last line! Promise! Promise! Last line! Timeout! Timeout!for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
Print out what ?
answer : 3 3 3 and 0 1 2
Asynchronous and let Form a block level scope 1
Promise.resolve(5)
A: 5
B: Promise {<pending>: 5}
C: Promise {<fulfilled>: 5}
D: Error
answer :C
promise There are three states ,resolve The corresponding is fulfilled state const myPromise = () => Promise.resolve('I have resolved!')
function firstFunction() {
myPromise().then(res => console.log(res))
console.log('second')
}
async function secondFunction() {
console.log(await myPromise())
console.log('second')
}
firstFunction()
secondFunction()
A: I have resolved!, second and I have resolved!, second
B: second, I have resolved! and second, I have resolved!
C: I have resolved!, second and second, I have resolved!
D: second, I have resolved! and I have resolved!, second
answer : D
encounter await myPromise(), It is asynchronous , It blocks the execution of the following code ,
So first execute firstFunction Medium second, then firstFunction Micro and medium-sized tasks, and then secondFunction The micro task of async function getData() {
return await Promise.resolve("I made it!");
}
const data = getData();
console.log(data);
A: "I made it!"
B: Promise {<resolved>: "I made it!"}
C: Promise {<pending>}
D: undefined
answer :C
The global execution context calls asynchronously getData after , Then perform console.log. This is the order of execution getData The result of the call is to return pending State of Promise边栏推荐
- How does JMeter implement interface association?
- C2 hiding of traffic encryption
- . bash_ profile
- [how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]
- Reptile Foundation_ Requests Library
- Azure applicationinsights integrated in blazor
- Use of MySQL 8.0.19 under alicloud lightweight application server linux-centos7
- 技术分享 | MySQL中一个聚类增量统计 SQL 的需求
- Getting started with qt-1-ui
- Compile time annotation
猜你喜欢

Installation of oracle19c under alicloud lightweight application server linux-centos7

. bash_ profile

T32 add toolbar button

Lamp Architecture 3 -- compilation and use of PHP source code

A blazor webassembly application that can automatically generate page components based on objects or types

Qt-3-basic components

Two of my essays

Record the processing process of slow response of primary system

Qt-4-common classes and components

Win10 installation and configuration mongodb
随机推荐
Machine learning model training template
Iterm2 file transfer with remote server
Detailed explanation of dynamic planning
Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]
STM32F0-DAY1
Declare war on uncivilized code II
Qt-6-file IO
Comprehensively analyze the key points of knowledge required for interface testing and interface testing
Technology sharing | a clustering incremental statistical SQL requirement in MySQL
ARP interaction process
Chapter 3 - data link layer
Redis学习(1)——概述和常用命令
给网站添加SSL安全证书
Implementation principle and difference between C value type and reference type
Chapter 6 - application layer
[test process and theory - software development process and project management]
Qt-7-multithreading
Dplayer development barrage background
Making my footprint map using API
C#&. Net to implement a distributed event bus from 0 (1)