<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mahdi Hosseini</title>
    <description>The latest articles on DEV Community by Mahdi Hosseini (@madifrontend).</description>
    <link>https://dev.to/madifrontend</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F882916%2F8e3bd63c-7514-4c6d-a22c-1fde3ae87809.jpeg</url>
      <title>DEV Community: Mahdi Hosseini</title>
      <link>https://dev.to/madifrontend</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madifrontend"/>
    <language>en</language>
    <item>
      <title>Tailwind CSS 4 vs. CSS Modules: Which Wins for Scalable Projects?</title>
      <dc:creator>Mahdi Hosseini</dc:creator>
      <pubDate>Wed, 03 Sep 2025 18:14:18 +0000</pubDate>
      <link>https://dev.to/madifrontend/tailwind-css-4-vs-css-modules-which-wins-for-scalable-projects-216a</link>
      <guid>https://dev.to/madifrontend/tailwind-css-4-vs-css-modules-which-wins-for-scalable-projects-216a</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9v5wrg26gkojq7n2sx9k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9v5wrg26gkojq7n2sx9k.jpg" alt=" " width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS 4 vs. CSS Modules:
&lt;/h2&gt;

&lt;p&gt;Which Wins for Scalable Projects?&lt;br&gt;
As web development evolves, choosing the right styling approach for your projects becomes increasingly critical. With the release of Tailwind CSS 4 in 2025, the debate between utility-first frameworks and traditional CSS methodologies like CSS Modules has reignited. Both tools offer unique strengths, especially when it comes to building scalable applications. But which one should you pick for your next big project? Let’s dive into a detailed comparison of Tailwind CSS 4 and CSS Modules, exploring their architecture, performance, maintainability, and suitability for large-scale development.&lt;/p&gt;

&lt;p&gt;The Foundations: What Are We Comparing?&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS 4: A Utility-First Evolution
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS has long been celebrated for its utility-first approach, allowing developers to style directly in their markup with pre-defined classes like bg-blue-500 or p-4. The latest iteration, Tailwind CSS 4, brings significant improvements over its predecessors, including a CSS-first configuration, faster build times (up to 5x for full builds and 100x for incremental builds), and enhanced support for modern CSS features like container queries and 3D transforms. It’s designed to streamline development while maintaining flexibility through a customizable tailwind.config.css file.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Modules: Scoped Styling Done Right
&lt;/h2&gt;

&lt;p&gt;CSS Modules, on the other hand, take a more traditional route by enabling locally scoped CSS. Introduced as a way to avoid global namespace collisions, CSS Modules process your CSS files at build time (e.g., with Webpack or Vite) to generate unique class names. This approach keeps styles encapsulated within components, making it a favorite for developers who prefer writing vanilla CSS with a modern twist.&lt;br&gt;
Performance: Build Times and Bundle Size&lt;br&gt;
Scalability often hinges on performance, and both tools handle this differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS 4:&lt;/strong&gt; With its Just-In-Time (JIT) compilation and purging capabilities, Tailwind 4 generates only the CSS you use, resulting in remarkably small production bundles (often under 10kB). The new engine optimizes build times, making it ideal for large projects where rapid iteration is key. However, during development, the initial setup can still feel heavy if not properly configured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS Modules:&lt;/strong&gt; CSS Modules don’t inherently optimize bundle size unless paired with tools like PurgeCSS. Since each module is processed separately, projects with many components can lead to larger CSS files if unused styles aren’t removed. Build times are generally faster for small projects but can scale poorly as the number of modules grows.&lt;/p&gt;

&lt;p&gt;Verdict: Tailwind 4 edges out in performance for scalable projects due to its built-in optimization and faster incremental builds, provided you configure purging correctly.&lt;br&gt;
Maintainability: Consistency vs. Control&lt;br&gt;
Maintaining a large codebase is where the rubber meets the road.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS 4:&lt;/strong&gt; The utility-first paradigm enforces a consistent design system through predefined scales for colors, spacing, and typography. This reduces the risk of style drift across teams. However, verbose HTML with long class lists (e.g., flex justify-center items-center p-4 bg-gray-100) can become hard to read, especially for complex components. &lt;br&gt;
The learning curve for new developers and the need for strict coding standards can also pose challenges.&lt;br&gt;
CSS Modules: With locally scoped styles, CSS Modules offer granular control and encourage modular design. You can write semantic CSS (e.g., .card-title { font-size: 1.5rem; }) that’s easier to trace and refactor. However, managing global styles or reusing utilities across components requires additional effort, such as creating a shared CSS file or using CSS custom properties.&lt;/p&gt;

&lt;p&gt;Example: Imagine a reusable button component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"&amp;gt;
  Click Me
&amp;lt;/button&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS Modules (with styles.module.css):
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styles from './styles.module.css';
&amp;lt;button className={styles.button}&amp;gt;Click Me&amp;lt;/button&amp;gt;
css.button {
  background-color: #3b82f6;
  color: white;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
}
.button:hover {
  background-color: #1d4ed8;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verdict: CSS Modules win for maintainability in projects requiring custom, semantic styles, while Tailwind 4 shines for enforcing consistency with less CSS overhead.&lt;br&gt;
Scalability: Handling Growth&lt;br&gt;
As projects scale, the ability to adapt to new features and team sizes becomes crucial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS 4:&lt;/strong&gt; Its configuration file allows you to define a design system upfront, which scales well with growing teams. Container queries and responsive utilities make it adaptable to complex layouts. However, refactoring a Tailwind-heavy codebase (e.g., updating a color scheme) can be tedious, requiring changes across numerous class references.&lt;br&gt;
CSS Modules: The modular nature scales naturally with component-based architectures like React or Vue. Adding new components with isolated styles is seamless, but managing a growing number of modules can lead to redundancy unless a strict naming convention (e.g., BEM) is enforced.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-World Consideration:&lt;/strong&gt; In a project with 50+ components, Tailwind’s purging keeps the CSS lean, while CSS Modules might require manual optimization to avoid bloat.&lt;br&gt;
Developer Experience: Productivity and Learning Curve&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS 4:&lt;/strong&gt; The utility-first approach accelerates prototyping and reduces context-switching between files. IntelliSense in modern IDEs (e.g., VS Code) enhances productivity. However, the initial learning curve can be steep for developers accustomed to traditional CSS.&lt;br&gt;
CSS Modules: Familiar to developers with a CSS background, CSS Modules offer a gentler learning curve. Modern tools provide autocompletion and error checking, but the need to manage imports and scope can slow down rapid development.&lt;/p&gt;

&lt;p&gt;Verdict: Tailwind 4 boosts productivity for experienced teams, while CSS Modules are more accessible for beginners or teams with diverse skill levels.&lt;br&gt;
When to Choose What?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose Tailwind CSS 4 if:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You prioritize rapid development and consistent design.&lt;br&gt;
Your team is comfortable with utility classes and can enforce coding standards.&lt;br&gt;
Performance and small bundle sizes are critical for your scalable app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose CSS Modules if:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need fine-grained control over custom designs and animations.&lt;br&gt;
Your project involves complex theming or dynamic styling.&lt;br&gt;
Your team prefers traditional CSS workflows with local scoping.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Hybrid Approach?&lt;/strong&gt;&lt;br&gt;
Many teams find success blending both. Use Tailwind for rapid prototyping and utility-driven layouts, while reserving CSS Modules for highly specific or reusable styles. This hybrid strategy leverages Tailwind’s speed and CSS Modules’ maintainability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS 4 and CSS Modules each bring unique strengths to the table. For scalable projects, Tailwind 4’s performance optimizations and design system consistency make it a powerhouse, especially with its 2025 enhancements. However, CSS Modules remain a robust choice for teams needing control and modularity. The decision hinges on your project’s needs, team expertise, and long-term maintenance goals. Why not experiment with both in a small project to see which fits your workflow best?&lt;br&gt;
As we continue to push the boundaries of web development, tools like these evolve to meet our needs. What’s your go-to styling approach? Share your thoughts in the comments&lt;/p&gt;

&lt;p&gt;I’d love to hear how you tackle scalability in your projects!&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>cssmodules</category>
      <category>frontend</category>
      <category>react</category>
    </item>
    <item>
      <title>Async Like a Senior: Understand JavaScript Timing Without the Confusion</title>
      <dc:creator>Mahdi Hosseini</dc:creator>
      <pubDate>Thu, 29 May 2025 05:30:52 +0000</pubDate>
      <link>https://dev.to/madifrontend/async-like-a-senior-understand-javascript-timing-without-the-confusion-2ie0</link>
      <guid>https://dev.to/madifrontend/async-like-a-senior-understand-javascript-timing-without-the-confusion-2ie0</guid>
      <description>&lt;p&gt;&lt;strong&gt;From Callbacks to Async/Await, Explained Simply and Professionally&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're working as a frontend developer, mastering asynchronous behavior in JavaScript is non-negotiable.&lt;br&gt;
Whether you're dealing with APIs, loading data, timers, or any kind of delayed execution, async code is everywhere ⚙️&lt;/p&gt;

&lt;p&gt;But here’s the real question:&lt;br&gt;
What is async, really? Why do we even need it? And how do callbacks, promises, and async/await actually differ not just in syntax, but in philosophy?&lt;/p&gt;

&lt;p&gt;In this article, I’ll break it all down for you, not just so you “know” it, but so you understand it. Because in real-world development, surface knowledge won’t cut it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, How Does JavaScript Run Code?&lt;/strong&gt;&lt;br&gt;
JavaScript is single-threaded, which means it can only do one thing at a time.&lt;br&gt;
But we’re constantly working with tasks that take time, like calling an API, reading files, or waiting for a timeout ⏳&lt;br&gt;
If we were to run these things synchronously, everything would freeze until they finish 🧊&lt;/p&gt;

&lt;p&gt;That’s exactly why asynchronous programming exists: to keep the app responsive while those tasks finish in the background.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Callbacks – The Old School Way&lt;/strong&gt;&lt;br&gt;
`You pass a function that gets called once the job is done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkozh5pil3i99shs6b3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkozh5pil3i99shs6b3m.png" alt="Image description" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🧠 It works fine, but once callbacks get nested, it becomes a nightmare to read and debug. That’s what we call callback hell 😵‍💫&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Step 2: Promises – A Formal Deal with the Future&lt;/strong&gt;&lt;br&gt;
A Promise is like a contract. It will either resolve (succeed) or reject (fail).&lt;br&gt;
You can then define:&lt;br&gt;
→ What to do when it succeeds&lt;br&gt;
→ What to do when it fails&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe45zmelal1yenxlk3dsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe45zmelal1yenxlk3dsu.png" alt="Image description" width="800" height="527"&gt;&lt;/a&gt;&lt;br&gt;
👍 Easier to read, better error handling, and cleaner structure. But chaining multiple promises still starts to stretch your code.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Step 3: Async/Await – Clean Code, Clear Mind&lt;/strong&gt;&lt;br&gt;
The newest and cleanest syntax for writing async code.&lt;br&gt;
It looks like regular synchronous code, but works asynchronously under the hood.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwgwxlnpxsyksb6026j4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwgwxlnpxsyksb6026j4.png" alt="Image description" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🌟 It’s easy to write, easier to read, and much more comfortable to debug. You’re still writing async code, but in a much more natural way.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;But What’s Actually Happening Behind the Scenes?&lt;/strong&gt;&lt;br&gt;
JavaScript uses an Event Loop system to handle async tasks without blocking the main thread.&lt;/p&gt;

&lt;p&gt;Think of it like a queue system at a coffee shop ☕&lt;br&gt;
The main thread handles orders (sync code)&lt;br&gt;
Async tasks get pushed to a queue&lt;br&gt;
The Event Loop keeps checking: "Is the main thread free now? Cool, let’s run the next async task"&lt;/p&gt;

&lt;p&gt;So when you run a setTimeout or fetch, JavaScript doesn’t wait. It keeps going and comes back to it later. That’s what keeps your UI smooth and responsive.&lt;br&gt;
**&lt;br&gt;
Why Should You Really Understand This?**&lt;br&gt;
It’s not enough to just use await. You need to know:&lt;/p&gt;

&lt;p&gt;When async is needed&lt;/p&gt;

&lt;p&gt;How to manage async flow and errors&lt;/p&gt;

&lt;p&gt;What’s happening under the hood&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Because in real projects:&lt;/strong&gt;&lt;br&gt;
❌ Async mistakes cause ugly bugs&lt;br&gt;
❌ Delayed data can ruin the user experience&lt;br&gt;
❌ Unhandled errors crash the whole app&lt;/p&gt;

&lt;p&gt;But when you master async, you code with confidence 💪&lt;br&gt;
You control time instead of fearing it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Words&lt;/strong&gt;&lt;br&gt;
✅ Callback was the foundation&lt;br&gt;
✅ Promise brought structure&lt;br&gt;
✅ Async/Await made it elegant&lt;/p&gt;

&lt;p&gt;If you only know one style, time to explore the others.&lt;br&gt;
If you know them all but don’t feel confident, build a project.&lt;br&gt;
Even a simple one.&lt;br&gt;
Create a fake login page with loading delays. Call an external API. Simulate a failure.&lt;br&gt;
It’s practice that burns this into your brain 🔥&lt;/p&gt;

&lt;p&gt;Thanks For Reading, Mahdi.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Monitoring Frontend Applications in Next.js, From Errors to Insights 🚀</title>
      <dc:creator>Mahdi Hosseini</dc:creator>
      <pubDate>Sat, 17 May 2025 14:17:06 +0000</pubDate>
      <link>https://dev.to/madifrontend/monitoring-frontend-applications-in-nextjs-from-errors-to-insights-37ag</link>
      <guid>https://dev.to/madifrontend/monitoring-frontend-applications-in-nextjs-from-errors-to-insights-37ag</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F751ocl3mpo8qddevlmcu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F751ocl3mpo8qddevlmcu.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Hey there! 👋 &lt;br&gt;
I'm Mahdi, a frontend developer with a few years of experience working with React and particularly Next.js. In this article, I want to share my real-world experience with monitoring in frontend projects - something I underestimated until a few serious bugs hit our production environment and taught me otherwise. 😅&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Monitoring Matters in Frontend 🤔
&lt;/h2&gt;

&lt;p&gt;The thing about frontend is that our code runs on the user's browser, not our own machine. Everything might seem perfect in development, but do we really know: &lt;br&gt;
🔹 Are users experiencing errors? &lt;br&gt;
🔹 Is the page loading fast? &lt;br&gt;
🔹 Does Safari behave differently? &lt;br&gt;
🔹 Are key interactions breaking?&lt;br&gt;
To answer these questions, proper monitoring is essential. 💡&lt;/p&gt;

&lt;h2&gt;
  
  
  What Should We Monitor? 📊
&lt;/h2&gt;

&lt;p&gt;Before diving into tools, let's define what we actually want to keep an eye on: &lt;br&gt;
🔹 JavaScript runtime errors &lt;br&gt;
🔹 Failed API requests &lt;br&gt;
🔹 Core Web Vitals (LCP, FID, CLS, etc.) &lt;br&gt;
🔹 UI freezes or crashes &lt;br&gt;
🔹 User behavior (rage clicks, drop-offs, session flows)&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools I've Used and Recommend 🛠️
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Sentry - My First Line of Defense 🛡️
&lt;/h3&gt;

&lt;p&gt;Sentry is always the first thing I set up in my Next.js projects. It gives detailed error tracking, browser context, and user insights. It helps me catch unexpected bugs early and fix them with confidence. 🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  LogRocket - Replay User Sessions 🎥
&lt;/h3&gt;

&lt;p&gt;If Sentry tells you what went wrong, LogRocket shows you how it happened. It records user sessions, including mouse movements, clicks, and DOM changes. It has saved me so much time debugging issues that only occur under specific circumstances. 🕵️‍♂️&lt;/p&gt;

&lt;h3&gt;
  
  
  Vercel Analytics - Lightweight Performance Monitoring 📈
&lt;/h3&gt;

&lt;p&gt;If you're using Vercel, their built-in analytics tool is a great way to track performance metrics like page load times and layout shifts. It's simple, privacy-friendly, and requires zero setup. 😎&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Analytics (GA4) - Track User Behavior 📊
&lt;/h3&gt;

&lt;p&gt;GA4 gives high-level insights into how users move through your app, where they drop off, and what events they trigger. It helps connect technical metrics with business goals. 💼&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Logging - Tailored to Your Product 🛠️
&lt;/h3&gt;

&lt;p&gt;Sometimes generic tools aren't enough. I also implement custom logging for specific user actions or edge cases that matter to my product team. It's lightweight, flexible, and surprisingly powerful. ⚡&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring Is a Culture, Not Just a Tool 🌟
&lt;/h2&gt;

&lt;p&gt;In one of the teams I worked with, we had a simple pre-release checklist that made all the difference: &lt;br&gt;
🔹 Is Sentry enabled for this module? &lt;br&gt;
🔹 Are critical errors being alerted via email or Slack? &lt;br&gt;
🔹 Are we tracking important user actions? &lt;br&gt;
🔹 Are performance metrics being recorded?&lt;br&gt;
Monitoring isn't something you "add later." It should be part of the delivery process from day one. ✅&lt;/p&gt;

&lt;h2&gt;
  
  
  A Real-World Story 📖
&lt;/h2&gt;

&lt;p&gt;One day, a user reported that the app "just doesn't load" - but only in Safari. Everything worked fine on Chrome and Firefox. &lt;br&gt;
Thanks to monitoring, I discovered that an optional chaining operator caused a crash in Safari 13, which didn't support it. I shipped a quick patch, and the issue disappeared. 🛠️ &lt;br&gt;
Without monitoring, I would have had no idea this bug existed. 😱&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts 💬
&lt;/h2&gt;

&lt;p&gt;Monitoring in a frontend Next.js app isn't a luxury - it's a requirement. Start with Sentry for error reporting, add LogRocket for session replays, and use GA4 or Vercel Analytics for behavior and performance tracking. &lt;br&gt;
Monitor. Understand. Improve. 🌈&lt;br&gt;
If you've had similar experiences or want to share tools that worked for you, I'd love to hear about them. 😊&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mahdi&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>7 Mistakes I Made When I First Learned React (And How I Fixed Them)</title>
      <dc:creator>Mahdi Hosseini</dc:creator>
      <pubDate>Sat, 19 Apr 2025 18:39:50 +0000</pubDate>
      <link>https://dev.to/madifrontend/7-mistakes-i-made-when-i-first-learned-react-and-how-i-fixed-them-4e3</link>
      <guid>https://dev.to/madifrontend/7-mistakes-i-made-when-i-first-learned-react-and-how-i-fixed-them-4e3</guid>
      <description>&lt;p&gt;Learning React was one of the most exciting—and confusing—parts of my frontend journey. I made a bunch of mistakes early on that, looking back, totally slowed me down. If I had known what I know now, things would’ve moved much faster.&lt;/p&gt;

&lt;p&gt;So here are 7 real mistakes I made when I was just getting started with React, and how I eventually figured them out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Overusing useState for everything&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
At first, I thought useState was the only way to manage state. I used it for everything, even complex or deeply nested data.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
I discovered useReducer for more complex state logic, and started using Context to share state across components. Life got easier real quick.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Ignoring project structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
I dumped everything—components, styles, assets—into one big folder. Zero organization.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
I started following better structures like feature-based folders and Atomic Design. It made my codebase way easier to manage and scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Relying too much on CSS classes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
I used a million CSS classes for every UI element. It looked messy and was hard to maintain.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
Switching to Tailwind CSS and breaking my UI into reusable components helped a lot with both readability and maintainability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Not understanding the difference between JSX and HTML&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
I treated JSX like it was just plain old HTML, which caused a lot of syntax errors and confusion.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
Once I understood that JSX is JavaScript, not HTML (e.g. className, self-closing tags, camelCase), things started to click.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Misusing useEffect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
I used useEffect without really understanding how it worked. I ended up causing infinite loops or making duplicate API calls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ What I learned:&lt;/strong&gt;&lt;br&gt;
I learned how to properly use the dependency array and started using tools like React Query and SWR for data fetching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Mixing UI and logic in the same file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
All the logic and UI were in the same file. It was hard to test, hard to update, and a mess to read.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
I started creating custom hooks to separate logic from presentation. My components became a lot cleaner and easier to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Skipping testing entirely&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🟥 What I did:&lt;br&gt;
I didn’t write any tests. Debugging was a nightmare when something broke.&lt;/p&gt;

&lt;p&gt;✅ What I learned:&lt;br&gt;
I started writing simple tests using Jest and React Testing Library. Even basic tests gave me more confidence in my code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every one of these mistakes helped me grow. If you’re just getting into React, I hope my experience helps you avoid some of these traps—or at least spot them early.&lt;br&gt;
And if you’ve made similar mistakes, I’d love to hear about them. Let’s learn from each other!&lt;/p&gt;

&lt;p&gt;✍️ Written by *&lt;em&gt;Mahdi *&lt;/em&gt;– a frontend developer who loves learning and sharing his journey.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>🚀 12 JavaScript Interview Questions You NEED to Know (2025 Edition) 🎯</title>
      <dc:creator>Mahdi Hosseini</dc:creator>
      <pubDate>Mon, 31 Mar 2025 12:59:34 +0000</pubDate>
      <link>https://dev.to/madifrontend/12-javascript-interview-questions-you-need-to-know-2025-edition-4ghi</link>
      <guid>https://dev.to/madifrontend/12-javascript-interview-questions-you-need-to-know-2025-edition-4ghi</guid>
      <description>&lt;p&gt;Hey fellow devs! 👋 If you're prepping for a frontend interview in 2025, buckle up! You’re gonna face &lt;strong&gt;JavaScript fundamentals, tricky async stuff, and some brain-teasing real-world problems.&lt;/strong&gt; Let's get you ready with &lt;strong&gt;12 must-know questions&lt;/strong&gt; (and answers) so you can crush your next interview! 💪🔥&lt;/p&gt;




&lt;h3&gt;
  
  
  1️⃣ &lt;code&gt;var&lt;/code&gt; vs. &lt;code&gt;let&lt;/code&gt; vs. &lt;code&gt;const&lt;/code&gt; – What’s the deal? 🤔
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; = Function scope, hoisted like a magic trick 🪄 (but can be messy).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; = Block scope, no redeclaration, safer!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt; = Like &lt;code&gt;let&lt;/code&gt; but &lt;strong&gt;locked in&lt;/strong&gt; (you can’t reassign it, but you can mutate objects!).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Rule of thumb: &lt;strong&gt;Use &lt;code&gt;const&lt;/code&gt; by default, &lt;code&gt;let&lt;/code&gt; when needed, and avoid &lt;code&gt;var&lt;/code&gt; like it’s a memory leak.&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  2️⃣ How does JavaScript handle async operations? 🤯
&lt;/h3&gt;

&lt;p&gt;JavaScript is &lt;strong&gt;single-threaded&lt;/strong&gt; but deals with async stuff using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Callbacks&lt;/strong&gt; (old-school, hello callback hell 👿)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promises&lt;/strong&gt; (&lt;code&gt;.then()&lt;/code&gt; &amp;amp; &lt;code&gt;.catch()&lt;/code&gt; make life easier)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async/Await&lt;/strong&gt; (the cleanest way to handle async code)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;Use async/await.&lt;/strong&gt; Your future self will thank you. 😎&lt;/p&gt;




&lt;h3&gt;
  
  
  3️⃣ Explain the Event Loop like I’m 5 🎡
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Event Loop&lt;/strong&gt; is what keeps JavaScript &lt;strong&gt;non-blocking&lt;/strong&gt; and fast. 🏎️&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Call Stack&lt;/strong&gt;: Runs sync code first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Task Queue&lt;/strong&gt;: Holds async callbacks (like &lt;code&gt;setTimeout&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microtask Queue&lt;/strong&gt;: Holds &lt;strong&gt;promises&lt;/strong&gt;, gets priority over Task Queue.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Ever wondered why &lt;code&gt;setTimeout(() =&amp;gt; console.log(‘Hi’), 0)&lt;/code&gt; doesn’t run immediately? &lt;strong&gt;Because promises cut the line!&lt;/strong&gt; ⏳&lt;/p&gt;




&lt;h3&gt;
  
  
  4️⃣ Closures: What, why, and when? 🧐
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;closure&lt;/strong&gt; is a function that &lt;strong&gt;remembers variables from its outer scope&lt;/strong&gt; even when the outer function has finished executing. 🧠&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Closures are 🔥 for &lt;strong&gt;data encapsulation, private variables, and function factories&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  5️⃣ Prototypal Inheritance – What’s the magic? ✨
&lt;/h3&gt;

&lt;p&gt;JavaScript doesn’t use classical OOP inheritance (like Java or C#). Instead, it uses &lt;strong&gt;prototypes&lt;/strong&gt;. Every object has a hidden &lt;code&gt;__proto__&lt;/code&gt; that links to another object. 🧬&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, I’m &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Hello, I’m Alice!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Prototypes are the backbone of JavaScript's object system! &lt;strong&gt;Modern syntax? Use &lt;code&gt;class&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  6️⃣ Shallow vs. Deep Copy – Clone Wars 🏴‍☠️
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shallow Copy&lt;/strong&gt; = Only copies the first level, deeper objects are still referenced.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep Copy&lt;/strong&gt; = Fully clones an object, including nested structures.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;c&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shallowCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;shallowCopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 42 (Oops! 😱)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deepCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;deepCopy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 42 (Phew! 🎉)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  7️⃣ &lt;code&gt;==&lt;/code&gt; vs. &lt;code&gt;===&lt;/code&gt; – The Battle of Equality ⚔️
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; does &lt;strong&gt;type coercion&lt;/strong&gt; (sometimes useful, mostly dangerous).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;===&lt;/code&gt; is &lt;strong&gt;strict&lt;/strong&gt; (always prefer it!).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true (😬 weird but true)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false (👍 expected behavior)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;Just use &lt;code&gt;===&lt;/code&gt;.&lt;/strong&gt; Unless you enjoy debugging nightmares. 😆&lt;/p&gt;




&lt;h3&gt;
  
  
  8️⃣ Generators – The Pause Button ⏸️
&lt;/h3&gt;

&lt;p&gt;Generators are functions that can &lt;strong&gt;pause and resume execution&lt;/strong&gt;. Perfect for iterators and async flows!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;numberGenerator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;gen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;numberGenerator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  9️⃣ What’s up with &lt;code&gt;this&lt;/code&gt;? 🤨
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; is the most &lt;strong&gt;confusing&lt;/strong&gt; keyword in JavaScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global = &lt;code&gt;window&lt;/code&gt; (or &lt;code&gt;undefined&lt;/code&gt; in strict mode).&lt;/li&gt;
&lt;li&gt;Object method = Refers to the calling object.&lt;/li&gt;
&lt;li&gt;Arrow function = Inherits &lt;code&gt;this&lt;/code&gt; from its surrounding scope.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Alice&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;Pro tip:&lt;/strong&gt; If &lt;code&gt;this&lt;/code&gt; is acting weird, check how the function is called! 🧐&lt;/p&gt;




&lt;h3&gt;
  
  
  🔟 Debouncing &amp;amp; Throttling – The Speed Limit 🚦
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debouncing&lt;/strong&gt; = Delays function execution until after a certain time has passed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Throttling&lt;/strong&gt; = Ensures a function runs at most once in a given period.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Resized!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  1️⃣1️⃣ Memory Leaks – Avoiding JavaScript Hoarding 🗑️
&lt;/h3&gt;

&lt;p&gt;Common memory leak causes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uncleared event listeners&lt;/strong&gt; 🛑&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global variables hanging around&lt;/strong&gt; 🎭&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Detached DOM elements&lt;/strong&gt; 👻&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Closures holding onto large objects&lt;/strong&gt; 🎒&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ &lt;strong&gt;Fix:&lt;/strong&gt; Use &lt;code&gt;WeakMap&lt;/code&gt;, remove event listeners, and clean up DOM nodes properly!&lt;/p&gt;




&lt;h3&gt;
  
  
  1️⃣2️⃣ &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;forEach()&lt;/code&gt;, or &lt;code&gt;reduce()&lt;/code&gt;? 🤷‍♂️
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/strong&gt; → Returns a &lt;strong&gt;new array&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;forEach()&lt;/code&gt;&lt;/strong&gt; → Loops, but &lt;strong&gt;doesn’t return a new array&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;reduce()&lt;/code&gt;&lt;/strong&gt; → Reduces an array to a single value.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [2, 4, 6]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;🔥 That’s a wrap! If you found this useful, &lt;strong&gt;share it with your dev friends!&lt;/strong&gt; 🚀 Let’s ace those interviews! 💼&lt;/p&gt;

&lt;h1&gt;
  
  
  frontend #javascript #js #reactjs #interview
&lt;/h1&gt;

</description>
    </item>
  </channel>
</rss>
