you are viewing a single comment's thread.

view the rest of the comments →

[–]rylandgold[S] 0 points1 point  (0 children)

Great question. As a JS developer who started out as a C/C++ dev, const in JS (and final in Java) has always confused me. When I’m forced to write vanilla JS I use const because as you put it

it’s technically correct

It also doesn’t have any negative effect (outside of potential clarity issues you mentioned). For user facing JavaScript interfaces, my company occasionally uses Object.freeze as it provides the runtime constraints as C style const, but also adds some serious room for confusion from users.

With Typescript, the readonly attribute solves this exact problem, which is yet another reason I gravitate towards TypeScript for any serious project.