
How I discovered my love for JavaScript after throwing 90% of it in the trash - haburka
https://hackernoon.com/how-i-rediscovered-my-love-for-javascript-after-throwing-90-of-it-in-the-trash-f1baed075d1b
======
igemnace
`const` doesn't mean immutable data. It means immutable variables, i.e. you
can't reassign to `const` variables. You can mutate the data regardless (push
to an array, add a new key to an object), unless the variable points to an
immutable value to begin with (primitives, or actual immutable data structures
such as with Immutable.js).

------
empthought
Replacing ifs with ternaries and switches with cond are hardly significant or
important changes.

The whole point of abstraction (functional or object-oriented) is to push that
logic from control structures in code to composition structures in runtime
data.

If you weren't replacing conditionals with polymorphism, you weren't doing
object-oriented programming in the first place.

------
satori99
> The for loop is now completely extinct in my codebase. If you do happen to
> stumble across one, point it out so I can kill it.

For loops in JS are _significantly_ faster than .forEach() or .map()

When performance matters (WebAudio, WebGL etc), you can't easily get rid of
for loops just yet.

~~~
fenomas
This isn't a concern unless you're tuning performance and the loop is a
bottleneck. forEach _can_ be slower (if the JS engine doesn't inline the
function body), but not to the extent that you need to structure your code
around it.

~~~
satori99
Yeah, I agree with that. Which is why I mentioned performance sensitive stuff
like WebGL.

Personally I use the functional methods whenever I can, but the original quote
I re-posted indicates that the author thinks that for-loops should always be
replaced with their functional equivalents, and I was just pointing out that
this is not universally a good idea yet.

~~~
fenomas
Yeah, I agree - just adding a caveat to your caveat.

Personally I found the whole article very skippable. None of it is necessarily
terrible advice, but everything is overstated, and said without really
explaining why its advice better than the alternatives.

------
kimi
Suggestion: throw the remaining 10% away as well and go for ClojureScript. You
are ready.

------
xkcd-sucks
Is it really okay to do recursion in JS?

