Javascript
Call back 함수
자라나라나무나무나
2022. 4. 8. 21:35
함수에 파라미터로 들어가는 함수
순차적으로 실행하고 싶을 때 사용
document.querySelector(.button).addEventListener("click", function() {
});
addEventListener(함수) 안에 파라미터로 함수를 넣는 경우 콜백함수라고 부를 수 있다.
대표적인 콜백함수
setTimeout(function() {
},1000);
예시
function first() {
console.log(1);
}
function second() {
console.log(2);
}
first(second);
first 함수 다음 second함수 실행하고 싶으면?
function first() {
console.log(1);
second();
}
function second() {
console.log(2);
}
first(second);
참고 : https://www.youtube.com/watch?v=-iZlNnTGotk