Open davej opened 9 years ago
You are right, but it doesn't make any difference in practice because trying to set an immutable variable is a compile-time error in EG. Though, I should probably generate const
anyway, if that can somehow help browsers run the code faster down the line.
Ah ok, I didn't realise that it was enforced at compile time.
Yeah, I guess I was also just confused that the semantics of var
and let
are completely different than semantics of var
and let
in Javascript. I see that's also how it's done in Swift (and probably other languages), I've just never come across those semantics before.
According to this, const
does cause JS compilation to change but the answer is a bit outdated. However, with ES6 finalized, I think it's definitely a good idea to generate ES6 files with it.
In the documentation it says that the following code gives an immutable variable:
It compiles to the equivalent javascript and
let
is not immutable in javascript, onlyconst
is immutable.