
fetch 함수가 반환하는 Promise를 어떻게 사용(Consume)하는지 방법을 알아보자. 아래는 오픈 API를 사용해 국가(country) 데이터를 가져오는 코드이다. 처음 fetch로 요청했을 때 Promise는 'pending' 상태이다. 비동기 작업이 백그라운드에서 실행 중이기 때문이다. 이후, 어느 시점이 되면 Promise는 'settled(정해짐)' 상태로 이동하여, fulfilled 또는 rejected가 된다. const getCountryData = function (country) { fetch(`https://restcountries.com/v2/name/${country}`).then(function ( response ) { console.log(response); }); }..