前几天看到一道有意思的js执行题,大家做做看
前几天看到一道有意思的js执行题,非常有意思,哈哈,大家做做看:
<script>
setTimeout(function () {
console.log(1);
},10);
new Promise(function (resolve) {
setTimeout(function () {
console.log(2);
new Promise(function (resolve) {
console.log(3);
resolve('ggg')
}).then(function () {
console.log(4);
});
new Promise(function (resolve) {
console.log(5);
resolve('ggg')
}).then(function () {
console.log(6);
});
},10);
console.log(7);
resolve('ggg')
}).then(function () {
console.log(8);
});
setTimeout(function () {
console.log(9);
},10);
new Promise(function (resolve) {
console.log(10);
resolve('ggg')
}).then(function () {
console.log(11);
});
</script>
注:浏览器和nodejs执行顺序是不一样的哦,有知道原因的请告知