What do you think the output to console.log will be?

  new Promise(function(resolve, reject) {
    return resolve("X")
  }).then(function(result) {
    console.log("A1 " + result); // 1
    return new Promise((resolve, reject) => { // (*)
      resolve("Z")
    });
    console.log("A2" + result)
  }).then(function(result) {
    console.log("C" + result); // 4
  });
  console.log("D")

Output:

D
A 1
C 2

 


 

What do you think the output to console.log will be?

function test() {
  return new Promise(function (resolve, reject) {
    return resolve("1")
  })
}

async function test2() {
  let r1 = await test();
  console.log("r1", r1)
  return r1
}

let r2 = test2()
console.log("r2", r2)

Output:

r2 Promise {<pending>}
  [[Prototype]]: Promise
  [[PromiseState]]: "fulfilled"
  [[PromiseResult]]: "1"
r1 1