์ฝ๋ฐฑํจ์
์๋ฐ์คํฌ๋ฆฝํธ๋ ๋๊ธฐ์ (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 |