|
|
|
|
|
by masklinn
3205 days ago
|
|
> Defaulting to const does nothing. If you or someone else decides later that it should be reassignable, then they'll change it and not think about it. Which they'll do regardless. `const` is an indication that the binding is not updated in the rest of the scope and thus that said scope can be perused without needing to consider an update to the binding itself. It is a guarantee of SSA, nothing more and nothing less. > If const is rare in your code, people will be aware of what const means in that context. The same as above which you apparently assert is "nothing"? > If you're putting your variable declarations after your return statement Why would I do that? I'm not adamantly using `var` when I have no reason to. |
|
Code bases change and some things that a coder did not foresee needing to be reassignable may later need to be reassignable. There aren't frequent cases that switching them becomes a problem, and as a result, people switch them. Since they do get switched so often, people stop thinking about when it really matters or if there was some intent to it originally being written that way. If everything is a constant, then the cases where it matters and the cases where it doesn't get blended together and it's impossible to differentiate the two.
When real, true constants are the only things declared with const, then it's abundantly clear what the intention of the coder was and that the value should never be changed nor should it ever be switched over to let/var.
Likewise with let, in the few cases where it's used it draws others' attention to the use of block scoping or the avoidance of hoisting. It's rare that those things really come into play, so the few cases where it's present really stand out.
tl;dr Block scoping and constants are the exception, not the DEFAULT, so you should write code accordingly.
> If you're putting your variable declarations after your return statement
What I meant here is that people shouldn't keep using var just so they can continue writing bad code.