Programming•5 min read
Modern JavaScript Tips & Tricks Every Developer Needs
By Rajesh Patel•

JavaScript continues to power the web. As the ECMAScript standards release updates annually, JavaScript is becoming more concise, readable, and powerful.
Advertisement
Responsive Ad Banner
Slot: article-intro-ad
Here are some essential modern JavaScript tips and shorthand techniques that will help you write cleaner code.
1. Optional Chaining (?.)
Avoid throwing errors when accessing nested properties that might be null or undefined.
// Old Way
let streetName = user && user.address && user.address.street;
// Modern Way
let street = user?.address?.street;
Advertisement
Square Ad (300x250)
Slot: article-middle-ad
2. Nullish Coalescing Operator (??)
Use the nullish coalescing operator to assign a fallback value only when the left-hand operand is null or undefined, rather than falsy values like empty strings or zero.
// Falls back on empty string or 0 (might be invalid)
let count = response.count || 10;
// Only falls back if null/undefined
let correctCount = response.count ?? 10;
3. Object Destructuring with Renaming
Destruct properties from objects and rename them easily inside a single line.const user = { firstName: 'John', age: 30 };
const { firstName: name, age } = user;
console.log(name); // John
4. Array Unique Values using Set
The easiest way to remove duplicates from an array is to use theSet constructor along with the spread operator.
const duplicateArray = [1, 2, 2, 3, 4, 4, 5];
const uniqueArray = [...new Set(duplicateArray)];
console.log(uniqueArray); // [1, 2, 3, 4, 5]
5. Destructuring Method Parameters
Instead of passing an object and accessing its properties inside the function, destructure parameters directly in the signature.// Clean function signature
function printUserProfile({ name, age, email }) {
console.log(${name} is ${age} years old.);
}Advertisement
Leaderboard Ad (728x90)
Slot: article-end-ad
