[개발자되기: 비동기, fetch API] Day-24

Kyoorim LEE·2022년 6월 1일
0

Promise

then, catch

Promise.prototype.then 메서드는 무엇을 리턴하나요?

=> promise를 리턴

Promise.prototype.catch 메서드는 무엇을 리턴하나요?

=> promise를 리턴

Promise의 세 가지 상태는 각각 무엇이며, 어떤 의미를 가지나요?

=> pending/ fulfilled/ rejected

await 키워드 다음에 등장하는 함수 실행은 어떤 타입을 리턴할 경우에만 의미가 있나요?

=> promise

const resolveAfterRandomSeconds = async (message) => {
  return new Promise((resolve,reject) => {
    setTimeout(() => {
      resolve(message);
    }, 5000)
  })
}

let resut = await resolveAfterRandomSeconds('codestates');
console.log(result) // 'codestates'

JSON.parse()

문자열을 객체로 바꿔줌

fetch API

특정 URL로부터 정보를 받아오는 역할
계속 업데이트가 되어야하는 부분(ex. 포털 메인사이트 내 최신뉴스, 미세먼지/날씨 정보 등)

response

.then(response => response.json())

JSON.parse() 랑 비슷한 기능 함

profile
oneThing

0개의 댓글