setTimeout(() => console.log('2'), 1000); // 비동기

function printImmetiately (print) {
    print(); // 동기 callback 함수 호출
}
printImmetiately( () => console.log('hello')); // 동기

function printWithDelay(print, timeout) {
    setTimeout(print, timeout); // 비동기
}
printWithDelay(() => console.log('async callback'), 2000); // 비동기

자바스크립트의 처리 과정

  1. 호이스팅으로 function printImmetiately (print) 맨 위로 선언
  2. 호이스팅으로 function printWithDelay(print, timeout) 맨 위로 선언
  3. 동기 실행 (순차적 실행)
  4. 비동기 함수 setTimeout(() => console.log('2'), 1000); 는 나중에 실행
  5. 비동기 함수 printWithDelay(() => console.log('async callback'), 2000); 는 나중에 실행
  6. 동기 함수 호출 printImmetiately( () => console.log('hello')); 실행
  7. 비동기 출력