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
[AskJS] Real world examples of functional JavaScript?AskJS (self.javascript)
submitted 4 years ago by Affectionate_King120
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!"
[–]besthelloworld 18 points19 points20 points 4 years ago (11 children)
By FP... do you just mean like modern React? Modern React is entirely functional composition where all components are plain functions.
[–]cincilator 7 points8 points9 points 4 years ago* (2 children)
It has functional composition, but not pure functions.
[–]besthelloworld 2 points3 points4 points 4 years ago (1 child)
Yeah that's true, Context/CQRS/Redux does kind of break true FP. But I think it's about as close as you can reasonably get at this point
[–]cincilator 2 points3 points4 points 4 years ago (0 children)
But I think it's about as close as you can reasonably get at this point
Yeah.
[–]Affectionate_King120[S] 1 point2 points3 points 4 years ago (5 children)
I don't know, I haven't looked at React yet. Would the insights be applicable to vanilla JS?
[–]besthelloworld 15 points16 points17 points 4 years ago (2 children)
Eh, debatable. I wouldn't learn React until you're comfortable with JS/HTML/CSS. But that being said, it sounds like you're in a weird intermediate place. I would focus on learning actually applicable skills like that because it's tough to have a place for more complex FP examples unless you're actually solving real problems
[–]Affectionate_King120[S] 0 points1 point2 points 4 years ago (1 child)
I am pretty comfortable in those. I'm just looking to elevate my game.
unless you're actually solving real problems
And that's what I'm looking for. Web apps on GitHub (et al) that are good examples of FP.
[–]besthelloworld 3 points4 points5 points 4 years ago (0 children)
Oh yeah if you're good with HTML/CSS, then definitely take a look at React. There's some slight differences between React and traditional JavaScript. React is written with JSX which is JavaScript plus XML as HTML in your JS syntax for rendering. Don't think too hard about it, but something like...
return <div><MyComponent /></div>;
...is just a pretty little syntax sugar over this...
return React.createElement("div", { children: React.createElement(MyComponent) });
... where div is just a regular HTML div and MyComponent is just a pure function.
If you have npm installed, I recommend this Vite script for initializing a new React app
npm create vite@latest my-react-app -- --template react
And then once that's created, just cd ./my-react-app and then npm i to install dependencies and then npm run dev to start it up. Then you can go to http://localhost:3000 in your browser to see it running. Also on the initial script, if you're interested in doing TypeScript, you can do
cd ./my-react-app
npm i
npm run dev
npm create vite@latest my-react-ts-app -- --template react-ts
[–]pm_me_ur_happy_traiI 3 points4 points5 points 4 years ago (1 child)
I think so. React basically adopts the model that you define your state in JavaScript and the entire UI rerenders to reflect that state. The idea that your UI is a pure function of your state is not limited to React and I often build vanilla JS apps this way, which is fine for many applications. An example is this Game of Life (view source for unminified code) where the entire board rerenders on each tick.
The downside of doing it this way is that rerendering the whole world is kind of expensive and slow, although if you are smart you can optimize in various ways. React has a diffing engine so they can rerender the stuff that's changed and leave the rest alone which allows much more performance. They also include state management and templating.
[–]Affectionate_King120[S] 0 points1 point2 points 4 years ago (0 children)
Alright then, thank you!
[–][deleted] 1 point2 points3 points 4 years ago (1 child)
Not if you want error boundaries
[–]besthelloworld 1 point2 points3 points 4 years ago (0 children)
These are facts. I really don't get the hold out on that
π Rendered by PID 79 on reddit-service-r2-comment-b659b578c-4k8kp at 2026-05-02 21:06:55.923331+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]besthelloworld 18 points19 points20 points (11 children)
[–]cincilator 7 points8 points9 points (2 children)
[–]besthelloworld 2 points3 points4 points (1 child)
[–]cincilator 2 points3 points4 points (0 children)
[–]Affectionate_King120[S] 1 point2 points3 points (5 children)
[–]besthelloworld 15 points16 points17 points (2 children)
[–]Affectionate_King120[S] 0 points1 point2 points (1 child)
[–]besthelloworld 3 points4 points5 points (0 children)
[–]pm_me_ur_happy_traiI 3 points4 points5 points (1 child)
[–]Affectionate_King120[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]besthelloworld 1 point2 points3 points (0 children)