DEV Community

Discussion on: Demystifying "const" variables in JavaScript

Collapse
 
cecilelebleu profile image
Cécile Lebleu

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!

Collapse
 
jckuhl profile image
Jonathan Kuhl

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.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

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