In the post-ECMAScript 6 era, you have probably hard-wired in your brain the concept of variables defined using let or const . Yet, after years have passed, you can still take advantage of these solid language features in a better way.

For example: have you ever clearly defined your default option between these two keywords when defining your variables?

You should genuinely care about this issue. Because thinking about it and improve can make your code straightforwardly more readable.

In general terms, the process of deciding whether to use const or let passes through a simple question: _“Does this variable change over time?”. _If the answer is “yes”, then let is the choice. Otherwise, you’re dealing with a constant, so const will do the trick.

Yet, when defining variables, you might think that this separation is not so relevant. After all, if you’re sure that you won’t modify this let variable why bother at all? But actually, const reveals itself to be the best default options for your variables for a very good reason.

Consider the following example:

Image for post

#programming #web-development #react #javascript

Why ‘const’ variables need to be your default choice in JavaScript
19.65 GEEK