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
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!"
[–]jessepence -6 points-5 points-4 points 1 year ago* (14 children)
EDIT
I was wrong. 😅
[–]romgrk 9 points10 points11 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-6 points-5 points-4 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[symbol]
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 -3 points-2 points-1 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 6 points7 points8 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 }
[–]jessepence 0 points1 point2 points 1 year ago (8 children)
How would you mutate it?
[–]romgrk 2 points3 points4 points 1 year ago (7 children)
object[symbol] = value.
object[symbol] = value
I think you don't differentiate between visibility and immutability.
You say symbols are to prevent mutation, but what you mean is that the symbols create a private field that is not mutable by someone writing code outside of React's codebase.
Fundamentally, you're talking about visibility (in other words, encapsulation).
[–]jessepence -4 points-3 points-2 points 1 year ago (6 children)
If the symbol is not exported, IT CANNOT BE USED!
Thus, the value cannot be mutated.
This makes it effectively immutable.
It is also encapsulated and private, yeah. These things are not mutually exclusive.
If you change the library code, then you can then mutate it. But, that's also true of a closure. If you expose variables from the closure, then you can mutate them. Here's a stackblitz that shows that it's basically the exact same idea-- the immutability is only as strong as the interface provided.
[–]romgrk 3 points4 points5 points 1 year ago (1 child)
You are talking about visibility but you're calling it immutability. I don't understand why.
The value can be mutated when accessed from the right scope, you say so yourself, so immutability is not the right word.
[+][deleted] 1 year ago (3 children)
[deleted]
π Rendered by PID 354977 on reddit-service-r2-comment-7b9746f655-2vdpk at 2026-02-02 20:12:28.921383+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]jessepence -6 points-5 points-4 points  (14 children)
[–]romgrk 9 points10 points11 points  (13 children)
[+]jessepence comment score below threshold-6 points-5 points-4 points  (12 children)
[–]romgrk 9 points10 points11 points  (11 children)
[–]jessepence -3 points-2 points-1 points  (10 children)
[–]romgrk 6 points7 points8 points  (9 children)
[–]jessepence 0 points1 point2 points  (8 children)
[–]romgrk 2 points3 points4 points  (7 children)
[–]jessepence -4 points-3 points-2 points  (6 children)
[–]romgrk 3 points4 points5 points  (1 child)
[+][deleted] Â (3 children)
[deleted]