Isn't promise asynchronous?

Why the result of running is cdab instead of cabd

function a(){console.log("a");}
function b(){console.log("b");}
new Promise(function(resolve,reject){
    console.log("c");
    resolve(22);
}).then(console.log("d"));
a();
b();

// 
c
d
a
b
Sep.26,2021

new Promise((resolve,reject) => {
    console.log("c"); 
    resolve("d")
 })
   .then(res => {
    console.log(res)
 })
a();
b();

then should accept a function;
here directly use the result undefined of console.log ("d") as its callback. Of course, the registration process is Synchronize.
do not misinterpret the then method as an asynchronous method. Then callback is asynchronous. The
then method immediately returns a new promise object, at which time the new promise object already has a then callback, and waits for the last promise state to change from pending to execute the callback


promise is a new object of ES6, mainly to solve the callback hell and solve the problem of asynchronism.


where is your code asynchronous?


because of your There is no asynchronous code.
promise is not asynchronous code, but solves the problem of asynchronous callback, so it is used with asynchronous code.
promise itself does not have asynchronous behavior.


modify the contents of then and try again:

.then(()=>{
    console.log('d');
})
The

then method receives a parameter of Function type

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb0b81-2300.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb0b81-2300.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?