let vs const — which to use, and why AI writes const almost everywhere

Open any file AI wrote for you. Count how many times it says const and how many times let. Most likely it's a blowout — ten to one, maybe twenty.
That's not a quirk of the model. There's a rule behind it that saves hours of debugging. Plus one misconception: const doesn't mean "this can't be changed" at all. Let's see what each word actually promises.
How they differ
Both words declare a variable — a tag you hang on a value. The difference is exactly one thing:
let— the tag can be moved to a different value.const— the tag is tied on for good. It can't be moved.
let score = 0
score = 10 // fine: we moved the tag
const name = "Anya"
name = "Olya" // TypeError: Assignment to constant variable
That's the whole difference. Everything else follows from it.
The trap: const doesn't mean "immutable"
The most common beginner misconception. const forbids moving the tag. But what's inside the value can still change:
const cart = ["tea"]
cart.push("honey") // fine! the cart now has two items
cart = ["coffee"] // not allowed: that's trying to move the tag
Same with objects. const user = { name: "Anya" }, then user.name = "Olya" — perfectly legal. The tag hangs on the same card; a field on the card just changed.
Remember the picture: const is a label glued onto a box. You can't swap the box. But you can rearrange what's inside as much as you like.
Criteria breakdown
Let's go through the questions that actually matter when you read or edit code.
Can you assign a new value?
let— yes, as many times as you want.const— no, only once, at declaration.
Can you change the contents of a list or object?
let— yes.const— also yes. Only the tag itself is protected.
Can you declare it without a value?
let— yes:let result, fill it in later.const— no:const xwith no value is an instant error.
Where is the variable visible?
- Same for both. Each lives inside its nearest curly braces — that's scope.
What does it tell the reader?
let— "heads up, this value will change further down."const— "you can stop tracking this, the tag isn't going anywhere."
That last point is the main reason AI picks const.
Which one fits who
A verdict without diplomacy: write const by default. Switch to let only when you actually reassign the value.
let belongs in three typical places:
- counters and accumulators —
let total = 0, thentotal += pricein a loop; - a value chosen by a condition —
let label, then anifassigns it one thing or another; - overwriting as you go — say, a request retry:
let attempt = 1, thenattempt++.
Everything else is const. Why it pays off: when you read someone else's code and see const, you can drop that variable from your head — it won't change somewhere below. The fewer lets, the fewer places a bug can hide. Many linter setups even include a prefer-const rule: it flags any let that's never reassigned.
What about var? Don't pick it at all. It's an old keyword that predates let and const by years. It ignores curly braces and behaves oddly. If you spot var in AI code, feel free to ask for it to be replaced.
What it looks like in AI code
Here's a typical chunk a model writes for a shopping cart. Notice where each word sits:
const items = await loadCart()
let total = 0
for (const item of items) {
total += item.price * item.qty
}
const label = total > 0 ? "Checkout" : "Cart is empty"
items is loaded once and never touched again — const. total grows in the loop — let. item inside for...of is also const: each step creates a new tag, and nobody moves the old one. And label is picked in a single line with a condition, so const is enough.
Code like this is easy to read: the one let immediately shows where the changing part lives. If the total is wrong, look near total.
Does Python have const?
No. In Python any variable can be reassigned. Instead of a rule, there's a convention: names in ALL CAPS, like MAX_USERS = 100, are treated as constants and left alone by agreement.
Which one is faster?
In practice there's no speed difference. Choosing between let and const is about readability and guarding against mistakes, not performance.
What happens if I just use let everywhere?
The code will work. But you lose the hint: a reader has to check every variable to see whether it gets overwritten further down. And you lose protection against an accidental = where you meant ===.
Short story-lessons, an agent simulator and daily practice — in our mobile app. Free.





