ES6 Promise & Async + Await

Create new Promise objects:


const p = new Promise((resolve, reject) => {
  resolve("good");
});

const p2 = new Promise((resolv, reject) => {
  reject("bad");
});

p.then((data) => {
  console.log(data);
}).catch((err) => {
  console.log(err);
});

p2.then((data) => {
  console.log(data);
}).catch((err) => {
  console.log(err);
});

Create resolved and rejected promises:


const func = async () => {

  const p = Promise.resolve("good");
  const x = await p;
  console.log(x)

  try{
    const p2 = Promise.reject("bad");
    const y = await p2;
    console.log(y)
  }
  catch(e){
    console.log(e);
  }

  console.log("done")

}

func();