async, await 내가 이해한 내용

skj1211·2022년 5월 13일
0

22.05.13

개념 설명 없이 그냥 사용법 적어봄

fetch('http://example.com/movies.json')
  .then((response) => response.json())
  .then((data) => console.log(data));

이런 방식으로만 써왔었음

function insertProductElement() {
  fetch(`uri`)
  	.then((res) => res.json)
    .then((data) => console.log(data))
  const title = data.title
  const name = data.name

async, await 사용

async function insertProductElement() {
  const res = await fetch(`uri`)
  const data = await res.json()
  
  const title = data.title
  const name = data.name

.then 사용없이 변수로 간단하게 불러 사용 가능해짐

0개의 댓글