Most JavaScript bugs aren’t big, complex problems. They’re small — and often hide in places you don’t expect. Like trying to access a nested property that doesn’t exist… And suddenly your app crashes with: "Cannot read properties of undefined" This is where one small operator makes a big difference: Optional Chaining (?.) Instead of writing: user.company.address.city Write: user.company?.address?.city Now if any part of the chain is missing, your app won’t crash — it simply returns undefined. #JavaScript #TypeScript #ReactJS #CodingTips #SoftwareEngineering
Prevent App Crashes with Optional Chaining in JavaScript
More Relevant Posts
-
🚨 𝗧𝗵𝗶𝘀 𝘀𝗺𝗮𝗹𝗹 ! 𝗶𝗻 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁 𝗰𝗮𝗻 𝗰𝗿𝗮𝘀𝗵 𝘆𝗼𝘂𝗿 𝗲𝗻𝘁𝗶𝗿𝗲 𝗮𝗽𝗽. 𝗬𝗲𝘀… 𝘀𝗲𝗿𝗶𝗼𝘂𝘀𝗹𝘆. I once saw code like this: user!.name At first glance, it looks harmless. But this one symbol can silently introduce runtime bugs if you don’t understand it. 💡 𝗦𝗼 𝘄𝗵𝗮𝘁 𝗱𝗼𝗲𝘀 ! 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗱𝗼? It’s called the 𝗡𝗼𝗻-𝗡𝘂𝗹𝗹 𝗔𝘀𝘀𝗲𝗿𝘁𝗶𝗼𝗻 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿 👉 It tells TypeScript: “Trust me, this value is NOT null or undefined.” 🔍 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: const name: string | undefined = undefined; name!.toUpperCase(); 💥 𝗕𝗼𝗼𝗺. 𝗖𝗿𝗮𝘀𝗵. 👉 TypeScript stays quiet 👉 JavaScript throws the error Because YOU told TypeScript: “Trust me” …and it did 😅 🧠 𝗧𝗵𝗲 𝗿𝗲𝗮𝗹 𝗽𝗿𝗼𝗯𝗹𝗲𝗺? ! doesn’t make your code safe It just 𝗵𝗶𝗱𝗲𝘀 𝘁𝗵𝗲 𝘄𝗮𝗿𝗻𝗶𝗻𝗴 🔥 𝗕𝗲𝘁𝘁𝗲𝗿 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵: if (name) { name.toUpperCase(); } ✔ Safe ✔ Predictable ✔ No surprises 👉 If you’re using !, ask yourself: “Am I 100% sure this will never be null?” If not… don’t use it. 💬 𝗛𝗮𝘃𝗲 𝘆𝗼𝘂 𝗲𝘃𝗲𝗿 𝗳𝗮𝗰𝗲𝗱 𝗮 𝗯𝘂𝗴 𝗯𝗲𝗰𝗮𝘂𝘀𝗲 𝗼𝗳 !? #TypeScript #ReactJS #Frontend #WebDevelopment #JavaScript #CodingTips #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Most people think slow apps = slow internet ❌ But today I learned something deeper 👇 A React app is not just “download and show UI” The browser actually does 3 heavy things: 📥 Download JavaScript 🧠 Parse (understand) it ⚙️ Execute (run) it 👉 Even UNUSED code still gets parsed 👉 Some of it even executes 💥 That means: Big bundle = more browser work = slower app So performance is not just about: 👉 reducing size It is about: 👉 reducing unnecessary JavaScript work That’s where things like: ⚡ Code Splitting 💤 Lazy Loading 🌳 Tree Shaking actually matter 💡 Biggest mindset shift: “Don’t send everything. Send only what the user needs right now.” Learning in public 🚀 #frontend #react #webperformance #javascript #softwareengineering
To view or add a comment, sign in
-
🚀 Built a React App Using useReducer ⚛️ I recently built a "React Quiz" app to strengthen my understanding of state management in React. 🧠 Key learnings: Managing complex state with useReducer Handling async data (loading questions from a mock API) Managing loading, error, and ready states ⚡ Answer selection & smooth navigation between questions Tracking progress 📊 Completing & restarting the quiz 🔁 Implementing a countdown timer using useEffect ⏱️ 💡 This project helped me understand when to use useReducer over useState for more structured and scalable state logic. 🔗 GitHub Repo: https://lnkd.in/g8VeyXhi Feedback is welcome 🙌 #React #JavaScript #FrontendDevelopment #WebDevelopment #ReactJS #LearningByBuilding
To view or add a comment, sign in
-
I used to think I understood React… until I had to pass the same state through 3–4 components just to control one small thing 😅 It worked, but it didn’t feel right. So instead of jumping to another tutorial, I tried to actually "understand the problem" and that led me to the Context API. To keep things simple, I built a tiny “bulb toggle” app 💡 At first, everything was prop-based. Then I switched to Context… and the difference was obvious. Now: 1. I’m not passing props through unnecessary layers 2. Components feel more independent 3. The code is easier to read and reason about But I also learned something important while doing this: 👉 Context is helpful, but it’s not a replacement for everything If the state is simple and only needed in a few places, props are still totally fine. Context starts to make sense when multiple parts of your app need the same data. Still early in my journey, but this was one of those small moments where things started to click. If you’ve worked with Context before -> 👉 how do you decide between props, Context, or other state tools? #learninginpublic #reactjs #webdevelopment #javascript #frontenddevelopment
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟯 𝗼𝗳 𝗠𝘆 𝗥𝗲𝗮𝗰𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 ⚛️🚀 Today I learned about 𝗥𝗲𝗮𝗰𝘁 𝗛𝗼𝗼𝗸𝘀, especially the 𝘂𝘀𝗲𝗦𝘁𝗮𝘁𝗲 𝗵𝗼𝗼𝗸 — and this finally made React feel more practical. Before this, I was thinking about how we usually update the UI manually in JavaScript — selecting elements, changing text, updating the DOM step by step. It works, but it can get messy and hard to manage as the app grows. With `𝘂𝘀𝗲𝗦𝘁𝗮𝘁𝗲`, React handles that for us. We just update the 𝘀𝘁𝗮𝘁𝗲, and React automatically updates the UI. No need to manually touch the DOM every time. That shift in thinking was really interesting — instead of telling the browser 𝗵𝗼𝘄 to update, we just tell React 𝘄𝗵𝗮𝘁 the state should be. Starting to see why React is so powerful for building dynamic apps 💻⚡ #ReactJS #JavaScript #WebDevelopment #LearningJourney #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 I improved my Next.js app performance without adding any new library… Most developers think performance = install more packages. I used to think the same. But recently, while working on a production project, I focused on fixing fundamentals instead of adding complexity 👇 ✅ Reduced unnecessary re-renders ✅ Optimized API calls (no duplicate fetching) ✅ Used proper dynamic imports in Next.js ✅ Cleaned up unused components & heavy logic 📉 Result? - Faster page load - Better Lighthouse score - Smoother user experience 💡 Biggest lesson: Performance is not about tools — it's about understanding your code deeply. Sometimes, the best optimization is removing things, not adding. Curious — what’s one performance mistake you’ve seen developers make often? #reactjs #nextjs #webdevelopment #frontend #performance #javascript
To view or add a comment, sign in
-
I noticed something small… that actually breaks user experience. Open the same app in two tabs. Change the language in one tab. The other tab stays the same. Now the user sees two different languages at the same time. That’s confusing. This happened in my React app. The feature worked perfectly… but only in a single tab. The problem wasn’t the backend. It was that tabs don’t share state by default. So I fixed it using the BroadcastChannel API. It lets tabs communicate with each other in real time. Now the flow is simple. • Change language in one tab • Send a message using BroadcastChannel • All other tabs receive it instantly • UI updates everywhere No refresh. No extra API calls. Everything stays in sync. For more advanced setups, this can also be combined with: • localStorage (for better browser support) • Service Workers (for more control) Final thought. Sometimes the issue isn’t the feature… It’s how it behaves in real-world usage. Would love to hear how others are solving multi-tab state problems. #React #JavaScript #Frontend #WebDevelopment #SoftwareEngineering #WebDev #FrontendDevelopment #Programming #Developers #Coding #BuildInPublic #DevCommunity #Tech #SoftwareDeveloper #ReactJS #JS #WebApps
To view or add a comment, sign in
-
-
💥 Most developers assume using useMemo and useCallback everywhere will automatically make a React app faster. Sounds logical: Memoize more → fewer re-renders → better performance. But in real-world apps, it often doesn’t work like that. I’ve seen this pattern quite often — developers start adding these hooks with good intent, but without actually measuring anything. • Wrapping functions with useCallback • Memoizing even simple values • Adding optimizations “just in case” And then… 🚨 No real performance improvement 🚨 Code becomes harder to read and maintain 🚨 Debugging gets more complicated 🚨 Sometimes performance even degrades 🧠 The important part: useMemo and useCallback are not free. They introduce overhead — memory usage, dependency comparisons, and extra complexity. ⚡ What actually works better: • Understanding why components re-render • Improving state structure • Splitting components smartly • Measuring performance using React DevTools 🔥 My take: React is already quite fast. Blindly adding memoization often creates more problems than it solves. 💡 Rule I follow: If I haven’t measured a real performance issue, I don’t reach for useMemo or useCallback. Curious — do you think these hooks are overused in most React apps? 🤔 #ReactJS #FrontendDevelopment #WebPerformance #JavaScript #SoftwareEngineering #ReactPerformance
To view or add a comment, sign in
-
-
🗂️ Does your app load 10,000 items at once? That's a performance disaster waiting to happen. Learn how pagination works, why it matters, and build a real React component from scratch — step by step. 🚀 Full guide is live on hamidrazadev.com — link in bio! #webdev #reactjs #javascript #frontenddevelopment #programminglife #developerlife #hamidrazadev
To view or add a comment, sign in
-
-
🧠 Most React apps scale fine at the start, Until state becomes messy, unpredictable, and hard to manage. 👉 Read the full guide 🔗 📌 What you’ll learn: https://shorturl.at/jtKRp ➥ Why poor state design is the biggest bottleneck in scaling React apps ➥ How to separate UI state vs server state effectively ➥ When to use local state, context or state libraries ➥ Patterns to avoid prop drilling and unnecessary re-renders ➥ Practical strategies to build clean, scalable state systems ✨✍ Written by: Harsh Chauhan #ReactJS #StateManagement #FrontendArchitecture #WebDevelopment #JavaScript #ScalableSystems #Engineering
To view or add a comment, sign in
-
More from this author
-
Android's 16KB Page Size Update — Why It Happened… And Why Developers Struggled
Muhammad Awais 1mo -
React Native Performance & State Management — Issues We All Face (And How to Fix Them)
Muhammad Awais 1mo -
Most React Native apps are slow — not because of React Native itself, but because of avoidable mistakes.
Muhammad Awais 1mo
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development