I'm trying to resolve the promise in the getABC function, but the local const variable b returns undefined. How do I implement the callback function used by the getB function so that it returns the destructured array item with the value of 'B'.
const [A, B, C] = ['A', 'B', 'C'];
function getA() {
return A;
}
function getB(callback) {
setTimeout(() => {
callback(B);
}, 10);
}
function getC() {
return Promise.resolve().then(() => C);
}
function getABC() {
return new Promise((resolve, reject) => {
const a = getA();
const b = getB(b => b);
const c = getC().then(item => item).catch(err => console.log(err));
resolve([a, b, c])
});
}
getABC().then((arr) => console.log(arr));