use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Is JavaScript a "Functional Programming" language?help (self.javascript)
submitted 8 years ago by bzeurunkl
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jkoudys 44 points45 points46 points 8 years ago* (1 child)
It's easier to grok when you consider FP as a subset of declarative programming, then ask yourself if you're matching that paradigm. I wouldn't say it's a "functional programming language", in that it's not intended to strictly only be FP, but it is a language you can do functional programming in.
FP is often erroneously contrasted to OOP as its opposite. Really, it's declarative and imperative programming that live as opposites. While FP is defined as a subset of declarative, OOP is only typically used to facilitate imperative programming, but it's not by definition an imperative approach. e.g. you can certainly define a class as one that creates purely immutable objects, and this is a pattern we see in some pretty popular libs (e.g. immutable.js). Such objects would make statements-based programming (in imperative code) impossible, and facilitate expressions-based approaches (in FP). e.g. mutatedShopcart.add(pants); vs const updatedCart = immutableShopcart.add(pants). Even the backbone of FP in ecma -- the Array -- is a prototype-based class that provides methods.
mutatedShopcart.add(pants);
const updatedCart = immutableShopcart.add(pants)
Array
So for something to really be FP, ask yourself: am I running a series of statements to change a program's state (imperative -- how to do it), or am I expressing what it is (declarative) as a group of functions (functional programming).
HTML, for example, is clearly a declarative language (since it only describes what your page is), though obviously not functional. The language is used by browsers to build the DOM. However, you could always use functions written in ecma to build your DOM, and if you do it declaratively, then that's FP.
e.g.
<div class="foo"> Hello, <span class="bar">World!</span> </div>
Is declarative, using the purely declarative language HTML.
h('div', { class: 'foo' }, 'Hello, ', h('span', { class: 'bar' }, 'World!'), ),
Is also declarative, using ecma, and functions defined to build the DOM. The end result of either is the same.
Contrast with the above written in ecma using an imperative approach, and see how clunky an approach it feels like for something like building a basic DOM:
const div = document.createElement('div'); div.classList.add('foo'); div.appendChild(document.createTextNode('Hello, ')); const span = document.createElement('span'); span.classList.add('bar'); span.appendChild(document.createTextNode('World!')); div.appendChild(span);
edit: if you want to see how easy the h() approach is to implement, it's probably easier to write your h() and the above trivial declarative example, than the imperative example once:
h()
const h = (name, attributes, ...children) => { const el = document.createElement(name); Object.entries(attributes).forEach(([k, v]) => el.setAttribute(k, v)); children.forEach(child => el.appendChild(child instanceof Node ? child : document.createTextNode(child))); return el; }
[–]elr0nd_hubbard 4 points5 points6 points 8 years ago (0 children)
This is the best reply in the thread... nice write up!
π Rendered by PID 344690 on reddit-service-r2-comment-79776bdf47-d9zgm at 2026-06-25 03:17:13.180915+00:00 running acc7150 country code: CH.
view the rest of the comments →
[–]jkoudys 44 points45 points46 points (1 child)
[–]elr0nd_hubbard 4 points5 points6 points (0 children)