← Back to list

5 JavaScript Tricks Every Developer Should Know in 2026

Practical tips that will make your code cleaner and faster

Er Anikettomar · 2026-06-25 14:39 · 0 claps · 1.4 min read
#javascript-tips #web-development #software-architecture #coding #best-practices
Open on Medium ↗
Wiki topics: 💻 · Programming 🌐 · Web Development 🏛️ · Architecture

5 JavaScript Tricks Every Developer Should Know in 2026

Practical tips that will make your code cleaner and faster

I have been writing JavaScript for a few years now, and I still discover new tricks that make me think — why did I not know this earlier? In this article, I am sharing 5 JavaScript techniques that genuinely changed how I write code.

1. Optional Chaining (?.) — Stop Writing Nested If-Else

Before optional chaining, accessing deeply nested object properties was a nightmare.

// Old way — messy
if (user && user.profile && user.profile.address) {
  console.log(user.profile.address.city);
}
// New way — clean!
console.log(user?.profile?.address?.city);

If any value in the chain is null or undefined, it simply returns undefined instead of throwing an error. This one trick alone cleaned up hundreds of lines in my codebase.

2. Nullish Coalescing (??) — Better Default Values

Most developers use || for default values, but it has a bug — it also replaces 0 and empty strings.

const score = userScore || 10; // Wrong! Replaces 0 with 10
const score = userScore ?? 10; // Correct! Only replaces null/undefined

3. Array Destructuring with Default Values

const [first = "Guest", second = "User"] = getUserData();
// Even if getUserData() returns [], you get defaults

This is incredibly useful when working with API responses that might return incomplete data.

4. Object.entries() for Clean Loops

const prices = { apple: 30, banana: 15, mango: 80 };
Object.entries(prices).forEach(([item, price]) => {
  console.log(`${item} costs ₹${price}`);
});

Much cleaner than using a for-in loop and avoids the common pitfall of iterating over prototype properties.

5. Promise.allSettled() — Handle Multiple API Calls Safely

const results = await Promise.allSettled([
  fetchUserData(),
  fetchPosts(),
  fetchComments()
]);
results.forEach(result => {
  if (result.status === "fulfilled") {
    console.log("Success:", result.value);
  } else {
    console.log("Failed:", result.reason);
  }
});

Unlike Promise.all(), this does not fail if one API call fails. Perfect for dashboards loading multiple data sources.

Final Thoughts

These are not just syntax tricks — they make your code more readable, safer, and easier to maintain. Try using at least one of these in your next project and see the difference.

If you found this helpful, follow me for more practical JavaScript and web development tips every week!


메타데이터
post_id
fc57557f136e
slug
5-javascript-tricks-every-developer-should-know-in-2026-fc57557f136e
url
https://medium.com/@aniket_singh/5-javascript-tricks-every-developer-should-know-in-2026-fc57557f136e
canonical_url
https://medium.com/@aniket_singh/5-javascript-tricks-every-developer-should-know-in-2026-fc57557f136e
author_url
https://medium.com/@aniket_singh
status
ok
fetched_at
2026-06-26 03:39:16