Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Javascript a Functional Programming Language?

People also ask

Is JavaScript OOP or functional?

What is JavaScript? JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well.

Why JavaScript is called functional programming language?

Those first-class functions are what makes functional programming possible in JavaScript. JavaScript is a multi-paradigm language that allows you to freely mix and match object-oriented, procedural, and functional paradigms. Recently there has been a growing trend toward functional programming.

Why JavaScript is not a functional language?

You can write functional programs in many object-oriented languages, such as JavaScript and Python, but these programs aren't truly functional since their constructs don't fully mesh with the framework and rules of functional programming.

Which programming language is functional?

Functional programming is based on mathematical functions. Some of the popular functional programming languages include: Lisp, Python, Erlang, Haskell, Clojure, etc. Pure Functional Languages − These types of functional languages support only the functional paradigms. For example − Haskell.


Repeating my own answer to a similar question,

There's no accepted definition of functional programming language.

If you define functional language as the language that supports first class functions and lambdas, then yes, JavaScript *is* a functional language.

If you also consider the factors like support for immutability, algebraic data types, pattern matching, partial application etc then no, JavaScript *is not* a functional language.


I'd encourage you to read the following related blog posts (and also the comments below them):

  • Scala is not a functional language

  • Erlang is not functional

  • Reddit discussion on "Erlang is not functional"


I would say that it is a multi-paradigm language.

EDIT: It's multi-paradigm and includes functional constructs.


if you stretch and twist the term "functional programming" to the point of philosophical discussions, this question may be open again. However, then you end up on the level of useful questions like "Is C++ really a programming language"?

The answer to your question on more daily level is "no".

Functional programming means that the program is conceptualized as a evaluation of a function, rather than a control flow. The code is a description of functions, and has no inherent concept of a control flow.

JavaScript has got a control flow and is conceptualized as a imperative language. From its design objective, it is clearly not a functional language.


The term "functional programming" language is so overloaded these days it's almost useless. There are two dominant meanings:

  1. Has first-class functions
    • Javascript is this!
  2. Is based on functions as used in the lambda calculus, with an emphasis on avoiding persistent mutable state (often replacing it with parameters passed to functions)
    • As commonly written, Javascript is not remotely this!

Pick your meaning and then the question is answerable.