The most common needless use of `let` I see: Setting an initial value,...


The most common needless use of `let` I see:

Setting an initial value, followed by mutations.

This is hard to read because it requires the reader to hold the initial value in their head while reading, and monitor any mutations along the way.

Solution: Call a function instead.

Note how the separate function is easier to reason about for multiple reasons:

-Groups related logic.
-No variables are declared or mutated.
-Delegates to child functions so each piece is clear.
-Returns early, so the reader doesn't have to hold state in their head as they read.

View original on X