3
const body = document.querySelector("body");
const divElement = document.createElement("div");
divElement.setAttribute("id", "resultado");
body.appendChild(divElement);
for(i = 1; i <= 20; i++) {
const textElement = document.createElement("p");
textElement.innerHTML = "Resultado: " + i;
divElement.append(textElement);
}
What happens exactly inside the for
with the const textElement
? (The code works normally, but I was wondering what’s going on over there with that constant)
- A
array
with 20 positions(textElement[1], textElement[2]... textElement[n])
? - To
constante
is superscripted? - A new value is obtained for each loop?
- If it is none of the above causes, what happens then?
The constant is within the scope of the for, that is, there will only be the constant in the current iteration and in the next cycle the constant will be declared again, pq ai will be another iteration scope.
– Max Rogério