JavaScript keeps evolving β here are some recent and upcoming features that caught my attention:
πΉ Array.prototype.toSorted() β Immutable sort
πΉ Object.hasOwn() β Safer hasOwnProperty
πΉ findLast() / findLastIndex() β Search from the end
πΉ Top-level await β No more wrapping in async
πΉ Promise.withResolvers() β Cleaner promise control
πΉ Record & Tuple (proposal) β Immutable data structures
**1. Array.prototype.toSorted()
**Non-mutating alternative to sort().
const numbers = [3, 1, 2];
const sorted = numbers.toSorted(); // [1, 2, 3]
console.log(numbers); // [3, 1, 2] β original array unchanged
Great for immutability and functional programming
**2. Object.hasOwn()
**Safer and clearer alternative to hasOwnProperty.
const user = { name: "Alex" };
Object.hasOwn(user, "name"); // true
Avoids prototype chain issues.
**3. Top-level await
**You can now use await outside of async functions in ES modules.
const data = await fetch("/api/data").then(res => res.json());
console.log(data);
Works only in modules (type="module" in HTML or .mjs files).
**4. Promise.withResolvers() (ES2024 Proposal)
**Cleaner way to create and control external promise resolution.
const { promise, resolve, reject } = Promise.withResolvers();
Very useful in custom async workflows.
**5. Array.prototype.findLast() and findLastIndex()
**Find from the end of an array.
[1, 2, 3, 4].findLast(x => x % 2 === 0); // 4
Efficient backward searching
Have you started using any of these? I'd love to hear your thoughts!
Top comments (0)