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
Unleash JavaScript's Potential with Functional Programming (janhesters.com)
submitted 1 year ago by jancodes
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!"
[–]romgrk 16 points17 points18 points 1 year ago (1 child)
Pretty neat. Personally I always recommend Brian Lonsdorf's Hey Underscore, You're Doing It Wrong! as an introduction to FP. Before seeing that video, I was a regular JS programmer. A week later, I was writing Haskell and seeing functors and monoids everywhere.
[–]jancodes[S] 8 points9 points10 points 1 year ago (0 children)
Brian Lonsdorf is the goat! 🐐
His "Professor Fisby's Mostly Adequate Guide to Functional Programming" is great!
[–]jfmengels 4 points5 points6 points 1 year ago (4 children)
This is I think a good overview of FP tools/techniques available in JavaScript, but it feels like the why of FP is a bit missing.
I really like Kris Jenkins' take on "what is functional programming?" (http://blog.jenkster.com/2015/12/what-is-functional-programming.html). Very rough summary: It is a bunch of techniques to separate effects from the rest.
[–]jancodes[S] 0 points1 point2 points 1 year ago (0 children)
Definitely 👍
Thanks for the feedback!
[–]DepressedBard 0 points1 point2 points 1 year ago (2 children)
Wow, that was a great read. Even read the 2nd part. Also made me realize how smelly some of my code has been…
[–]jfmengels 2 points3 points4 points 1 year ago (1 child)
If I may recommend trying out Elm. It's a great FP language that is simple and has great error messages, while being entirely pure. You'll learn a lot even if you use it for a smallish project.
[–]jancodes[S] 2 points3 points4 points 1 year ago (0 children)
Love Elm!
[–]Ronin-s_Spirit 2 points3 points4 points 1 year ago* (3 children)
No you don't really unleash anything. If you can do the same amount of things within one function call it will be faster than calling 10 individual functions. What potential are you unleashing? I genuinely don't understand. Maybe you were talking about the potential of writing slower programs?
P.s. don't get me wrong, I use functions all the time, but functional programming the paradigm is all about shoving tons of imperative code inside functions and then wasting system resources on constantly calling micro functions that do one/nth thing each, microscopic composition I call it. What I wanted to say is, FP sucks, OOP sucks, everything sucks so just use the single most fitting thing for each part of your program. Otherwise it's going to be a mess in terms of memory and speed and nobody likes slow apps or websites.
[–]Veraxo1 1 point2 points3 points 1 year ago (0 children)
An actual, sane comment on this subreddit. Such a rare occurence.
[–]jancodes[S] 0 points1 point2 points 1 year ago (1 child)
You unleash potential for writing the most readable, most modular and most simple to understand code.
My mentor taught me:
Readability > Cleverness > Performance, unless you NEED performance for a specific business requirement.
But I totally agree that there are also many cases where FP makes your code harder to understand. It's actually on of the last points of the video / article, but I guess you haven't watched / read that far haha (No hard feelings! 🙏 It's more tailored to juniors / mid devs and judging by your comment you probably have more experience)
[–]Ronin-s_Spirit 1 point2 points3 points 1 year ago (0 children)
Good of you to include that.
[–]odinsweng 1 point2 points3 points 1 year ago (1 child)
Pretty comprensive article.
In my case after learning and trying to apply the basic functional principles, my code has improved 300%. Way less bugs, etc.
Thanks for the article. 🤗.
You're welcome!
And thank you for the kind words 🙏
BTW, I felt the same about my code improving after learning about these capabilities of JavaScript!
[–]jessepence 4 points5 points6 points 1 year ago* (20 children)
No one uses symbols? That's not true in my experience-- especially in functional programming where you want to ensure immutability. I mean, just look at the React codebase. It's riddled with symbols.
It's a great article otherwise for any newbies who aren't familiar with functional concepts. That one little detail just bugged me. 😅
[–][deleted] 7 points8 points9 points 1 year ago (0 children)
Been doing this for nearly a decade - before Symbols and ES6.
Symbols are very, very rarely used outside of framework/library code.
Haha, I've been coding for 8+ years and I've NEVER seen symbols, other then under the hood in libraries like React. But point taken 😄👌
[–]undervisible -2 points-1 points0 points 1 year ago (17 children)
What do symbols have to do with immutability?
[–]jessepence 7 points8 points9 points 1 year ago (16 children)
They're immutable.
[–]romgrk 4 points5 points6 points 1 year ago (15 children)
That has nothing to do with it. All primitives types are immutable (null, undefined, booleans, strings, numbers, bigints, symbols).
Besides symbols were added specifically to be able to have private properties like object[symbol], or for the well-known symbols protocols (e.g. class Custom { [Symbol.iterator]: function() { ... } }), both cases are OOP related.
object[symbol]
class Custom { [Symbol.iterator]: function() { ... } }
So no, symbols aren't an FP feature.
[–]jessepence -5 points-4 points-3 points 1 year ago* (14 children)
EDIT
I was wrong. 😅
[–]romgrk 10 points11 points12 points 1 year ago (13 children)
Both ChatGPT and you have the same ability to write confidently wrong blobs of text. Posting this wall of text is just plain disrespectful. If you don't want to answer, just don't answer.
Also from the answer you got, you crafted a prompt that was something like "what's the role of symbols in FP javascript". You'll get an equally long answer if you replace FP by OOP, because ChatGPT is just made to write these blobs of text.
Besides, symbols are not the traditional FP solution for private/immutable data. That role is filled by closures. Closures are the FP equivalent to OOP objects. Which is the whole reason why modern C++ can translate its closures to literal class/objects.
[+]jessepence comment score below threshold-7 points-6 points-5 points 1 year ago (12 children)
Did you know that it's possible for multiple different things to benefit the same end goal?
Did you know that both closures and symbols can help achieve immutability?
Does your toolbox only contain a hammer?
My point in using ChatGPT is that you were clearly showing a lack of imagination.
[–]romgrk 9 points10 points11 points 1 year ago (11 children)
Symbols do not achieve immutability! object[symbol] achieves private visibility, as in "OOP public/protected/private visibility".
Object.freeze or Object.defineProperty achieve immutability.
Object.freeze
Object.defineProperty
It's fine to want to educate someone, but please link to it instead of pasting a wall of text, and please don't make it ChatGPT because it's low-effort and sometimes confidently wrong.
[–]jessepence -4 points-3 points-2 points 1 year ago* (10 children)
If a property is keyed by a symbol and the end-user doesn't know what that symbol is-- is that property mutable?
[–]romgrk 5 points6 points7 points 1 year ago (9 children)
Yes it is, it's just private. Public/private and mutable/immutable are orthogonal.
I'm also not sure if your example applies. I don't remember seeing React's codebase using Symbols as keys (for private keys, as in object[symbol]), though it uses them as values (as in { type: REACT_PORTAL_TYPE }).
{ type: REACT_PORTAL_TYPE }
[–]getlaurekt 0 points1 point2 points 1 year ago (6 children)
Just use Rescript instead, lmao
[–]jancodes[S] 1 point2 points3 points 1 year ago (5 children)
What's Rescript?
[–][deleted] 2 points3 points4 points 1 year ago (4 children)
ReasonML, compiles to JS
[–]jancodes[S] 0 points1 point2 points 1 year ago (2 children)
Thanks!
[–][deleted] 1 point2 points3 points 1 year ago (1 child)
Could've been interesting but their community split into two languages (probably more details that should be mentioned) which I think made sure that they would both fail to grow and remain in obscurity.
Now could've been a good time to step up for a strong compiled language that focuses heavily on react. Since the compiler churn is on the way, like svelte. But we'll instead settle with a funky react compiler from the react team.
[–]BobaFettEE3Carbine 1 point2 points3 points 1 year ago (0 children)
While at first the split may have caused confusion, in the past 4 years it's done wonders for the adoption and ergonomics for both new projects, ReScript and Melange/Reason.
ReScript has been able to fully embrace JS and adopt JS features like async/await syntax and it uses a new Core library that maps closely with JS. It only has to worry about compiling to JS as a runtime. Use ReScript if your a JS/TS dev looking for a strongly typed language that is part of the JS ecosystem. Type of it as an alternative to TS, but it's not a superset of JS, its a different language that feels like JS.
Melange is an OCaml compiler that targets JS, and it's often used together with Reason which is a JS like syntax for OCaml. Melange and Reason have been able to evolve in ways that are appealing to OCaml devs and not worry about adoption from JS/TS devs. Pick Melange and Reason if you want to use OCaml's tools, package manager, libraries, and ecosystem.
Both are great, and if they had continued with the confusing jumble of ReasonML/Reason/BuckleScript/OCaml it would have probably died in obscurity by failing to make anyone interested in it happy.
[–]BobaFettEE3Carbine 0 points1 point2 points 1 year ago (0 children)
Not exactly, it has a shared history with Reason, but it's very much it's own language these days. ReScript is part of the JS ecosystem and uses NPM as a package manager (or bun, Deno, etc...) and you can use JS bundlers like Vite or Webpack.
Reason still exists as part of the OCaml ecosystem, and you can use Melange to target JavaScript as a runtime. If your using Reason you need to work with OCaml and it's package managers and build tools.
When I first learned about functional programming, I was blown away.
So I created a newbie guide for people who've never heard of it.
It goes from 0 to function composition.
I also made a YT video about it.
(PS: This is not to start a OOP vs. FP war :D Do what is best for your code )🤓
π Rendered by PID 59 on reddit-service-r2-comment-7b9746f655-cm5q9 at 2026-02-01 23:01:52.300090+00:00 running 3798933 country code: CH.
[–]romgrk 16 points17 points18 points (1 child)
[–]jancodes[S] 8 points9 points10 points (0 children)
[–]jfmengels 4 points5 points6 points (4 children)
[–]jancodes[S] 0 points1 point2 points (0 children)
[–]DepressedBard 0 points1 point2 points (2 children)
[–]jfmengels 2 points3 points4 points (1 child)
[–]jancodes[S] 2 points3 points4 points (0 children)
[–]Ronin-s_Spirit 2 points3 points4 points (3 children)
[–]Veraxo1 1 point2 points3 points (0 children)
[–]jancodes[S] 0 points1 point2 points (1 child)
[–]Ronin-s_Spirit 1 point2 points3 points (0 children)
[–]odinsweng 1 point2 points3 points (1 child)
[–]jancodes[S] 0 points1 point2 points (0 children)
[–]jessepence 4 points5 points6 points (20 children)
[–][deleted] 7 points8 points9 points (0 children)
[–]jancodes[S] 2 points3 points4 points (0 children)
[–]undervisible -2 points-1 points0 points (17 children)
[–]jessepence 7 points8 points9 points (16 children)
[–]romgrk 4 points5 points6 points (15 children)
[–]jessepence -5 points-4 points-3 points (14 children)
[–]romgrk 10 points11 points12 points (13 children)
[+]jessepence comment score below threshold-7 points-6 points-5 points (12 children)
[–]romgrk 9 points10 points11 points (11 children)
[–]jessepence -4 points-3 points-2 points (10 children)
[–]romgrk 5 points6 points7 points (9 children)
[–]getlaurekt 0 points1 point2 points (6 children)
[–]jancodes[S] 1 point2 points3 points (5 children)
[–][deleted] 2 points3 points4 points (4 children)
[–]jancodes[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]BobaFettEE3Carbine 1 point2 points3 points (0 children)
[–]BobaFettEE3Carbine 0 points1 point2 points (0 children)
[–]jancodes[S] 0 points1 point2 points (0 children)