콜백함수
자바스크립트는 동기적(synchronous) 언어이다. 이 말은 코드를 작성한 순서에 맞춰 동기적으로 실행된다는 말이다.
아래는 비동기적으로 실행되는 함수이다.
console.log('1');
setTimeout(() => console.log('2'), 1000);
console.log('3');
//1
//3
//2
Synchronous callback
function printImmediately(print) {
print();
}
printImmediately(() => console.log('hello'));
Asynchronous callback
function printWithdelay(print, timeout) {
setTimeout(print, timeout);
}
printWithdelay(() => console.log('hello'), 2000);
출처 : 드림코딩 https://www.youtube.com/@dream-coding / MDN https://developer.mozilla.org/ko / 코딩애플 https://codingapple.com/
'🟨 JavaScript > 개념' 카테고리의 다른 글
| [드림코딩] 콜백함수 (2) : 콜백지옥 탈출, Promise (State, Producing) (0) | 2022.07.22 |
|---|---|
| [드림코딩] 콜백함수 (1) : 콜백지옥 예시 (0) | 2022.07.22 |
| [드림코딩] JSON to Object (parse) (0) | 2022.07.12 |
| [드림코딩] Object to JSON (stringify) (0) | 2022.06.29 |
| [드림코딩] JSON이란? (0) | 2022.06.29 |