Skip to main content

Featured

🎉 Day 46 — React Mastery Completed (Final Summary & Congratulations!)

🎉 Day 46 — React Mastery Completed (Final Summary & Congratulations!) Congratulations, developer! 👏 You’ve successfully completed the 45-Day React.js Roadmap — from understanding the fundamentals to mastering advanced concepts like Redux, Routing, Testing, and Deployment. 📘 What You’ve Learned ✅ React basics — Components, JSX, Props, and State ✅ Hooks — useState, useEffect, useRef, useMemo, and Custom Hooks ✅ Context API and Redux Toolkit for global state management ✅ Routing with React Router & Protected Routes ✅ Data fetching using Fetch API, Axios, React Query ✅ Advanced Patterns — Compound Components, Render Props, HOCs ✅ Styling — CSS Modules, Styled Components, Theming ✅ Animations, Accessibility, Testing, and Performance Optimization ✅ Deployment on Vercel, Netlify, or GitHub Pages 🧩 Final Project Ideas Now that you’re done, build real-world apps to polish your skills: 📝 Task ...

⚠️ Day 50 – Error Handling in JavaScript

📘 Day 50: Error Handling in JavaScript

Every program is prone to errors — incorrect user input, failed API calls, or broken logic. JavaScript provides mechanisms to handle such exceptions gracefully instead of crashing the application.

🔹 What Is an Error?

An error is something unexpected that breaks normal execution. JavaScript has built-in Error objects to represent runtime issues.

try {
  console.log(x); // x is not defined
} catch (error) {
  console.log("Error caught:", error.message);
}

🔹 The try-catch-finally Block

This structure allows you to run code safely and handle problems:

try {
  let result = 10 / 0;
  console.log(result);
} catch (err) {
  console.log("Something went wrong:", err.message);
} finally {
  console.log("Execution completed.");
}

🔹 Throwing Custom Errors

You can create your own errors for specific conditions using the throw keyword.

function divide(a, b) {
  if (b === 0) {
    throw new Error("Division by zero not allowed!");
  }
  return a / b;
}

try {
  console.log(divide(5, 0));
} catch (e) {
  console.log("Caught:", e.message);
}

💡 Common Error Types

  • ReferenceError: Using a variable that doesn’t exist.
  • TypeError: Calling a non-function or invalid operation.
  • SyntaxError: Incorrect code syntax.
  • RangeError: Invalid numeric range (like infinite recursion).

Effective error handling makes your web apps more stable, reliable, and user-friendly.

Comments