-2

I'm wondering what is the difference between let and const in ECMAScript 6. Both of them are block scoped

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.