How to solve several questions in javascript telephone interview?

1: there are three interfaces, and the third interface needs to wait for the results returned by the first two interfaces. What should I do?
the difference between 2:let and const, can const only define constants?

Mar.05,2021

first question:
1. Use the fallback function.
2. Use promise.
3. Use async/await.

second problem: the main difference between
let and const is that the value of the const definition variable cannot be changed.
when the value of const is an address pointing to an object, the object can be changed because its address value has not changed.


add the first question. You can also use bad code words on async await, phones and occupy a pit


callback version

a.call(function(){
    b.call(function(){
        c.call(function(){
        });   
    });
});

abc corresponds to interfaces 1, 1, 2, 3, 3

promise version

const aPromise = function() {
    return new Promise((resolve,rejct)=>{
        a.call(e=>e?reject(e):resolve(e));
    });
};

the other two are similar. Call

Promise.all([aPromise,bPromise],function(a,b){
    c.call();
});

async/await version

await aPromise();
await bPromise();
c.call();
  1. objects defined by let can be reassigned, while objects defined by const cannot be reassigned. It is not required to define only constants, as long as the reference remains unchanged.

the most direct thought is promise's all, and
is followed by callback nesting. B clamp is in the callback of A, and C is embedded in the callback of B.

generally speaking, let defines variables, const defines constants
variables defined by let can update values, but not const

in addition, const can define a lot of things, as long as you don't change the body

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-1b3b3e4-2c280.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-1b3b3e4-2c280.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?