question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Always use const to declare variables. ???

See original GitHub issue

Shouldn’t it be something along these lines :

  • Always use let to declare variables. Always use const to declare constantes or references. Avoid using var. Not doing so will result in global variables…
  • Use one const or let declaration per variable.

Maybe the “references” and “variables” parts should be merged, linked or moved next to each other.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20

github_iconTop GitHub Comments

7reactions
Mujaddadicommented, Dec 18, 2017

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. }

}

7reactions
ljharbcommented, Feb 10, 2016

Nope! Everything should be const, because reassignment is something that should be avoided.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found