From 7fc7a250e203f96946b10bbe7b0429675f364dbd Mon Sep 17 00:00:00 2001 From: jstar_00 Date: Tue, 2 Dec 2025 20:28:31 +0900 Subject: [PATCH] =?UTF-8?q?6=EC=A3=BC=EC=B0=A8=20=ED=80=B4=EC=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week6_JISUNG/quiz.md | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 week6_JISUNG/quiz.md diff --git a/week6_JISUNG/quiz.md b/week6_JISUNG/quiz.md new file mode 100644 index 0000000..0d335fa --- /dev/null +++ b/week6_JISUNG/quiz.md @@ -0,0 +1,55 @@ +## Q1. 비동기 함수와 콜백 + +```javascript +function foo() { + let todos; + + const get = (url) => { + const xhr = new XMLHttpRequest(); + xhr.open("GET", url); + xhr.send(); + + xhr.onload = () => { + if (xhr.status === 200) { + console.log("A: 비동기 콜백 (함수 내부)"); + } else { + console.error(); + } + }; + }; + + get("url"); + console.log(todos); // undefined + console.log("B: 함수 내부 동기 코드"); +} + +foo(); // foo 함수 호출 +console.log("C: 함수 외부 동기 코드"); +``` + +**Q: 위 코드의 실행 결과는?** + +## Q2. 비동기 함수와 태스크 큐 + +```javascript +console.log("시작"); + +setTimeout(() => { + console.log("A"); +}, 0); + +Promise.resolve() + .then(() => { + console.log("C"); + setTimeout(() => console.log("D"), 0); + }) + .then(() => console.log("E")); + +console.log("끝"); +``` + +**Q: 이 코드의 실행 순서는?** + +## Q3. async/await + +**Q: 콜백을 인수로 받는 비동기 함수는 try-catch로 에러 처리가 불가능한데, async/await는 왜 가능한가요?**