JavaScript is a dynamic and versatile language that surprises even experienced developers with its quirks and hidden gems. In this post, I’ll walk you through some unique and lesser-known JavaScript concepts that can level up your understanding of the language. Whether you're a beginner or an experienced dev, there’s something for everyone here!
Destructuring with Default Values
Destructuring is a handy way to extract values from arrays or objects, but did you know you can assign default values to avoid undefined?
const person = { name: "John", age: 30 };
// Extracting with defaults
const { name, age, gender = "Unknown" } = person;
console.log(gender); // Output: "Unknown"
Why It’s Useful:
When working with APIs or partial data, you can ensure your variables always have meaningful defaults.
Top comments (0)