const stands for constant, and it means the variable cannot be reassigned at a later time.

let is similar to var except that it is block scoped, which means it can be declared inside of a for loop and will be local to the body of that for loop (and therefor does not exist outside of it)

The latter is different from a var variable which can be declared anywhere but is always local to the function scope.

In general it is good practice to try and define your variables as const as much as possible.

Answer from vileRaisin on Stack Overflow
🌐
TypeScript
typescriptlang.org β€Ί docs β€Ί handbook β€Ί variable-declarations.html
TypeScript: Documentation - Variable Declaration
In other words, they have the same scoping rules as let, but you can’t re-assign to them. This should not be confused with the idea that the values they refer to are immutable. ... Unless you take specific measures to avoid it, the internal state of a const variable is still modifiable. Fortunately, TypeScript ...
Discussions

TypeScript/ES2015: Prefer `const` instead of `let` reduces readability?
ES2015 introduced the let and const keywords, which essentially have the same semantics apart from reassignment. (const can be seen as a final variable in languages like Java.) I see the point of More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
JS <> const vs let = should I always use const?
It's not a matter of preference, rcommended, or ideal programming style. const and let have their own purpose. One is not absolute better than the other. It would depend on whether the contained (direct) value may be changed or not; or whether it needs to be protected from being changed or not - either by your own code, or by others' code which you don't have control of. If neither doesn't matter, there's no difference betwen using const or let. More on reddit.com
🌐 r/learnprogramming
14
8
November 6, 2022
Benefit of const vs let in TypeScript (or Javascript) - Stack Overflow
I was reading the TypeScript Deep Dive and I see that both let and const are block scoped, which is great. Obviously, a const cannot be changed (it is immutable). But why is ReSharper is encouragin... More on stackoverflow.com
🌐 stackoverflow.com
How much should I be using 'let' vs 'const' in ES6?
I've been writing a lot of ES6 code for io.js recently. There isn't much code in the wild to learn from, so I feel like I'm defining my own conventions as I go. My question is about when to use co... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
April 9, 2015
🌐
Medium
medium.com β€Ί @robinviktorsson β€Ί understanding-the-differences-between-var-let-and-const-in-javascript-and-typescript-0ddd90c0b672
Understanding the Differences Between var, let, and const in JavaScript and TypeScript πŸ’» | by Robin Viktorsson | Medium
March 10, 2025 - ... Use var only if you are working ... rare in modern JavaScript/TypeScript). Use let when you need a block-scoped variable that can be reassigned, especially within loops or conditions....
🌐
Tutorial Teacher
tutorialsteacher.com β€Ί typescript β€Ί typescript-variable
TypeScript Variable Declarations: var, let, const
This increases the code readability and maintainability. Variables can be declared using const similar to var or let declarations. The const makes a variable a constant where its value cannot be changed.
🌐
Total TypeScript
totaltypescript.com β€Ί let-and-const
How let and const Work In TypeScript | Total TypeScript
February 26, 2024 - So, TypeScript uses how JavaScript works to its advantage. This will often encourage you to use const over let when declaring variables, as it's a little stricter.
Find elsewhere
Top answer
1 of 2
5

*sigh*... This is why immutable needs to be the default. Even the referenced Java answer suggests this. Note that that answer does not recommend removing final modifiers, just that the author of that answer wouldn't add them in new code (for local variables) because they "clutter up" the code.

However, there is a difference between JavaScript and Java here. In Java, final is an additional modifier on a variable declaration, so you get:

final int foo = 3; // versus
int foo = 3;

In JavaScript, though, const is just an alternate variable declaration, so the situation is:

var foo = 3; // (or let nowadays) versus
const foo = 3;

I don't think two more characters constitutes "clutter". If the alternative being suggested is just foo = 3 then the reviewers are just wrong.

Personally, I would always use const when applicable and would suggest it's inclusion in a code review. But then I'm a Haskeller, so I would be like that. But also, JavaScript tends to be more pervasively mutable and have a worse debugging story when things do unexpectedly change, that I would say const in JavaScript is more valuable than final in Java (though it's still valuable there.)

As Ixrec points out, const only controls the modifiability of the binding, not the object that is bound. So it's perfectly legal to write:

const foo = { bar: 3 };
foo.bar = 5;

This can be used as an argument against using const as someone may be surprised when an "unmodifiable" object is modified. Newer versions of JavaScript do have a mechanism to actually make objects unmodifiable, namely Object.freeze. It makes a good addition to const (though only use it on objects that you create, for example, as Object.freeze({ ... })). This combination will communicate and enforce your intent. If used consistently, the times where you are mutating things will stick out and clearly signal non-trivial data flow.

2 of 2
0

It is indeed good practice to declare variables as const (or readonly or final, depending on the language) if possible.

The author of the linked answer also admits that is is right to mark variables as final, but the author is simply too lazy to do it.

Even if the authors opinion about "clutter" was right, then it wouldn't apply to JavaScript or TypeScript, since const is instead of let, not in addition to.

🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί var-let-and-const-whats-the-difference
Var, Let, and Const – What's the Difference?
April 2, 2020 - While a const object cannot be updated, the properties of this objects can be updated. Therefore, if we declare a const object as this: ... This will update the value of greeting.message without returning errors. Just like let, const declarations are hoisted to the top but are not initialized.
🌐
Overreacted
overreacted.io β€Ί on-let-vs-const
On let vs const β€” overreacted
December 22, 2019 - This turned out to be very controversial, sparking conversations on Twitter and Reddit. It seems that the majority view (or at least, the most vocally expressed view) is that one should use const wherever possible, only falling back to let where necessary, as can be enforced with the prefer-const ESLint rule.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί javascript β€Ί difference-between-var-let-and-const-keywords-in-javascript
Difference between var, let and const keywords in JavaScript - GeeksforGeeks
This happens because let variables are hoisted but not initialized, so they remain in the TDZ until the declaration is executed. ... Hoisting with const: The variable x is declared with const, which is block-scoped and not hoisted.
Published Β  January 16, 2026
🌐
TutorialsPoint
tutorialspoint.com β€Ί home β€Ί typescript β€Ί typescript let and const
TypeScript let and const
December 18, 2016 - TypeScript has the same rules as JavaScript to declare variables. Initially, only the 'var' keyword was used to declare the variable, but in the ES6 version of JavaScript 'let' and 'const' keywords are introduced to declare a variable.
Top answer
1 of 2
56

I agree with Giorgi that performance is not the main reason. A code analyzer could just as well determine that a variable declared with let is not ever reassigned and optimize it the same as if you had declared it with const. (Heck, linters have rules to detect this and suggest using const instead of let.)

Yes, it does signal to the reader that you're not going to assign to the variable. The benefit of const, over putting a comment saying the same thing, is mainly that const is a standard way of signalling it. Being standard, it transmits the information more readily than custom comments. (Also, a comment could be wrong but const won't let you be wrong.) I don't think this is the main benefit though.

The "principle of least privilege" is often invoked in conjunction with const, but why should I care about the least privilege? Because it helps with early detection of coding mistakes. Consider the following code:

function findSomethingInDocument(document) {
    let tree = getTreeFromDocument(document); // We get some sort of tree structure.
    let found;
    for (const child of tree.children) {
        if (child.someFlag) {
            tree = child; // Oops I meant found = child :(
            break;
        }
    }
    return found;
}

In this code, I typed tree = child when I meant to type found = child. Yes, the bug can be found in testing. But why wait for testing? I never meant tree to be changed. If I had marked it const then I would have immediately learned the error because the compiler would informed me of it. I would not have to wait for testing. The code above is fairly simple but imagine a more complicated algorithm that uses more variables.

2 of 2
16

When you have a variable which can be declared as const, and you declare it as such you inform the reader that you don't plan to reassign it to a different value later on.

Also by declaring a variable const it means you have thought up front that you don't plan to reassign it, which in turn can protect you from accidental bugs or errors.

🌐
Gazar
gazar.dev β€Ί typescript β€Ί when-to-use-let-vs-const
When to Use let vs const in TypeScript | Gazar
let counter = 0; if (true) { let counter = 1; console.log(counter); // Output: 1 } console.log(counter); // Output: 0 Β· The const keyword is used to declare variables that cannot be reassigned. Like let, const is also block-scoped. However, it does not mean the value it holds is immutable.
🌐
SheCodes
shecodes.io β€Ί athena β€Ί 124459-why-are-we-using-let-and-not-const
[JavaScript] - Why are we using let and not const? - | SheCodes
In programming, let and const are both used to declare variables. Find out why we choose let over const and when to use each one.
🌐
YouTube
youtube.com β€Ί watch
Differences Between Var, Let, and Const - YouTube
You have probably watched many different tutorials, and you may have noticed that some tutorials use var to declare variables while others use let or even co...
Published Β  November 10, 2018
Top answer
1 of 6
185

My reply here is not javascript-specific.

As a rule of thumb in any language that lets me do so in a semi-easy way I'd say always use const/final/readonly/whatever it is called in your language whenever possible. The reason is simple, it's much easier to reason about code when it is dead obvious what can change and what cannot change. And in addition to this, in many languages you can get tool support that tells you that you are doing something wrong when you accidentially assign to a variable that you've declared as const.

Going back and changing a const to a let is dead simple. And going const by default makes you think twice before doing so. And this is in many cases a good thing.

How many bugs have you seen that involved variables changing unexpectedly? I'd guess a lot. I know that the majority of bugs that I see involve unexpected state changes. You won't get rid of all of these bugs by liberally using const, but you will get rid of a lot of them!

Also, many functional languages have immutable variables where all variables are const by default. Look at Erlang for example, or F#. Coding without assignment works perfectly in these languages and is one of the many reasons why people love functional programming. There is a lot to learn from these languages about managing state in order to become a better programmer.

And it all starts with being extremely liberal with const! ;) It's just two more characters to write compared to let, so go ahead and const all the things!

2 of 6
57

Be careful, because const object keys are mutable.

From here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

object keys are not protected

consider this example:

const colors = {red: "#f00"}; 
console.log(colors); // { "red": "#f00" }

colors.red = "#00f";
colors.green = "#0f0";
console.log(colors); // { "red": "#00f", "green": "#0f0" }

Same thing for arrays:

const numbers = [1, 2, 3];
console.log(numbers); // [ 1, 2, 3 ]

numbers.push(4);
console.log(numbers); // [ 1, 2, 3, 4 ]

I haven't decided totally myself, but I'm considering using const for all non-array/non-objects and use let for objects/arrays.

🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί differences-between-var-let-const-javascript
var, let, and const in JavaScript – the Differences Between These Keywords Explained
January 11, 2023 - In this regard, const is different from var and let. const is used for declaring constant variables – which are variables with values that cannot be changed. So such variables cannot be redeclared, and neither can they be reassigned to other ...
🌐
Home
javahabit.com β€Ί typescript-variable-let-var-const
TypeScript's Variable Wars: Battle of let vs. const vs. var – Which One Wins?
May 28, 2023 - Understanding the differences between TypeScript's variable declarations is essential for writing clean and reliable code. This article explores the contrasts between let, const, and var, providing definitive examples to illustrate their unique features. While var offers familiarity but carries risks such as hoisting, let embraces block scoping, enhancing code readability and preventing redeclarations.