What is the advantage of Promise over callbacks in the following lines of code?

recently learned ES6 , learned promise , you can use then (). Then (). Then () to solve callback hell
I would like to ask:
like the following simple logic case, the two effects may be the same.
so what are the advantages of promise ?
if there is, where do you want to get the favor of the old driver, please do not hesitate to hit the gold code and hit two lines.
Thank you for your help

    function afterSomeSeconds( callBackFn ){
        setTimeout(()=>{
            callBackFn("2");
        }, 2 * 1000);
    };
    afterSomeSeconds(function toLog(msg){
        console.log(msg)
    }); 
    console.log("1");

    // ,
    // 
    // ES6Promise

    function afterSomeSecondsPromise(){
        return new Promise(function(resolve, reject){
            setTimeout(()=>{
                resolve("3");
            }, 3 * 1000);
        })
    }
    afterSomeSecondsPromise().then(msg=>{
        console.log(msg)
    });
    console.log("2");
:
1
2
2
3

Yes!

1.When blessed by await, it feels better

in an environment that supports await, you can directly

  

you use the setTimeout timer to call back, so in the traditional single-threaded execution, what if you need to deal with something asynchronously without affecting the main thread? It is recommended to learn more about asynchronism rather than using timers to describe it.

Menu