3 ms·
local const variables like JavaScript has them. You can declare variables with „let“ (mutable) or „const“ (immutable). This is really great when reading code, b
by andix 4y ago
local const variables like JavaScript has them. You can declare variables with „let“ (mutable) or „const“ (immutable). This is really great when reading code, because you never have to check if some code may change the variable at some point. And you usually declare most variables as const.
A lot of languages provide immutable variables only for class members or statics, but not for local variables.
- kaba0 4y agoI really like Scala’s `val` vs `var`.
- andix 4y agoOkay, that would confuse me. Looks very similar and easy to overlook.
- jlokier 4y agoSyntax highlighting can help with distinctions like that. You might prefer Nim's visually distinct "let" for immutable, "var" for mutable. "const" is also available and means resolved to constant at compile time, similar to Zig's "comptime".
- culi 4y agoit hurts that `let`, `var`, and `const` are all used in JS and mean completely different things. `let` even means the exact opposite
- still_grokking 4y agoActually not, as firstly you almost never use `var`s, and secondly if you do, most syntax highlighting rules will make them shine in bright color as something very exceptional.
- sureglymop 4y agoSame in Kotlin
- still_grokking 4y agoNo surprise though as Kotlin is a cheap Scala rip off.