JS Changes Fast; CLJS Makes It Manageable
I wrote my first JavaScript somewhere around 15 years ago and switched almost exclusively to ClojureScript several years ago. JavaScript as a language has changed so much that, if you drop me in any modern js codebase, it’s probably 50/50 that I could actually read it without referencing google.
JavaScript is constantly changing with new syntax, new data structures, new features, etc. And for the most part, using ClojureScript just lets me ignore the constant change and focus on solving problems.
Changes in JavaScript, Handled by ClojureScript
Pipeline operator
When the pipeline operator was first proposed, developers seemed very excited about it. I was confused at the excitement because it’s just the threader macro in ClojureScript.
Example from How to try the JavaScript Pipeline Operator Today
Optional Chaining Operator
The optional chaining operator cleans up all checks that your properties exist when navigating an object. In ClojureScript, we would use a map and just use get-in
. And if we have an object, we use Google Closure’s goog.object
.
Example from ESNext: JavaScript “Optional Chaining Operator”
Object Manipulation
There are plenty of new ways of defining, destructuring, and working with objects. Most of these are irrelevant to ClojureScript because we use maps instead of objects and have a powerful API to work with data. The new Object.entries
and Object.values
are just keys
and vals
when working with maps. JavaScript added destructuring and default values which are just part of ClojureScript’s core language.
Generators and Async/Await
I can see why JavaScript developers are excited about Generators and Async/Await, but I’ve yet to see anything that couldn’t be implemented with core.async. It wouldn’t surprise me if ClojureScript could use these internally for performance gains, but as a ClojureScript user it’s not a new feature that unlocks new value.
Regular Expressions
Regular expressions are one exception where ClojureScript developers need to keep up with JavaScript, because ClojureScript regular expressions compile to native JavaScript regular expressions. There are several proposals for new features with JavaScript regular expressions that will be visible in ClojureScript.
In general, ClojureScript makes it so that I just don’t think much about JavaScript as a language. ClojureScript deserves a lot of praise for the stability it provides given the frequent changes of the language it’s built on. For the last several years, ClojureScript developers have been free to spend time learning a consistent API without needing to track frequent language and syntax changes.