DEV Community

Olaf Minkowicz
Olaf Minkowicz

Posted on

The Misconception of Functional Programming in JavaScript

The term functional programming gets thrown about when developers talk about it in the context of JavaScript and it seems to a term that is very much understood by junior developers. This article is a breakdown of the term itself, how it’s used in JavaScript and how it’s being applied in popular frameworks such as React.

Functional programming, the term has been around since the 1930s and has its origins in lambda calculus. That specific term, “functional programming”, refers to a programming paradigm (classification of programming languages regarding their features and architecture) that refers to the consistent evaluation of mathematical computational models and functions that avoid changing state and mutable data.

Now while JavaScript can be classified as a functional programming language and has the capabilities to be written in that specific structure it supports multiple different programming paradigms and is classified under several. With the introduction of classes in ECMAScript 2015 more individuals start debating overusing object-oriented programming vs functional programming. Now while we have the syntactic sugar of classes it does NOT introduce any new object-oriented inheritance models to JavaScript. Classes are just a thin layer of paint on top of JavaScript’s prototype inheritance.

In React you can have functional components and class components. Before the introduction of React hooks, only class components had state and functional (stateless) components that could be classified as being written in a functional programming model. Now with hooks, you can use state in functional components and it’s up in the air if you could consider them written in a functional programming architecture now that state is being used in them. The whole point of the functional programming paradigm is avoiding changing state while evaluating functions, with the addition of hooks letting you change state it is void of that.

Top comments (0)