re: Is JavaScript truly a functional language? VIEW POST


I'd like to know what are these features that make a language truly functional?

I have never written haskell but I have been reading about functional programming for a while now. Here a the things I think javascript is not truly functional.

  • Functions are not pure by default.

The keyword function exists and we use that word to describe them but the blocks of code we write are more like procedures, that is just a group of instructions. "Pure functions" in javascript only exists by convention.

In haskell for example, one does not simply print something in the screen. A function in haskell can't change anything in the outside world (not without help). You actually have to make an effort to produce any kind of side effect.

  • Syntactic sugar for certain features

Things like partial application and function composition are second class citizens in javascript. There is support for them, you can make them yourself, but the language doesn't give a very special treatment to them.

  • Side effects

They're everywhere in javascript. The language was built for them. It's just the way it is. This isn't bad, it makes javascript fun to work with and very practical. Functional languages go to extreme lenghts to push those side effects to the "edge" of every program, or at the very least control them and make them predictable.

Code of Conduct Report abuse