I'm wondering what is the difference between let and const in ECMAScript 6. Both of them are block scoped
Asked
Active
Viewed 38 times
-2
-
There is indeed [no difference between them with regard to scoping](https://stackoverflow.com/q/31219420/1048572). – Bergi Jan 11 '18 at 12:57
1 Answers
1
The difference between let and const is that once you bind a value/object to a variable using const, you can't reassign to that variable. Example:
const something = {};
something = 10; // Error.
let somethingElse = {};
somethingElse = 1000; // This is fine.
Note that const doesn't make something immutable.
const myArr = [];
myArr.push(10); // Works fine.
Probably the best way to make an object (shallowly) immutable at the moment is to use Object.freeze()
on it.

George
- 6,630
- 2
- 29
- 36

Abdullah Khan
- 649
- 5
- 11