Vinicius Spada Melo’s Post

📣 JavaScript More Predictable with .toSorted() and .toReversed() One of my favorite additions to JavaScript is .toSorted() and .toReversed() — they return a new array instead of mutating the original one. 🔍 Why this matters: Accidental mutations with sort() and reverse() have caused bugs in so many codebases — especially when dealing with shared or stateful data. ✅ No side effects ✅ Cleaner, more functional patterns ✅ Available in modern runtimes (Node.js 20+, modern browsers) 🧠 If you're still using .sort() and doing slice() to clone first — it’s time to upgrade. Have you started using .toSorted() or .toReversed() yet? #NodeJS #JavaScript #WebDevelopment #Tech #DesignPatterns #FrontendDevelopment #WebDevelopment #DeveloperLife #nodejs #backend #backenddeveloper #TypeScript #CodingTips #DeveloperBestPractices

  • text

The shift from mutating methods like `sort()` to non-mutating versions like `toSorted()` is a direct application of separating queries from commands.

This is excellent! Native array manipulation with immutable patterns means that we can more easily generate pure, declarative functions. Love it.

See more comments

To view or add a comment, sign in

Explore content categories