2021-11-03 10:05:10 +08:00

61 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 题目1:
// console.log('script start');
// setTimeout(function () {
// console.log('setTimeout');
// }, 0);
// Promise.resolve().then(function () {
// console.log('promise1');
// }).then(function () {
// console.log('promise2');
// });
// console.log('script end');
// script start
// script end
// promise1
// promise2
// setTimeout
// 宏任务队列setTimeout
// 微任务队列promise1、promise2
// 题目2
Promise.resolve().then(() => {
console.log('Promise1')
setTimeout(() => {
console.log('setTimeout2')
}, 0)
})
setTimeout(() => {
console.log('setTimeout1')
Promise.resolve().then(() => {
console.log('Promise2')
})
}, 0)
// Promise1
// setTimeout1
// Promise2
// setTimeout2
// 宏任务队列setTimeout2
// 微任务队列:
</script>
</body>
</html>