5 Modern JavaScript Features to Simplify Your Code

JavaScript evolves every year — but many devs still use it like it’s 2016. 🚀 Here are 5 underrated modern features that can simplify your code instantly: Optional chaining ?. Nullish coalescing ?? Array.at() Object.hasOwn() Intl for formatting 1️⃣ Optional Chaining (?.) 💡 Use Case: Access nested properties safely without breaking your code. const user = { profile: { name: 'Akhila' } }; console.log(user.profile?.name); // ✅ 'Akhila' console.log(user.address?.city); // ✅ undefined (no error) 🧠 No more Cannot read property 'x' of undefined errors. 2️⃣ Nullish Coalescing (??) 💡 Use Case: Provide fallback values only for null or undefined. const score = 0; console.log(score ?? 100); // ✅ 0 (unlike || which would return 100) ⚡ Keeps false, 0, and '' valid — great for numeric or boolean defaults. 3️⃣ Array.at() 💡 Use Case: Access elements from the end of an array more cleanly. const fruits = ['🍎', '🍌', '🍇']; console.log(fruits.at(-1)); // ✅ '🍇' (last element) 🍉 Replaces clunky fruits[fruits.length - 1] syntax. 4️⃣ Object.hasOwn() 💡 Use Case: Check if an object directly has a property (safer than hasOwnProperty). const obj = { name: 'JS' }; console.log(Object.hasOwn(obj, 'name')); // ✅ true 🛡️ Cleaner and avoids prototype pollution issues. 5️⃣ Intl (Internationalization API) 💡 Use Case: Format dates, numbers, and currencies globally. const price = new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR' }).format(9999.5); console.log(price); // ✅ ₹9,999.50 🌍 Perfect for apps with multi-language or multi-region users. ✨ Small features, big clarity. Which of these do you use the most (or plan to start using)? #JavaScript #WebDevelopment #CodingTips #Frontend #TechTrends

  • diagram, text

To view or add a comment, sign in

Explore content categories