๐ŸŸจ JavaScript/๊ฐœ๋…

[mdn, ๋“œ๋ฆผ์ฝ”๋”ฉ, ์ฝ”๋”ฉ์• ํ”Œ] ์ฝœ๋ฐฑํ•จ์ˆ˜ (1) : ๋™๊ธฐ์™€ ๋น„๋™๊ธฐ ๊ฐœ๋…

Zoeeey 2022. 7. 12. 12:27

์ฝœ๋ฐฑํ•จ์ˆ˜

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๋™๊ธฐ์ (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/