7 ms·
why does javascript have a const keyword which shouldn't be used?
by exit 16y ago
why does javascript have a const keyword which shouldn't be used?
- goodside 16y agoThe inclusion of const in JS predates its use by Microsoft in Internet Explorer, which doesn't support it (at least up to IE6). It's not that it won't respect its const-iness; it won't even do the initial assignment. The original designers at Netscape couldn't have foreseen this, so it's in the language.
- markkanof 16y agoThe document says not to use const but you can use @const when appropriate. Can anyone explain what @const does? In the documentation example code it looks like it is just in the comments.
- riprock 16y agoMy other comment touches on this but the Closure Compiler parses the JSDoc comments and gives warnings for rules that are violated in the code.
- axod 16y agomany of the reserved words in js are taken from java. abstract goto debugger enum native implements protected synchronized throws transient volatile ^^ All 'reserved' for future use. const is used in the js 2.0 spec though.