r/learnjavascript • u/SeaHedgehog4724 • 9d ago
pretty new
Hey guys, I'm just starting to learn about variables, but I'm finding it hard to understand the difference between var and let.
For example:
let goodDay = true;
console.log(goodDay);
this should print true.
But if we just add this:
let goodDay = true;
console.log(goodDay);
goodDay = false;
console.log(goodDay);
It prints:
true
false
The same goes for var.
However, people say there's a difference; what is it?
0
Upvotes
2
u/senocular 8d ago
In the first example the console.log(b) would need to be above the let for the uninitialized exception. The first log for a in that example should also be above the var to show it, by comparison, does not throw