DEV Community

loading...

Discussion on: TypeScript tips from Kotlin developer - const

Collapse
maxart2501 profile image
Massimo Artizzu

Oh, not just in TypeScript: in JavaScript too. That's an advice I repeatedly tell as a good practice.

But don't ever forget that it will not make your objects immutable.

Collapse
nepeckman profile image
nepeckman

Yeah this is a really important distinction. const and val are read only value references, but they don't mean that the value is an immutable value. You can still change the state of the object, and you don't get any of the guarantees around thread safety mentioned in the linked article.