DEV Community

Discussion on: Declaring JS Variables in 2019

Collapse
 
aprouja1 profile image
aprouja1

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
Collapse
 
samthor profile image
Sam Thorogood

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 😅)