Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript is functional but not in a strict sense. It does not rely on immutabl

ID: 647183 • Letter: J

Question

JavaScript is functional but not in a strict sense. It does not rely on immutable data and side-effect free functions. There are a few libs that provide immutable data structures, so I believe it should be possible to write a more strictly functional program using JavaScript.

I know ClojureScript exists but I am not interested in transcompilation.

Are there any open source projects that use JavaScript in a more strictly functional sense with nothing but immutable data? I am interested in whether this is practical in a language not built with this in mind.

Explanation / Answer

I wanted to expand a bit on what jozefg commented on above.
He's probably right that it would be slow, because JS compilers don't have support for immutability.
If you look at Erlang (language with built-in immutability), the compiler knows about immutability, so it can optimize for it. For example, i'f I'm not mistaken, immutable objects are not all complete clones from each other, but are stored internally as pointers to the original object together with any data that's different from the original data.
If you're going to try immutability all over the place in JS, you're going to have a massive amount of objects, which all are going to have to be garbage collected at some point...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote