Promise

Jang Byeong Mok·2020년 2월 11일
0

Javascript

목록 보기
8/9

Javascript Promise

<script>
  const sexy = new Promise((resolve, reject) => {
    setTimeout(resolve, 3000, "good");
    setTimeout(reject, 4000, "bad");
  });

  sexy
    .then(result => console.log(result))
    .catch(error => console.log(error)); // output : "good"

  const mango = new Promise((a, b) => a(2));
  mango.then(num => num * 2).then(otherNum => console.log(otherNum * 2));//output : 8
</script>

0개의 댓글