Date Published: 13 February 2018
Prefer const Over let Or var
Use let For Loop Control Variables
Follow the first rule and use const wherever you can. But there are some cases where you can't, like when you're writing a loop. In that case, you should default to using let. Let is block scoped just like const, but can be re-assigned, as is required by looping constructs like for loops.
Wes Bos writes more on this topic, and links to some differing viewpoints.
Check out my podcast, Weekly Dev Tips, to hear a new developer productivity tip every week. You can also join my mailing list for similar (but different!) tips in your inbox every Wednesday!
Tags - Browse all tags
Category - Browse all categories
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.