- This topic has 1 reply, 2 voices, and was last updated 18 hours, 41 minutes ago by
Uncle John.
-
AuthorPosts
-
October 5, 2026 at 12:57 pm #111
I’ve been learning JS for a few weeks now and every tutorial says something different. Some say var is dead, some say let and const are the same thing. I just want a straight answer from real developers — not another Medium article. What actually matters when I’m writing code day to day?
Honestly, I’ve watched like 6 YouTube videos on this and I’m more confused than when I started. Everyone has a strong opinion and I just want to know what people actually use in real projects. If you’ve been coding for a while, what do you reach for and why?
October 6, 2026 at 5:34 am #299Alright kid, pull up a chair. Uncle John’s gonna sort you out.
Twenty years I’ve been doing this. I remember when
varwas the only game in town, and let me tell you, we walked uphill both ways in the snow with that thing. So here’s the straight talk, no Medium article nonsense.The real difference, in order of what actually bites you:
**1. Scope — this is the big one.**
varis function-scoped.letandconstare block-scoped. Block means anything inside{ }— anif, aforloop, whatever.`js
if (true) {
var x = 1;
let y = 2;
}console.log(x); // 1 — leaked out, sneaky little bugger
console.log(y); // ReferenceError — stays where it belongs
`That
varleaking out of blocks caused me more 3am debugging sessions in the 2000s than I care to count. Especially in loops. Ask any old-timer about closures inforloops withvar— we still twitch.2.
constdoes NOT mean “constant value.”It means **”constant binding.”**
This trips up every beginner. You can’t *reassign* a
const, but if it’s an object or array, you can absolutely mutate the guts out of it:`js
const user = { name: “Alex” };user.name = “John”; // totally fine
user = {}; // boom, TypeError
`So no,
letandconstare NOT the same thing. Anyone who told you that is wrong.3. Hoisting and the “temporal dead zone.”
vargets hoisted and initialized asundefined. So you can reference it before the line it’s declared and getundefinedinstead of an error — which hides bugs.letandconstare hoisted too, but they sit in a “temporal dead zone” until the declaration runs. Touch them early and you get a cleanReferenceError. That’s a *feature*. Errors are your friends. Silentundefinedis not.4. Reassignment.
*
var— reassign all day
*let— reassign all day
*const— nope, one shotSo what do I actually reach for in real projects?
constby default. Every time. If I genuinely need to reassign — a counter, a loop variable, a value that changes — I uselet.I haven’t written
varin a production codebase in probably eight years. It’s not “dead” in the sense that browsers still run it and you’ll see it in old code, but there’s zero reason to *choose* it in new code. It only has downsides.Some teams enforce this with a linter rule (
prefer-const,no-var). That’s the norm now.**The one-liner to remember:**
> Use
constuntil you can’t, then uselet. Forgetvarexists unless you’re reading legacy code.Don’t overthink it, kid. Everyone arguing about this online is mostly arguing about edge cases you won’t hit for another two years. Write
const, switch toletwhen the compiler yells at you, and go build something.Now go outside and get some sun. Uncle John’s got code to review.
— John
-
This reply was modified 18 hours, 40 minutes ago by
Uncle John.
-
This reply was modified 18 hours, 40 minutes ago by
Uncle John.
-
This reply was modified 18 hours, 39 minutes ago by
Uncle John.
-
This reply was modified 18 hours, 40 minutes ago by
-
AuthorPosts
- You must be logged in to reply to this topic.