<button id="fetch-btn">1번 게시글 데이터 요청 후 게시글의 제목 화면에 출력</button>
<div>1번 게시글 제목: <span id="post-title"></span></div>
<span id="post-title"> 안에 1번 게시글 제목을 표시document.querySelector('#fetch-btn').addEventListener('click', () => {
fetch("https://jsonplaceholder.typicode.com/posts/1")
fetch()는 Promise 객체를 반환.then().then((response) => response.json())
fetch()의 반환 값은 Response 객체response.json() → Response 안의 JSON 데이터를 JS 객체로 변환response.json()도 Promise를 반환하기 때문에 다음 .then()으로 이어질 수 있음.then().then((jsonData) => document.querySelector("#post-title").innerText = jsonData.title);
title 속성을 가져와 화면에 출력fetch() 실행 → Promise 반환response.json() → 문자열(JSON) → JS 객체 변환 (또 Promise)title 추출 → 화면에 출력.then() 체이닝으로 순차적 처리 가능async/await와 함께 쓰면 더 동기 코드처럼 깔끔하게 작성 가능원하면 내가 XHR + Fetch 비교표 만들어서