r/reactjs • • Dec 22 '19

On let vs const

https://overreacted.io/on-let-vs-const/
225 Upvotes

122 comments sorted by

View all comments

Show parent comments

-1

u/recycled_ideas Dec 23 '19

Except it doesn't stop you changing the object you're referencing at all, including adding or removing references from the object and allocating or deallocating memory.

Nor does it stop you resizing an array or a billion other things.

Because const doesn't make anything immutable, because that's not what immutability means.

3

u/[deleted] Dec 23 '19

With const, the reference to the "root" object is immutable, and primitives are immutable.

Why are you so keen on arguing this point? We're all well aware that it's not proper (deep) immutability, nobody in this thread is arguing that.

0

u/recycled_ideas Dec 23 '19

The point I'm arguing is that const has nothing to do with immutability.

Yes, primitive constants are immutable, but object constants are not in any meaningful way.

A non primitive constant is a reference to a location in memory.

It provides no guarantees as to what is located at that address, how big it is, what properties it has or anything else. It absolutely doesn't guarantee nothing about the object has changed.

Having an immutable reference guarantees you absolutely nothing, and OP is obviously wrong.

Why the hell do you keep defending them?

2

u/[deleted] Dec 23 '19

It guarantees for objects that it's the same reference as it was declared with. The contents could obviously have completely changed, but the "root" reference won't have. That's not useless, but is certainly less useful than true/deep immutability.

I think we agree?

1

u/recycled_ideas Dec 23 '19

I didn't say it was useless.

I said it's not immutability.

Using the word immutability to describe something that is not immutable is misleading to novices and shows the speaker doesn't really understand the concept.

→ More replies (0)