loading...

re: Is JavaScript truly a functional language? VIEW POST

FULL DISCUSSION
 

I think the functional vs non-functional is kind of a spectrum, rather than a binary thing.

There are some features of programming languages that are considered "functional": higher order functions, immutable data structures, recursion + tail call optimization
There are some features that are considered "non-functional", like functions with side effects, mutable data structures etc.

Some languages implement most of the functional features and few non-functional, for example Haskell is a strongly functional language, it does not allow you to mutate state, and side effects are done via monads

On the other side we have languages like C, which are strongly imperative: there are no built-in immutable data structures, higher order function are possible, functions are not first-class citizens (you can't pass a function as an argument, although you can pass a pointer to the function).

So now after this long introduction, the question is where to put JavaScript on this spectrum?
JS has some built-in functional features: high order functions, first-class functions, anonymous functions, etc. At the same time, the built-in data structures like objects and arrays are mutable and you can write imperative code in JS. Therefore I would say that JavaScript allows you to write functional code, but it does not force you to do that (so I would put it closer to "imperative/OO" than "functional" on the spectrum)

Code of Conduct Report abuse