• 2 min read • By Alex Johnson
Modern JavaScript: ES2023 Features You Should Know
Explore the latest JavaScript features and learn how to write cleaner, more efficient code with ES2023.
JavaScript ES2023 Programming Web Development
What’s New in ES2023?
JavaScript continues to evolve, and ES2023 brings exciting new features that make our code cleaner and more expressive.
Array Methods
Array.prototype.findLast() and findLastIndex()
Find elements from the end of an array:
const numbers = [1, 2, 3, 4, 5, 4, 3, 2, 1];
// Find the last even number
const lastEven = numbers.findLast(n => n % 2 === 0);
console.log(lastEven); // 2
// Find its index
const lastEvenIndex = numbers.findLastIndex(n => n % 2 === 0);
console.log(lastEvenIndex); // 7
Array.prototype.toSorted()
Create a sorted copy without mutating the original:
const numbers = [3, 1, 4, 1, 5];
const sorted = numbers.toSorted();
console.log(numbers); // [3, 1, 4, 1, 5] - unchanged
console.log(sorted); // [1, 1, 3, 4, 5]
Hashbang Grammar
Enable executable JavaScript files:
#!/usr/bin/env node
console.log('This file can be executed directly!');
Symbols as WeakMap Keys
Use symbols for privacy:
const privateData = new WeakMap();
const key = Symbol('private');
class User {
constructor(name) {
this.name = name;
privateData.set(key, { password: 'secret' });
}
}
Best Practices
Use Array Methods Wisely
Choose the right method for your use case:
// Find first match
const first = array.find(item => condition);
// Find last match
const last = array.findLast(item => condition);
// Transform array
const transformed = array.map(item => transform(item));
// Filter array
const filtered = array.filter(item => condition);
Immutable Operations
Prefer methods that don’t mutate:
// ❌ Mutates original
array.sort();
// ✅ Creates new array
const sorted = array.toSorted();
Conclusion
ES2023 continues JavaScript’s evolution toward more expressive and safer code. By adopting these new features, you can write code that’s both more readable and more maintainable. Stay curious and keep learning!