2 ms·
Why? `const` isn't that much immutable than `let` is. For any reference type that's bound to a variable with `const`, you can mutate it without getting errors.
by elros 11y ago
Why? `const` isn't that much immutable than `let` is. For any reference type that's bound to a variable with `const`, you can mutate it without getting errors. This was very confusing to me at first, even though I understand the mechanics behind it.
const a = {}
// That's OK:
a.a = 1
// That's not OK:
a = 1
While I don't disagree with you on your point, one could easily create the counter-point that by using `const` you're implying something that's not true.
- kansface 11y agoThe translation to C would be * const, not const *. Const is strictly better than let because it prevents a certain class of bugs - use it everywhere possible instead of let/var.