Answer the question
In order to leave comments, you need to log in
Why is a variable declared inside a loop not considered an error?
If you declare any variable, and after it declare another variable with the same name, then there will be an error (Identifier 'max' has already been declared)
let max;
let max;
for (let i = 0; i < 10; i++) {
let max;
console.log(i);
}
Answer the question
In order to leave comments, you need to log in
let and const act up to the nearest brackets, new brackets - new context
You would write what kind of language, but there are rules: curly braces define a block, and inside the block a new level of nesting and local variables, i.e. a local variable is not related to an external variable of the same name.
You can try like this:
let max;
{let max;}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question