const something = document.createElement("p");
for (let i = 0; i < 5; i++) {
something.textContent = i;
document.body.appendChild(something);
}
// 4
for (let i = 0; i < 5; i++) {
const something = document.createElement("p");
something.textContent = i;
document.body.appendChild(something);
}
/*
0
1
2
3
4
*/
ex1)
something이 for문 밖에서 선언 되었기 때문에 p태그 한번만 생성됨.. for문 마지막 숫자인 4만 출력
ex2)
something이 for문 안에 선언 되어서 p태그 5번 생성됨..
0~4 출력됨