더북(TheBook)

이 코드를 개발자 도구 또는 CodeSandBox에서 실행해보세요. 결과는 다음과 같습니다.

calculating...
9! = 45
hello

이 코드는 calculate 함수로 1부터 9까지의 합을 연산한 다음, hello 함수를 호출합니다.

다음으로, 비동기적 작업은 특정 작업이 끝나지 않아도 다음 작업을 수행합니다. 다음 예시 코드를 확인해보세요.

function calculate() {
  console.log('calculating...');
  setTimeout(() => {
    let result = 0;
    for (let i = 1; i < 10; i++) {
      result += i;
    }
    console.log(`9! = ${result}`);
  }, 0)
}

function hello() {
  console.log('hello');
}

calculate();
hello();
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.