const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
wait(0).then(() => console.log(4)); //0을 설정해도 약간의 딜레이 발생
Promise.resolve()
.then(() => console.log(2))
.then(() => console.log(3));
console.log(1); // 1, 2, 3, 4
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
wait(0).then(() => console.log(4)); //4가 먼저 출력될거 같다.
Promise.resolve()
.then(() => {
for (let i = 0; i < 10000; i++) {
console.log(2);
}
})
.then(() => console.log(3));
console.log(1); // 하지만 결과는 1, 2(10000개), 3, 4
var a = 1;
function outer() {
function inner() {
console.log('inner function:: ', a);
var a = 3;
}
inner();
console.log('outer function:: ',a);
}
outer();
console.log('outer::', a);
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
wait(0).then(() => console.log());
console.log(1);
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
wait(0).then(() => console.log(4));
Promise.resolve()
.then(() => {
for (let i = 0; i < 10000; i++) {
console.log(2);
}
})
.then(() => console.log(3));
console.log(1);
https://meetup.nhncloud.com/posts/89
https://velog.io/@seonghyeon01/javaScript-%EC%8B%A4%ED%96%89%EC%BB%A8%ED%85%8D%EC%8A%A4%ED%8A%B8%EC%99%80-%EC%BD%9C-%EC%8A%A4%ED%83%9D