Skip to content
loading...

re: Declaring JS Variables in 2019 VIEW POST

FULL DISCUSSION
 

You also need to remember that let and const have block scope:

let i = 0;
console.log(1,i);
if(i===0){
  let i = 1;
  console.log(2,i)
}
console.log(3,i)

This will result in a log of

1 0
2 1
3 0
 

Actually, not mentioning this was one of the goals of my article. I think this behavior, for new programmers, is logically the most sensible!

(Having a comment pointing it out is fine though 😅)

code of conduct - report abuse