<?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>Forem: Chirag Surendra</title>
    <description>The latest articles on Forem by Chirag Surendra (@chirag_surendra_32c810577).</description>
    <link>https://forem.com/chirag_surendra_32c810577</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%2F3671098%2F899d5168-2482-48c1-b94e-4a6c595c16d5.png</url>
      <title>Forem: Chirag Surendra</title>
      <link>https://forem.com/chirag_surendra_32c810577</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chirag_surendra_32c810577"/>
    <language>en</language>
    <item>
      <title>The JavaScript Basics I’m Glad I Learned Before Going Back to React</title>
      <dc:creator>Chirag Surendra</dc:creator>
      <pubDate>Fri, 26 Dec 2025 14:57:12 +0000</pubDate>
      <link>https://forem.com/chirag_surendra_32c810577/the-javascript-basics-im-glad-i-learned-before-going-back-to-react-3p9p</link>
      <guid>https://forem.com/chirag_surendra_32c810577/the-javascript-basics-im-glad-i-learned-before-going-back-to-react-3p9p</guid>
      <description>&lt;p&gt;In my last blog, I talked about the mistakes I made while learning React—especially how skipping JavaScript fundamentals made everything harder.&lt;br&gt;
This time, I want to share what I did differently when I decided to learn JavaScript properly.&lt;br&gt;
And trust me, this decision changed everything.&lt;/p&gt;
&lt;h2&gt;
  
  
  My First (Funny) JavaScript Misunderstanding 😅
&lt;/h2&gt;

&lt;p&gt;When I first heard about JavaScript, I honestly thought:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Java and JavaScript are probably the same… just add script at the end.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yeah. Big mistake 😄&lt;br&gt;
Turns out, Java and JavaScript are completely different languages. Different use cases, different syntax, different worlds.&lt;/p&gt;

&lt;p&gt;Once I got past that assumption, I decided:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This time, I won’t rush. I’ll start from the absolute basics.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Everything in JavaScript Happens Inside an Execution Context 🧠
&lt;/h2&gt;

&lt;p&gt;One of the first (and most important) concepts I learned was the &lt;strong&gt;Execution Context.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it like a sealed container where JavaScript runs your code.&lt;/p&gt;

&lt;p&gt;This container holds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Information about variables&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;The order in which code is executed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every time JavaScript runs a program, it creates an execution context.&lt;/p&gt;
&lt;h2&gt;
  
  
  What’s Inside the Execution Context?
&lt;/h2&gt;

&lt;p&gt;The execution context has two main components:&lt;/p&gt;

&lt;p&gt;1️⃣ Memory Component (Variable Environment)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stores variables and functions&lt;/li&gt;
&lt;li&gt;Keeps them in key-value pairs&lt;/li&gt;
&lt;li&gt;Variables are initially stored as undefined&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2️⃣ Code Component (Thread of Execution)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Executes code one line at a time&lt;/li&gt;
&lt;li&gt;Follows a strict order&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of this, JavaScript is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Synchronous → One command at a time&lt;/li&gt;
&lt;li&gt;Single-threaded → Executes code in a specific sequence&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  JavaScript Runs in Two Phases ⚙️
&lt;/h2&gt;

&lt;p&gt;Whenever a JS program runs, the execution context is created in two phases:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1: Memory Creation Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory is allocated to all variables and functions&lt;/li&gt;
&lt;li&gt;Variables get undefined&lt;/li&gt;
&lt;li&gt;Functions get stored entirely in memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phase 2: Code Execution Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code is executed line by line&lt;/li&gt;
&lt;li&gt;Actual values are assigned&lt;/li&gt;
&lt;li&gt;Functions are invoked&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let’s Understand This with a Simple Example 👇&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var n = 2;

function square(num) {
  var ans = num * num;
  return ans;
}

var square2 = square(n);
var square4 = square(4);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🧠 Memory Creation Phase
&lt;/h2&gt;

&lt;p&gt;JavaScript first scans the whole code and allocates memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;n → undefined&lt;/li&gt;
&lt;li&gt;square → function definition&lt;/li&gt;
&lt;li&gt;square2 → undefined&lt;/li&gt;
&lt;li&gt;square4 → undefined&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing is executed yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  ▶️ Code Execution Phase
&lt;/h2&gt;

&lt;p&gt;Now JavaScript starts executing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;n gets the value 2&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function square is skipped for now&lt;br&gt;
When square(n) is called:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A new execution context is created&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory is allocated for num and ans&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;num = 2, ans = 4&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;return ans sends control back&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same steps repeat for square(4).&lt;/p&gt;

&lt;p&gt;Once everything finishes, the global execution context is destroyed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Call Stack: The Manager Behind the Scenes 📚
&lt;/h2&gt;

&lt;p&gt;So how does JavaScript keep track of all this?&lt;/p&gt;

&lt;p&gt;👉 With the Call Stack&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It keeps track of execution contexts&lt;/li&gt;
&lt;li&gt;Follows Last In, First Out (LIFO)&lt;/li&gt;
&lt;li&gt;When a function finishes, its execution context is removed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The call stack is also known as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Execution Context Stack&lt;/li&gt;
&lt;li&gt;Program Stack&lt;/li&gt;
&lt;li&gt;Runtime Stack&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why This Matters (Especially for React) 💡
&lt;/h2&gt;

&lt;p&gt;When I finally understood:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Execution context&lt;/li&gt;
&lt;li&gt;Memory allocation&lt;/li&gt;
&lt;li&gt;Call stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Things like this started making sense:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hoisting&lt;/li&gt;
&lt;li&gt;Closures&lt;/li&gt;
&lt;li&gt;useEffect&lt;/li&gt;
&lt;li&gt;State updates&lt;/li&gt;
&lt;li&gt;Unexpected behavior in React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React didn’t feel “magical” anymore—it felt &lt;strong&gt;logical&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;This time, I didn’t rush into React.&lt;/p&gt;

&lt;p&gt;I slowed down.&lt;br&gt;
I respected JavaScript.&lt;br&gt;
I learned how it actually works behind the scenes.&lt;/p&gt;

&lt;p&gt;And honestly?&lt;br&gt;
That made me a much better React learner.&lt;/p&gt;

&lt;p&gt;If you’re about to start React, or feeling stuck:&lt;br&gt;
Don’t skip JavaScript fundamentals.&lt;br&gt;
They’re not optional—they’re the foundation.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>learning</category>
      <category>react</category>
    </item>
    <item>
      <title>Beginner mistakes I made while learning React</title>
      <dc:creator>Chirag Surendra</dc:creator>
      <pubDate>Sat, 20 Dec 2025 07:50:12 +0000</pubDate>
      <link>https://forem.com/chirag_surendra_32c810577/beginner-mistakes-i-made-while-learning-react-1li6</link>
      <guid>https://forem.com/chirag_surendra_32c810577/beginner-mistakes-i-made-while-learning-react-1li6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;React JS (commonly referred to as React) is an open-source JavaScript library developed and maintained by Facebook (now Meta). It is mainly used for building user interfaces, especially single-page applications.&lt;/p&gt;

&lt;p&gt;Unlike full frameworks like Angular, React focuses only on the view layer, which makes it flexible and easy to integrate with other tools and libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Characteristics of React
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Component-Based Architecture&lt;/strong&gt;&lt;br&gt;
React applications are built using small, reusable components that return UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declarative Approach&lt;/strong&gt;&lt;br&gt;
You describe what the UI should look like, and React handles how to update the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual DOM&lt;/strong&gt;&lt;br&gt;
React uses a lightweight copy of the real DOM to optimize rendering and improve performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unidirectional Data Flow&lt;/strong&gt;&lt;br&gt;
Data flows from parent components to child components, making apps easier to debug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSX Syntax&lt;/strong&gt;&lt;br&gt;
JSX allows you to write HTML-like code inside JavaScript.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Main Problem I Faced
&lt;/h2&gt;

&lt;p&gt;When I started learning React, I jumped directly into React without fully understanding JavaScript.&lt;/p&gt;

&lt;p&gt;At first, I thought React itself was difficult. But later, I realized the real problem was my weak JavaScript fundamentals. React heavily depends on JavaScript concepts, and without them, everything feels confusing.&lt;/p&gt;

&lt;p&gt;This mistake made my learning process slower and more frustrating than it needed to be.&lt;/p&gt;

&lt;p&gt;That’s why I’m writing this post—to help other beginners avoid the same mistakes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Beginner Mistakes I Made While Learning React
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Skipping JavaScript Fundamentals ❌&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was my biggest mistake.&lt;/p&gt;

&lt;p&gt;React uses many JavaScript concepts such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;map, filter, reduce&lt;/li&gt;
&lt;li&gt;Arrow functions&lt;/li&gt;
&lt;li&gt;Destructuring&lt;/li&gt;
&lt;li&gt;Spread operator&lt;/li&gt;
&lt;li&gt;this, closures, and scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without understanding these, React code looks scary.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const users = ["Alex", "John", "Sam"];

users.map(user =&amp;gt; &amp;lt;li&amp;gt;{user}&amp;lt;/li&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don’t understand map(), this line will confuse you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Before learning React, make sure you are comfortable with core JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Not Understanding Components Properly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initially, I treated components like normal HTML files.&lt;/p&gt;

&lt;p&gt;In reality, components are functions that return UI.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Welcome() {
  return &amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should be small&lt;/li&gt;
&lt;li&gt;Should do one thing&lt;/li&gt;
&lt;li&gt;Should be reusable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Think of components as building blocks, not pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Confusing Props and State&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first, I didn’t understand the difference between props and state.&lt;/p&gt;

&lt;p&gt;Props → Data passed from parent to child (read-only)&lt;/p&gt;

&lt;p&gt;State → Data managed inside a component (can change)&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Greeting({ name }) {
  return &amp;lt;h2&amp;gt;Hello, {name}&amp;lt;/h2&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, name is a prop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Understand when to use props and when to use state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Forgetting to Use Keys in Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When rendering lists, I often forgot to add key, which caused warnings.&lt;/p&gt;

&lt;p&gt;Wrong:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;items.map(item =&amp;gt; &amp;lt;li&amp;gt;{item}&amp;lt;/li&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;items.map(item =&amp;gt; &amp;lt;li key={item}&amp;gt;{item}&amp;lt;/li&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keys help React identify which items have changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Always use unique keys when rendering lists.&lt;/p&gt;

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

&lt;p&gt;I used useEffect without understanding dependencies, which caused unnecessary re-renders.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  fetchData();
}, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The empty array means this effect runs only once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Learn how dependency arrays work before using useEffect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Mutating State Directly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first, I modified state directly, which didn’t update the UI.&lt;/p&gt;

&lt;p&gt;Wrong:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;state.count = state.count + 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setCount(count + 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React updates the UI only when state is updated immutably.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Lesson:&lt;/strong&gt;&lt;br&gt;
Never mutate state directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Wrote This Post
&lt;/h2&gt;

&lt;p&gt;I wrote this post because these mistakes made my React learning journey harder than it needed to be.&lt;/p&gt;

&lt;p&gt;If you are a beginner and feeling stuck with React, chances are the problem isn’t React—it’s the basics you skipped.&lt;/p&gt;

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

&lt;p&gt;React is a powerful and beginner-friendly library if you learn it the right way.&lt;/p&gt;

&lt;h2&gt;
  
  
  My advice to beginners:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Learn JavaScript fundamentals first&lt;/li&gt;
&lt;li&gt;Build small projects&lt;/li&gt;
&lt;li&gt;Make mistakes and learn from them&lt;/li&gt;
&lt;li&gt;Don’t rush the process&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💬 I’d love to hear from you!
&lt;/h2&gt;

&lt;p&gt;What mistakes did you make while learning React?&lt;br&gt;
Feel free to comment, share your experience, or ask questions below.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
      <category>reactjsdevelopment</category>
    </item>
  </channel>
</rss>
