Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You use const because you want a runtime error if someone attempts to change it.

It's also documentation of intent.

Some code, for better or worse has very long functions, and you might use the variable 100 lines down from where it is declared.

Is a runtime error better than letting it silently change? Debatable, but the error is more likely to blow up a unit test, so you know there is a problem before you ship.

And needless to say: in Typescript you'll get a compile time error. In Typescript it's a no-brainer to use const when appropriate.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: