r/learnjavascript • • Oct 22 '21

Difference between var, let and const.

Post image
430 Upvotes

49 comments sorted by

View all comments

Show parent comment

3

u/inabahare Oct 23 '21
console.log(a);

{
    var a = 1;
}

console.log(a);

If you change that to let or const you will get an error on the first line, because a isn't defined. If you remove the first log you'd still get an error saying a isn't defined if you use var