This is what I tell people when they argue against using const ("it's not really immutable"). When using const is the default, we naturally think in ways that result in better code.
Most functions have a structure like this:
letvar1;// ... do stuff to settle on the value for var1letvar2;// ... do stuff to settle on the value for var2// ... use var1 and var2 to produce the result.
When we are allowed to reassign, these "concerns" easily get intertwined and a clear separation is not visible. It also becomes harder to extract out meaningful function out for reuse.
With no reassignment the code looks more like:
constvar1=condition?value1:value2;constvar2=(()=>{// Do stuff to settle on a value of var2returnvalue2;})();
There is a clear separation of concern and it is easier to refactor.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is what I tell people when they argue against using
const
("it's not really immutable"). When usingconst
is the default, we naturally think in ways that result in better code.Most functions have a structure like this:
When we are allowed to reassign, these "concerns" easily get intertwined and a clear separation is not visible. It also becomes harder to extract out meaningful function out for reuse.
With no reassignment the code looks more like:
There is a clear separation of concern and it is easier to refactor.