Skip to content

promise和setTimeout执行顺序是怎样的? #5

Open
@artdong

Description

@artdong

写出下列程序运行结果并做出解释:

setTimeout(function(){
    console.log(1);
},0); 

new Promise(function(resolve) { 
    console.log(2) 
    for(let i=0; i<10000 ; i++ ) { 
        i==9999 && resolve(); 
    } 
    console.log(3) 
}).then(function(){ 
    console.log(4) 
}); 
console.log(5); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsjavascript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions