티스토리 뷰

 

 

 

1. ?에 각각 들어가야 하는 코드는?

const new = {
  name:  'request',
};

fetch('url', {
    method: 'POST',
    body: ?(new), // 자바스크립트 객체를 string 타입의 JSON 데이터로 변환해야 함.(Serialization)
})
    .then(() => {
    fetch('url')
      .then((response) => response.text())
      .then((result) => {
        const users = ?(result); // string 타입의 JSON 데이터를 자바스크립트 객체로 변환해야 함.(Deserialization)
        console.log(users);
      });
  });

답: JSON.stringify, JSON.parse

 

2. 다음 코드의 비동기 실행 결과로 옳은 것은?

console.log('Start!'); // (1)

fetch('<https://www.google.com>')
  .then((response) => response.text())
  .then((result) => { console.log(result); }); // (2)

console.log('End'); // (3)

 

답: (1) > (3) > (2)

 

3. promise 객체의 세가지 상태를 설명하시오.

 

답:

Promise 객체는 어떤 작업에 관한 '상태 정보'를 나타낸다. Promise 객체는 크게 세 가지 중 하나의 상태를 가진다.

 

1. Pending: 작업이 진행중임을 의미한다.

2. Fulfilled: 작업이 성공적으로 완료되었음을 의미한다.

3. Rejected: 작업이 실패했음을 의미한다.

 

4. 인터넷이 안되는 상황에서 아래 코드의 결과는?

fetch("<https://jsonplaceholder.typicode.com/>").then(
    (result) => {
        console.log("success");
    },
    (error) => {
        console.log("fail");
    }
);

답: fail

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함