JavaScript is a flexible language with first-class functions, so it supports a functional programming style. Usually people do this with a library such as Underscore.js, which provides array operations like “map” and “reduce” and function operations like “bind” and “compose”. This is very cool. For example, when you use “map”, you work at a higher level of abstraction. You don’t have to worry about a temporary index variable for iterating over the array, so the code becomes shorter and clearer.
However, this approach is not as functional as it could be. If you’re freely assigning values to variables, then you’re still relying on changing state. If your code is primarily a sequence of statements, it’s imperative or procedural, and you’re missing the peculiar beauty of functional code.
Your new post is loading...