I'm a newbie in JavaScript and trying to learn about Objects and for..in loop.
Then I tried this code in the browser:
const dad = {
gender: 'male',
age: 53
}
for(let prop in dad){
console.log(prop, dad[prop]);
}
It showed the result once, but then when I run again, the console says:
Uncaught SyntaxError: Identifier 'dad' has already been declared
I've tried to do some Google search and read through about scope and block scoping, but still not yet really understand
When I tried to block the code with an outer scope ( grap the code in a {}
) or put the code in a function, it works well.
Please help me understand this