I Bet You’re Not Using These JavaScript Tricks (But You Should Be)

The 5 Power Tricks Every Developer Should Know But Rarely Use

Still using only .map() then you need to think again

You think you know JavaScript?
Same, until I found out these methods that made me go

“Whatttt, can we do this?, What was I doing till now??”
Being a fool till now :(

We all use .map(), .filter(), .reduce() like our daily chai (Without which we can’t survive, especially indians😂) But there are some of powerful JavaScript gems that can make you go faster, efficient and a whole lot smarter.
Let’s have a look at those.

1. Not Using Object.fromEntries() – Turn Arrays into Objects Instantly

Most developers use reduce() or manual loops when converting arrays to objects.

const entries = [['name', 'Neha'], ['role', 'Writer']];
const obj = Object.fromEntries(entries);

// Output: { name: 'Neha', role: 'Writer' }

Use it when:

  • You’re converting query params to an object
  • Mapping form data
  • Reversing an object using Object.entries()

2. Not Using flatMap() – Flatten While You Transform

Ever used .map() and then .flat() right after?

Just do this instead:

const numbers = [1, 2, 3];
const doubled = numbers.flatMap(num => [num, num * 2]);

// Output: [1, 2, 2, 4, 3, 6]

// With .map().flat()
numbers.map(el=>[el,el*2]).flat()

📌 Real use-case:

  • Flattening nested comments, tags, and related list
  • Especially in apps with dynamic UI elements.
Joey being smart 😂

3. Not using Optional Chaining ?. + Nullish Coalescing ??

Before:

if (user && user.profile && user.profile.name) {
console.log(user.profile.name);
}

After:

const name = user?.profile?.name ?? "Guest";
💡 ?. — avoids breaking your code if something is undefined
💡 ?? — assigns fallback only if value is null or undefined

Note — 🚫 Won’t trigger for false, 0, or '' (which is what you want!)

4. at()– Stop Doing arr[arr.length - 1]

Don’t be surprised if you didn’t know till now 😅.

const arr = [10, 20, 30];

console.log(arr.at(-1)); // 30
  • Works with positive and negative indexes
  • Cleaner than writing arr.length - 1
  • Doesn’t break if the array is empty
🧠 Use it to grab the last item without the mental load.

5. Destructuring + Renaming in One Smooth Move

This one’s a neat combo most developers underuse.

const user = { name: 'Neha', age: 27 };

const { name: userName } = user;

console.log(userName); // 'Neha'
  • Clean way to avoid naming collisions
  • Perfect when working with third-party APIs
  • Boosts readability in destructured props or params
Brilliant tricks!!

Final Thoughts: Little Tricks, Big Difference

These aren’t just fancy new tools.
They solve real problems and make your code more elegant, efficient, and future-proof.

I used to be that developer who thought:

“Why bother learning these? Everything works fine.”

But once you start exploring JavaScript beyond the basics, you realise how much smoother and cleaner your day can be.

Your Turn 👇

Which one of these surprised you the most? Do you have a favourite JavaScript trick I didn’t mention?

💬 Drop it in the comments — I’d love to feature your tip in Part 2.

Don’t be Shy, Just share your thoughts :)

Thank you for being a part of the community

Before you go: