Super Kawaii Cute Cat Kaoani
본문 바로가기
728x90

promise2

5주차 스터디 자바스크립트 웹 개발 기본기 (4) async/await을 활용한 세련된 비동기 코드 [코드잇 부스트 백엔드 스터디 ] 4. async/await을 활용한 세련된 비동기 코드   async/await이란?  promise 객체가 등장함으로써 콜백 헬을 해결할 수 있게됨→ 이후에도 발전되어 async/await을 사용하게 됨 async funtion fetchAndPrint(){ const response = await fetch('https://jsonplaceholder.typicode.com/users'); const result = await response.text(); console.log(result);} fetchAndPrint();  asynchronous 의 줄임말을 사용 (비동기를 의미한다)await : 뒤에 코드를 실행하고 코드가 리턴하는 promise 객체를 기다린다fulfilled 상태가 되면.. 2024. 6. 4.
5주차 스터디 자바스크립트 웹 개발 기본기 (3) 비동기 실행과 Promise 객체 [코드잇 부스트 백엔드 스터디 ] 3. 비동기 실행과 Promise 객체    fetch 함수와 비동기 실행  비동기 실행한번 시작된 작업이 완료되기 전에 바로 다음코드로 실행이 넘어가고 나중에 콜백이 실행됨으로써 작업이 마무리 된다   console.log('Start!');fetch('https://jsonplaceholder.typicode.com/users') .then((response)=>response.text()) .then((result)=>{console.log(result);});console.log('End'); fetch 함수에 비동기 실행이 되는 부분이 있다 fecth 함수는 리퀘스트를 보내고 어떤 객체를 리턴한다그 객체의 then 메소드로 콜백을 등록한다→ 콜백은 서버로부터 리스폰스를 받았을 때 실행된다  .. 2024. 6. 4.
728x90