Member-only story

Underused JavaScript Gems: Tips Every Fullstack Python Developer Should Know

Jenny Ouyang
5 min readOct 18, 2024

--

As a fullstack engineer, I spend the majority of my time writing backend code in Python. However, I also dive into JavaScript frequently when working on the frontend. Over time, I’ve discovered that while JavaScript is a powerful language, it hides some of its best tools under the hood. In this article, I’ll introduce you to some underused JavaScript gems that have not only made my code cleaner but also more efficient and readable. If you’re a Python developer like me, these tricks will help you write slicker JavaScript in no time.

If you don’t have medium subscription, you can still access the complete article via my friend link.

Let’s dive into some tips, with explanations, code examples, and even a bit of performance discussion where relevant!

1. Optional Chaining (?.)

What it is: Optional chaining is a great shortcut when it comes to accessing deeply nested object properties. It avoids errors like “Cannot read property ‘X’ of undefined” when accessing properties that might not exist.

Code Example:

const user = {
name: 'John',
address: {
city: 'New York',
}
};

console.log(user?.address?.city); // Output: "New York"
console.log(user?.contact?.phone); // Output: undefined (no error)

Time & Space Usage: Optional chaining doesn’t have significant performance overhead compared to traditional checks (&& operators), and it improves readability.

2. Nullish Coalescing (??)

What it is: This operator is similar to ||, but it only checks for null or undefined rather than all falsy values (like 0 or ""). This is perfect when you want to provide a default but still allow for falsy values like 0 or false.

Code Example:

const count = 0;
const defaultCount = count ?? 10;
console.log(defaultCount); // Output: 0

Time & Space Usage: It’s as efficient as || in terms of performance but adds the advantage of avoiding unwanted fallbacks for values like 0.

3. Destructuring with Defaults

--

--

Jenny Ouyang
Jenny Ouyang

Written by Jenny Ouyang

✨️ Programmer | Parent | PhD exploring the future of GenerativeAI. https://jennyouyang.substack.com/ Building products: https://findinfolder.online/

No responses yet

Write a response