loading...

re: Demystifying "const" variables in JavaScript VIEW POST

FULL DISCUSSION
 

As a common rule, I suggest using const to declare all new variables, and when you come across a point where you need to reassign one of those variables, then change it to a let.

Great explanation! I will definitely be trying this, as I have always been confused about const and when to use it. But looking at it “upside down” is a great approach. Thanks!

 

It's always been my rule of thumb.

Use const. If you need to reassign it, change the variable to let. No reason to use var anymore.

 

One reason to use var: prototype something in the browser console and get something wrong, for that session your const won't be changeable, so use var for fast prototyping

code of conduct - report abuse