DEV Community

Discussion on: 5 JavaScript "tips" that might bite you back.

Collapse
 
mrwensveen profile image
Matthijs Wensveen

A worthy article to read. Thanks!
My two cents:

  1. Why would you even create a 'sum' function when there is an operator that does just that? FP does not mean that you have to make functions for everything and your grandmother.
  2. Again, FP does not mean you have to make functions where expressions are readily available. The function actually hides that you're using spread, possibly surprising the callers of the function with unexpected results. They're better off using the appropriate method of concatenation where it is needed.
  3. Whoever says you can use bitwise operators to "round" is just plain lying. But it is an extremely fast way to cast your number to int (in other languages cast to int also truncates).
  4. I have to say I was surprised by this. Good tip!
  5. The main point to take away from this tip is that you don't have to use lambda's all over the place, which a lot of developers do, but that you can supply a function that takes the appropriate number of arguments. BTW, not every higher-order method takes 3 arguments, by definition. Just the ones on Array :)