Always use const to declare variables. ???
See original GitHub issueShouldn’t it be something along these lines :
- Always use
let
to declare variables. Always useconst
to declare constantes or references. Avoid usingvar
. Not doing so will result in global variables… - Use one
const
orlet
declaration per variable.
Maybe the “references” and “variables” parts should be merged, linked or moved next to each other.
Issue Analytics
- State:
- Created 8 years ago
- Comments:20
Top Results From Across the Web
const - JavaScript - MDN Web Docs - Mozilla
The const declaration creates block-scoped constants, much like variables declared using the let keyword. The value of a constant can't be ...
Read more >Should every variable be const by default? | Belay the C++
I for one chose to use the const keyword every single time I declare a variable. I only remove it when I actually...
Read more >Why most of the time should I use const instead of let in ...
Because the const declaration creates a read-only reference to a value (cannot be reassigned). It prevents us to be confused with the value...
Read more >How the let, const, and var Keywords Work in JavaScript
You can use var , let , and const to declare global variables. But you shouldn't do it too often. let f_name =...
Read more >Why 'const' variables need to be your default choice in ...
In general terms, the process of deciding whether to use const or let passes through a simple question: “Does this variable change over...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know it’s an old thread but I am also wondering the same. Why use constant for everything? For me It’s not semantically correct. I tend to follow Kyle Simpson for it. In all the languages I have written programs, constant means a constant such as value of PI. I use const for only constants. I think we are forgetting the semantic aspect of programming. Just because const is available to us, which will stop us reassigning the variable, it doesn’t mean we should use const for everything. Maybe it’s good for lazy programmer but we are abusing it.
Here is what my typical JavaScript file looks like
const PI =3.4;
function some(){ var someVar = 36; // So I know that this variable is available in all inner scopes of function
if(doSome){ let innerScopevar = 56; //Now I know it’s only available in this scope. }
}
Nope! Everything should be
const
, because reassignment is something that should be avoided.