Amina Bešlija
Amina Bešlija

Replacing let with const

In the above example, I have conditionally defined the height variable. It starts as let so that I may reassign it immediately to what I want it to constantly be. It’s value will be unchanging going forward, and I really wish I were able to define it as a constant to represent how I do not want future code to ever change it. There is always more than one way to solve a problem. In this case, you could use a really long ternary to define height as a const, but in some cases that might not be the best (or possible) solution. I want to propose a solution that is applicable to all uses of let, not just this one. This solution may not be the most optimal for every use case, but it is applicable to every use case, and it is extensible to any refactor. If you ever find yourself using let, you can use this pattern to replace your let with const.


Replacing let with const #javascriptba #javascript #nodejs #reactjs #angularjs #vuejs #meteorjs #typescript #jquery #emberjs #denojs #bosnia