callback

김혁중·2022년 3월 19일
0

JavaScript

목록 보기
15/23

callback

  • 콜백 함수는 다른 함수에 인자로 전달된 함수이며, 어떤 이벤트가 발생했거나 특정 시점에 도달했을 때 작동

동기식 콜백

function printImmediately(print) {
  print()
}
printImmediately(() => console.log('Synchronous callback'))
  • 즉시 실행

비동기 콜백

function printWithDelay(print, timeout) {
  setTimeout(print, timeout)
}
printWithDelay(() => console.log('Asynchronous callback'), 500)
  • 0.5초 후 실행
profile
Digital Artist가 되고 싶은 초보 개발자

0개의 댓글