top | item 40255036

(no title)

rrherr | 1 year ago

https://www.joshwcomeau.com/javascript/the-const-deception/

discuss

order

ralusek|1 year ago

I don’t get this argument. const means you can’t reassign the variable, that’s it. If you don’t plan on reassigning the variable, use const. In the rare places that you don’t use const, you’re telling me that you reassign the variable somewhere.

I don’t understand why people need const to be something it’s not. The fact that you can still mutate objects is because in js, an object assigned to a variable is best thought of as a pointer to a value in the heap. const means the variable won’t reassign the reference, Object.freeze means the referenced data can’t change. Both useful, both different use cases; needn’t be conflated.