자바스크립트는 기본적으로 동기적
setTimeout 은 비동기적
callback도 동기적, 비동기적 두가지의 경우가 있다.
동기적 callback
ex)
console.log('1');
setTimeout(() => console.log('2'), 1000);
console.log('3);
function printImmediately(print){
print();
}
printImmediately(function(){
console.log('hello');
}
)
비동기적 callback
ex)
function printWithDelay(print, timeout){
setTimeout(print, timeout);
}
printWithDelay( ()=> console.log('동기적 callback'), 2000);
)
-> 이코드의 console
1
3
hello
2
동기적 callback
promise
async await
'Javascript' 카테고리의 다른 글
JS 이벤트 전파 중단하는 방법 (0) | 2020.08.30 |
---|---|
JS 정규표현식 (0) | 2020.08.26 |
JS class (0) | 2020.08.24 |
JS 프로토타입과 클래스 - 객체 생성자 (0) | 2020.08.23 |
JS 화살표함수 (0) | 2020.08.20 |