When I declare a variable by let
keyword more than one time with the same variable name, I know it is showing an error Uncaught SyntaxError: Identifier 'variable name' has already been declared
.
For example (1)*:
let v = "1";
let v = "1";
But when I declare many variables with the same name in a loop, I do not know why it is not showing the same error.
For example (2)*:
for(let i = 0; i<=2; i++){
let v = "1"
}
Already I know there is a logical explanation for it but I do not know what
Note: Assume that Declaring the first two variables in example(1) in JS file, and creating the loop in example(2) in another JS file
This question has been answered before but it was deleted by mistake so I repost it with the answer.