On your very first point, OH HELLS NO!!!

You really think that introducing the overhead of a function call for each and every loop, the dumbass cryptic arrow function TRASH, passing values around on the stack introducing memory thrashing, and an execution time roughly 25 time slower than the for loop is an improvement?

Array.foreach is utter garbage in most every usage case due to the reliance upon callbacks. Array.map has a purpose, and it's a good one, but it too can introduce overhead and code clarity issues.

Much less that if you have the derpy cryptic arrow function TRASH, you also have access to for/of? Don't introduce unnecessary function calls, you're just dragging performance down.

Your first loop also doesn't even do the same thing, you're outputting the index, not the value.

for (var i of numbers) console.log(i);

To blazes with .forEach, and use .map with great care. If you care about performance, neither of them are worth a flying purple fish.

... and don't even get me started about the mind-numbing derpitude of LET and CONST.. . crutches for people too stupid to be writing JS in the first place.

Nesting closures "bad" -- only if your formatting is trash. Wah wah, you mean I have to add whitespace. And your alternative is NOT an improvement... but again, derpy arrow function and map trash dragging performance and code clarity down.

Nested IF's I'm right there with you on, so long as there's no "else" you need to trap separately. Don't just assume you can always condense them."

Your final one wasting memory creating variables for nothing, much less the dumbass overhead required to implement CONST is not the answer. ESPECIALLY when you're running as many comparisons as the first example.

It's called whitespace, use it. Put each comparison on its own line, tabbed in, with the && at the end. Boom, instant code clarity. Crapping out more variables for nothing is not providing "clarity" or making it any better.

if (
person.name == "Indrek" &&
person.age == 26 &&
person.pets &&
person.pets.type === "cat"
) console.log("You're definitely Indrek");

Improves the code clarity, without changing the logic or wasting memory on extra variables — much less immutables — for NOTHING.

You're not improving code clarity, you're just making more bloat and more overhead. Remember, the less code you use, the less there is to break.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store