r/learnjavascript • • Oct 19 '26

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

23 comments sorted by

View all comments

Show parent comment

1

u/tambooby Oct 20 '26

the hoisting bit is a good callout, that trips people up more than scoping does imo

1

u/chikamakaleyley helpful Oct 20 '26

when i first learned that i thought someone was playing a cruel joke on me. "You can't just make up stuff man!"