Just because functions are first class objects, there are closures, and higher order functions, does Javascript deserve to be called a Functional Programming language? The main thing I think it lacks is Pure Functions, and it doesn't 'feel' like other functional languages, like lisp (although thats not really a good reason for it not to be a functional langauge...)

@slashmais: No! That only prevents it from being a pure(ly) functional language. ML (at least modern dialects) are impure, too - but noone would dare to call them not functional ;)
– user395760Oct 18 '10 at 19:47

4

There are plenty of languages that are commonly considered functional, but which aren't pure. I don't see how that's a requirement. If you want to be that strict, then most so-called OOP languages aren't OOP either. You end up with about 95% of all languages being no-paradigm languages.
– jalfOct 18 '10 at 19:58

6

Why does it matter though? When I code in C++, I don't care if the language "is OOP" or not. I care that it has certain OOP features, and that it has a couple of functional programming features, and a lot of imperative programming features, and a lot of generic programming features. But whether it "is-a" OOP language or a FP language or something else doesn't matter. Likewise when I code in JS, it doesn't matter if it is FP or not. What matters is that it supports a lot of nice FP features. It seems this is the wrong question to ask.
– jalfOct 18 '10 at 20:06

3

@hvgotcodes: so? There's absolutely no rule saying it isn't. My rule of thumb is that it is a functional language if you can use it to program in a functional style. Since Javascript has first-class functions, closures and lambdas, I believe you can, and so as far as I'm concerned, it's a functional language. Not a pure one, obviously, but neither are most of the languages we typically consider FP (SML for example). So really, I think you just need to loosen up. If that makes your eye twitch, you need to see a doctor.
– jalfOct 19 '10 at 17:11

2

@jalf, absolutely. The motivation for the question was i wanted to know what my peers and people who are smarter than me think.
– hvgotcodesOct 19 '10 at 17:18

JavaScript has the notion of partials, and partially applying parameters, so I wonder if your statement that it does not support this is incorrect?
– johnbakersOct 14 '13 at 2:43

2

@OpenLearner, partial application is supported by pretty much every language I can think of, even C. For a certain definition of "support" anyway. The case with JS is no different. The point is whether partial application is effortless and first class in that language. In JS, it isn't. If you're curious about what I mean, take a look at OCaml or Haskell.
– missingfaktorOct 14 '13 at 7:28

yeah, I agree it's a mix and several different things.
– Ashley GrenonOct 18 '10 at 19:37

4

but that doesn't answer the question of whether it is also functional. Being multi-paradigm implies supporting multiple paradigms. Is one of these paradigms functional programming?
– jalfOct 18 '10 at 20:01

yes, maybe its ok to say 'it has some features, but not all'...
– hvgotcodesOct 18 '10 at 20:28

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.

design objective? What do you mean? Last I checked, one of its sources of inspiration was Scheme. I'd say it's pretty clear that one of its design objectives was to support functional programming as well as a bucketful of other paradigms
– jalfOct 18 '10 at 20:04

2

It supports functional programming as much as C++ does, if you write appropriate foundations for this by yourself - as much as you can emulate imperative syntax in, say, Haskell with a little work. Nevertheless the syntax of JavaScript leads to it being thought of a a work flow rather than the evaluation of a function. For that reason, I (or most functional programmers) regard applying the term "functional" as too extensive.
– shuhaloOct 18 '10 at 20:11

@user411768: so you're saying that whether or not a language is functional depends on the design of its standard library? I've never heard that definition before. Java has most of the tools needed to program in a functional style (closures and anonymous functions, for example), which C++ (currently) doesn't. I think that makes JS a lot more FP than C++ is. The fact that the language doesn't force you to program in a FP style doesn't make it "less functional", does it?
– jalfOct 19 '10 at 17:13

1

(i) The standard library is a part of the standard, just as the syntactical features are, and emphasizes a certain idiomatic and conceptual style. E.g. "C++ with STL" is very different from "C with classes". It has an impact. (ii) JavaScript features object orientation, first-class-citizen functions - the features are rather orthogonal to the imperativ/functional-dichotomy. However, neither does it directly implement currying, nor does it provide purity, nor has it ever been intended for this. (iii) My last words on that, see first paragraph of the post.
– shuhaloOct 19 '10 at 23:27

2

The statement that JavaScript and C++ offer the same functional programming conveniences is certainly wrong. JavaScript makes functional programming quite straightforward and simple without all of the messy constructs you must go through in C++ to achieve the same thing. There are plenty of great C++ coders who prominently say that functional programming is really not encouraged in C++, however articles on doing functional programming in JavaScript abound plentiful
– johnbakersOct 14 '13 at 2:47

Is there a source which uses "functional programming" to refer to languages with functions being first-order citizens?.
– shuhaloOct 18 '10 at 19:54

@user411768: Actually, another answerer linked to Wikipedia's article, which uses that definition. en.wikipedia.org/wiki/Javascript — Joel Spolsky also implied this definition in his "Can your programming language do this?" post on the benefits of "functional programming"
– ChuckOct 18 '10 at 20:05

You note that, as commonly written, JavaScript is not using your second point, but that certainly doesn't mean that there aren't programmers doing exactly that, and that the language doesn't support such a feature, because it certainly does
– johnbakersOct 14 '13 at 2:49

@OpenLearner: Well, yeah, but the same is true of Java and lots of other languages that are generally considered to be strictly imperative — you can write them in a functional style, but it's not the language's happy path.
– ChuckOct 14 '13 at 19:58

... but the latest JS would support it.
– Erik ReppenDec 11 '13 at 2:03

I don't think there a concrete definition of functional programming , however many of things people consider "functional programming" can be done with javascript. Here is a good brief example in this article.

To me, Javascript is both an imperative language and a functional language, and you can choose to use it either way, and even (egad) both ways. Or you can choose to use one paradigm and never touch the other. It's up to you. I, like you, don't think Javascript should be called a Functional Language, because it allows you to wander in and out of the functional programming paradigm. Perhaps if it had a pragma of some kind, to limit you using only functional programming paradigms, then that would be useful, I think. But, in summary, I say it's more of a imperative/procedural language with some functional programming features tossed in.

By that reasoning, F# can no long be called functional.
– Eric MickelsenOct 18 '10 at 19:45

1

Right. According to Wikipedia, F# is exactly what I just called Javascript: "F# [...] is a multi-paradigm programming language [...] that encompasses functional programming as well as imperative object-oriented programming disciplines"
– Brian OnnOct 18 '10 at 20:42

I tend not to think of programming languages as having one particular paradigm, but that they lend themselves to certain paradigms. However just because they lend themselves to a particular paradigm doesn't mean you have to use that paradigm. It's quite possible to write object oriented programs in C and write imperative programs in ML. Not using a certain paradigm to solve a problem because the language isn't designed for it is just artificially limiting yourself (of course you should still take into account the limitations of a language when deciding if a particular solution will be a good solution).

Javascript is to a point. It truly depends on how you go about programming it. If I code in an OO manner, would it not be OO? So if you just code things in a 'functional' manner it would be functional. I guess it is multi-paradigm language so to call it just one thing isn't entirely accurate.

As we know the functional programming language doesn't allow to change or mutate the elements(state)of functions but in javascript it is allowed in that sense it is not a functional programming language, although it does treat function as first class citizens.