<?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: Masudur Rahman Sourav</title>
    <description>The latest articles on DEV Community by Masudur Rahman Sourav (@masudursourav).</description>
    <link>https://dev.to/masudursourav</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%2F783182%2Fcd8424d9-d7f0-499e-b94b-21aa1cba2354.jpg</url>
      <title>DEV Community: Masudur Rahman Sourav</title>
      <link>https://dev.to/masudursourav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/masudursourav"/>
    <language>en</language>
    <item>
      <title>React Compound Components: The "Build Your Own Adventure" Pattern</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Mon, 16 Feb 2026 11:07:40 +0000</pubDate>
      <link>https://dev.to/masudursourav/react-compound-components-the-build-your-own-adventure-pattern-2dff</link>
      <guid>https://dev.to/masudursourav/react-compound-components-the-build-your-own-adventure-pattern-2dff</guid>
      <description>&lt;p&gt;If you've ever bought a piece of furniture from a certain Swedish store, you know the drill. You don't buy a pre-assembled "Sitting Unit." You buy a frame, cushions, legs, and maybe a weird little wrench, and you put it together yourself.&lt;br&gt;
&lt;strong&gt;Compound Components&lt;/strong&gt; are the Ikea furniture of React.&lt;/p&gt;

&lt;p&gt;Instead of building one giant, monolithic component that takes 500 props (), you build a set of smaller components that work together like magic. They share state behind the scenes, but you decide where everything goes.&lt;/p&gt;

&lt;p&gt;Let's dive into the pattern that makes libraries like Radix UI and Headless UI possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎨 The Graphical Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you are building a &lt;strong&gt;Tabs&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Mega-Prop" Way (The Old Way) 🦖&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You pass a giant configuration object. The component decides the layout. You have zero control. If you want to move the "Tab List" below the "Panels," you have to rewrite the library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
       +-----------------------------+
       |      &amp;lt;Tabs config={...} /&amp;gt;  |
       +-----------------------------+
       | [Tab 1] [Tab 2] [Tab 3]     |  &amp;lt;-- Hardcoded position
       |                             |
       |  Content for Tab 1...       |
       +-----------------------------+

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The Compound Component Way (The Flexible Way) 🤸&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You export a parent (&lt;code&gt;Tabs&lt;/code&gt;) and several children (&lt;code&gt;Tab&lt;/code&gt;, &lt;code&gt;Panel&lt;/code&gt;). The Parent holds the state (which tab is active), but the User decides the layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       &amp;lt;Tabs&amp;gt;
          &amp;lt;TabList&amp;gt;  &amp;lt;-- You put this where YOU want
             &amp;lt;Tab&amp;gt;One&amp;lt;/Tab&amp;gt;
             &amp;lt;Tab&amp;gt;Two&amp;lt;/Tab&amp;gt;
          &amp;lt;/TabList&amp;gt;

          &amp;lt;TabPanels&amp;gt;
             &amp;lt;Panel&amp;gt;Content 1&amp;lt;/Panel&amp;gt;
             &amp;lt;Panel&amp;gt;Content 2&amp;lt;/Panel&amp;gt;
          &amp;lt;/TabPanels&amp;gt;
       &amp;lt;/Tabs&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Parent (&lt;code&gt;Tabs&lt;/code&gt;) secretly passes state to the children using &lt;strong&gt;Context&lt;/strong&gt;. They communicate telepathically. 🧠✨&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💻 The Code: From "Prop Hell" to "Component Heaven"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's build a simple &lt;strong&gt;Accordion&lt;/strong&gt; (toggle sections).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Setup (Creating the Context)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we need a secret channel for our components to talk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext, useContext, useState } from 'react';

// 1. Create the Context
const AccordionContext = createContext();

// 2. Create the Parent Component
const Accordion = ({ children }) =&amp;gt; {
  const [openIndex, setOpenIndex] = useState(0);

  // The toggle function logic
  const toggleIndex = (index) =&amp;gt; {
    setOpenIndex(prev =&amp;gt; (prev === index ? null : index));
  };

  return (
    &amp;lt;AccordionContext.Provider value={{ openIndex, toggleIndex }}&amp;gt;
      &amp;lt;div className="accordion-wrapper"&amp;gt;
        {children}
      &amp;lt;/div&amp;gt;
    &amp;lt;/AccordionContext.Provider&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. The Children (Consuming the Context)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we create the sub-components. Notice they don't accept &lt;code&gt;isOpen&lt;/code&gt; or &lt;code&gt;onClick&lt;/code&gt; as props from the user. They grab it from the Context!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 3. The Item Component (Just a wrapper, usually)
const AccordionItem = ({ children }) =&amp;gt; {
  return &amp;lt;div className="accordion-item"&amp;gt;{children}&amp;lt;/div&amp;gt;;
};

// 4. The Trigger (The clickable part)
const AccordionHeader = ({ children, index }) =&amp;gt; {
  const { toggleIndex, openIndex } = useContext(AccordionContext);
  const isActive = openIndex === index;

  return (
    &amp;lt;button 
      className={`accordion-header ${isActive ? 'active' : ''}`}
      onClick={() =&amp;gt; toggleIndex(index)}
    &amp;gt;
      {children} {isActive ? '🔽' : '▶️'}
    &amp;lt;/button&amp;gt;
  );
};

// 5. The Content (The hidden part)
const AccordionPanel = ({ children, index }) =&amp;gt; {
  const { openIndex } = useContext(AccordionContext);

  if (openIndex !== index) return null;

  return &amp;lt;div className="accordion-panel"&amp;gt;{children}&amp;lt;/div&amp;gt;;
};

// Attach sub-components to the Parent for cleaner imports (Optional but cool)
Accordion.Item = AccordionItem;
Accordion.Header = AccordionHeader;
Accordion.Panel = AccordionPanel;

export default Accordion;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Usage (The Magic Moment) 🪄&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Look how clean this API is. No complex config objects. Just JSX.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Accordion from './Accordion';

const FAQ = () =&amp;gt; (
  &amp;lt;Accordion&amp;gt;

    &amp;lt;Accordion.Item&amp;gt;
      &amp;lt;Accordion.Header index={0}&amp;gt;Is React hard?&amp;lt;/Accordion.Header&amp;gt;
      &amp;lt;Accordion.Panel index={0}&amp;gt;
        Only until you understand `useEffect`. Then it's just chaotic.
      &amp;lt;/Accordion.Panel&amp;gt;
    &amp;lt;/Accordion.Item&amp;gt;

    &amp;lt;Accordion.Item&amp;gt;
      &amp;lt;Accordion.Header index={1}&amp;gt;Why use Compound Components?&amp;lt;/Accordion.Header&amp;gt;
      &amp;lt;Accordion.Panel index={1}&amp;gt;
        Because passing 50 props is bad for your blood pressure.
      &amp;lt;/Accordion.Panel&amp;gt;
    &amp;lt;/Accordion.Item&amp;gt;

  &amp;lt;/Accordion&amp;gt;
);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🏆 Why Should You Do This? (Use Cases)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. UI Libraries (Tabs, Selects, Menus)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are building a design system, this is mandatory. Users will want to put an icon inside the Tab, or move the Label below the Input. Compound components let them do that without bugging you to add a &lt;code&gt;renderLabelBottom&lt;/code&gt; prop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Implicit State Sharing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Notice how Accordion.Header automatically knew how to toggle the panel? The user didn't have to wire up &lt;code&gt;onClick={() =&amp;gt; setIndex(1)}&lt;/code&gt; manually. It "Just Works".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Semantic Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It reads like HTML. &lt;code&gt;&amp;lt;List&amp;gt;&amp;lt;Item /&amp;gt;&amp;lt;Item /&amp;gt;&amp;lt;/List&amp;gt;&lt;/code&gt;. It’s declarative and beautiful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🕳️ The Pitfalls (The "Gotchas")&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The "Single Child" Restriction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you try to wrap a child in a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; that blocks the Context (rare with Context API, but common with the older &lt;code&gt;React.Children.map&lt;/code&gt; approach), things break.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fix&lt;/em&gt;: Stick to the Context API pattern shown above. It penetrates through &lt;code&gt;divs&lt;/code&gt; like X-rays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Over-Engineering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don't use this for a simple Button. If a component doesn't have internal state that needs to be shared among multiple distinct children, you probably just need regular props.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Name Pollution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you export &lt;code&gt;Accordion&lt;/code&gt;, &lt;code&gt;AccordionItem&lt;/code&gt;, &lt;code&gt;AccordionHeader&lt;/code&gt;, &lt;code&gt;AccordionPanel&lt;/code&gt;, your imports get messy.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fix&lt;/em&gt;: Attach them to the main component: &lt;code&gt;Accordion.Item&lt;/code&gt;. It keeps the namespace clean and makes you look like a pro.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🏁 Conclusion&lt;/strong&gt;&lt;br&gt;
The &lt;strong&gt;Compound Component Pattern&lt;/strong&gt; is the difference between giving someone a fish (a rigid component) and teaching them to fish (a flexible set of tools).&lt;/p&gt;

&lt;p&gt;It requires a bit more setup code for you (the library author), but it creates a delightful experience for the developer using your component. And isn't that what we all want? To be loved by other developers? (Please validate me). 🥺🤝&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>learning</category>
      <category>react</category>
    </item>
    <item>
      <title>React Form Patterns: Controlled vs. Uncontrolled Components</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Fri, 06 Feb 2026 05:57:38 +0000</pubDate>
      <link>https://dev.to/masudursourav/react-form-patterns-controlled-vs-uncontrolled-components-584j</link>
      <guid>https://dev.to/masudursourav/react-form-patterns-controlled-vs-uncontrolled-components-584j</guid>
      <description>&lt;p&gt;If React components were people, Controlled Components would be that friend who plans every minute of their vacation in an Excel spreadsheet. Uncontrolled Components would be the friend who shows up at the airport without a ticket, wearing flip-flops, saying, "The universe will provide."&lt;/p&gt;

&lt;p&gt;Handling forms in React forces you to choose a side. Do you want to micro-manage every keystroke? Or do you want to let the DOM do its thing and just check the results later?&lt;/p&gt;

&lt;p&gt;Let's break down the battle between Controlled and Uncontrolled forms.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎮 The Controlled Component (The Micro-Manager)
&lt;/h2&gt;

&lt;p&gt;In a Controlled setup, React is the single source of truth. The DOM input doesn't breathe without React's permission.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The User types 'A'.&lt;/li&gt;
&lt;li&gt;React says, "Hold on, let me update my State first."&lt;/li&gt;
&lt;li&gt;React updates State to 'A'.&lt;/li&gt;
&lt;li&gt;React tells the Input: "Okay, now you can display 'A'."&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s a tight feedback loop. It’s secure. It’s predictable. It’s also a little exhausting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎨 The Graphical Explanation&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;
    User Types 'H'
           |
           v
  +------------------+
  |  Event Handler   |  "Hey React, they typed H!"
  +--------+---------+
           |
           v
  +------------------+
  |   React State    |  "Updating state to 'H'..."
  +--------+---------+
           |
           v
  +------------------+
  |   Input Value    |  "Displaying 'H' as ordered, sir!"
  +------------------+

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;💻 The Code&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;import React, { useState } from 'react';

const ControlFreakForm = () =&amp;gt; {
  const [name, setName] = useState('');

  const handleChange = (e) =&amp;gt; {
    const value = e.target.value;
    // We can intercept! NO LOWERCASE ALLOWED! 👮‍♂️
    setName(value.toUpperCase());
  };

  return (
    &amp;lt;form&amp;gt;
      &amp;lt;label&amp;gt;Name (Screaming only):&amp;lt;/label&amp;gt;
      &amp;lt;input 
        type="text" 
        value={name} 
        onChange={handleChange} 
      /&amp;gt;
      &amp;lt;p&amp;gt;Current State: {name}&amp;lt;/p&amp;gt;
    &amp;lt;/form&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ Use Case:&lt;/strong&gt; When you need instant validation (password strength meters), dynamic formatting (credit card spacing), or conditional disabling of the submit button.&lt;/p&gt;

&lt;h2&gt;
  
  
  🐎 The Uncontrolled Component (The "It Is What It Is")
&lt;/h2&gt;

&lt;p&gt;In an Uncontrolled setup, the data lives in the DOM, not in React state. React is like a landlord who owns the building but doesn't have a key to your apartment. When React needs the data (like on submit), it has to knock on the door (using a &lt;code&gt;ref&lt;/code&gt;) and ask, "Hey, what did you write in there?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The User types 'A'.&lt;/li&gt;
&lt;li&gt;The Input displays 'A'.&lt;/li&gt;
&lt;li&gt;React is asleep.&lt;/li&gt;
&lt;li&gt;User hits "Submit".&lt;/li&gt;
&lt;li&gt;React wakes up and checks the Ref to see what happened.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🎨 The Graphical Explanation&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;      User Types 'H'
           |
           v
  +------------------+
  |   DOM Input      |  "I got this. I'll hold the 'H'."
  +------------------+
           |
           | (React ignores this part)
           |
      User Clicks Submit
           |
           v
  +------------------+
  |    React Ref     |  "Yo DOM, what's the value?"
  +------------------+


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;💻 The Code&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;import React, { useRef } from 'react';

const WildWestForm = () =&amp;gt; {
  const nameInputRef = useRef(null);

  const handleSubmit = (e) =&amp;gt; {
    e.preventDefault();
    // Knocking on the DOM's door ✊
    alert(`Welcome, ${nameInputRef.current.value}!`);
  };

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;label&amp;gt;Name (I don't care until you submit):&amp;lt;/label&amp;gt;
      &amp;lt;input 
        type="text" 
        defaultValue="" 
        ref={nameInputRef} 
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ Use Case:&lt;/strong&gt; When you are migrating legacy code, integrating with non-React libraries (like jQuery plugins... shudder), or building simple forms where you don't need instant validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  🥊 The Showdown: Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Controlled&lt;/th&gt;
&lt;th&gt;Uncontrolled&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Source of Truth&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;React State&lt;/td&gt;
&lt;td&gt;The DOM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data Access&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Instant (on every keystroke)&lt;/td&gt;
&lt;td&gt;On Demand (usually submit)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Validation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Real-time (as you type)&lt;/td&gt;
&lt;td&gt;On Submit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Re-renders on every keystroke&lt;/td&gt;
&lt;td&gt;Only re-renders on submit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Code Volume&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;More boilerplate (handlers, state)&lt;/td&gt;
&lt;td&gt;Less boilerplate (refs)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  🕳️ The Pitfalls (Gotchas)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. The "File Input" Exception 📁&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In React, an  is always uncontrolled because its value can only be set by a user, not by code (security reasons). If you try to control a file input value, React will yell at you. Just use a Ref.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Performance Myth 🐌&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;People say Controlled components are slower because they re-render on every keystroke. Unless you are pasting the entire script of The Bee Movie into a text area on a low-end Android phone from 2015, it usually doesn't matter. React is fast. Don't optimize prematurely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The &lt;code&gt;null&lt;/code&gt; vs &lt;code&gt;undefined&lt;/code&gt; Trap 🪤&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you initialize a controlled input with value={undefined} (or null) and then switch it to a string later, React will scream: "A component is changing an uncontrolled input of type text to be controlled."&lt;br&gt;
Fix: Always initialize state with an empty string useState('').&lt;/p&gt;

&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;So, which one should you choose?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controlled&lt;/strong&gt; is the standard. It’s robust, "React-y," and allows you to do cool things like disable the submit button if the email is invalid. It’s high-maintenance but high-reward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uncontrolled&lt;/strong&gt; is the quick-and-dirty. It’s great for quick hacks, simple forms, or when you just don't want to write a handleChange function for the 100th time today.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>nextjs</category>
      <category>javascript</category>
    </item>
    <item>
      <title>The Container &amp; Presentational Pattern: Separation of Concerns in React</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Wed, 04 Feb 2026 05:23:14 +0000</pubDate>
      <link>https://dev.to/masudursourav/the-container-presentational-pattern-separation-of-concerns-in-react-38mc</link>
      <guid>https://dev.to/masudursourav/the-container-presentational-pattern-separation-of-concerns-in-react-38mc</guid>
      <description>&lt;p&gt;If you’ve been writing React for a while, you’ve probably created a "God Component." You know the one. It fetches data, manages fifty state variables, handles form validation, calculates the Fibonacci sequence for some reason, and also renders the HTML. It’s a messy, co-dependent relationship where everyone is screaming. &lt;/p&gt;

&lt;p&gt;Enter the Container/Presentational Pattern (also known as Smart vs. Dumb components, though we try to be nicer about the naming these days). It’s couples therapy for your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎨 The Graphical Explanation
&lt;/h2&gt;

&lt;p&gt;Imagine a high-end restaurant.&lt;/p&gt;

&lt;p&gt;The Container ( The Chef / Manager ): Sweating in the back. Dealing with suppliers (APIs), managing inventory (State), and screaming about hygiene standards (Business Logic). They don't care what the plate looks like; they just care that the food exists.&lt;/p&gt;

&lt;p&gt;The Presentational ( The Waiter / Plater ): Takes the prepared food, arranges it beautifully, and smiles at the customer. They don't know how the sausage is made, and frankly, they don't want to know.&lt;/p&gt;

&lt;p&gt;Here is how it looks in your app structure:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   +-------------------------+
   |   CONTAINER COMPONENT   |
   |  (The Brains / Logic)   |
   +-------------------------+
   | 1. Fetches Data (API)   |
   | 2. Manages State        |
   | 3. Defines Handlers     |
   +-----------+-------------+
               |
    (Passes Data via Props)
               |
               v
   +-------------------------+
   | PRESENTATIONAL COMPONENT|
   |  (The Looks / UI)       |
   +-------------------------+
   | 1. Receives props       |
   | 2. Renders JSX / CSS    |
   | 3. Looks Fabulous       |
   +-------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  💻 The Code: A Tale of Two Components
&lt;/h2&gt;

&lt;p&gt;Let's look at a classic example: A list of Crypto Currencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Presentational Component (The "Pretty" One)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This component is pure. It has no idea where the data comes from. It just takes props and turns them into pixels. It has zero anxiety.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// CryptoList.jsx
import React from 'react';

const CryptoList = ({ coins, isLoading, onRefresh }) =&amp;gt; {
  if (isLoading) {
    return &amp;lt;div className="spinner"&amp;gt;Loading your digital gold...&amp;lt;/div&amp;gt;;
  }

  return (
    &amp;lt;div className="crypto-card"&amp;gt;
      &amp;lt;h2&amp;gt;🚀 To The Moon!&amp;lt;/h2&amp;gt;
      &amp;lt;ul&amp;gt;
        {coins.map((coin) =&amp;gt; (
          &amp;lt;li key={coin.id} className="coin-row"&amp;gt;
            &amp;lt;strong&amp;gt;{coin.name}&amp;lt;/strong&amp;gt;: ${coin.price.toFixed(2)}
          &amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
      &amp;lt;button onClick={onRefresh}&amp;gt;Refresh Prices&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default CryptoList;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. The Container Component (The "Smart" One)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This component does the heavy lifting. It doesn't care about CSS classes. It cares about useEffect, fetch, and handling errors without crying.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// CryptoListContainer.jsx
import React, { useState, useEffect } from 'react';
import CryptoList from './CryptoList';

const CryptoListContainer = () =&amp;gt; {
  const [coins, setCoins] = useState([]);
  const [loading, setLoading] = useState(true);

  const fetchCoinData = async () =&amp;gt; {
    setLoading(true);
    // Simulating an API call because I don't have an API key handy
    setTimeout(() =&amp;gt; {
      setCoins([
        { id: 1, name: 'Bitcoin', price: 45000 },
        { id: 2, name: 'Ethereum', price: 3200 },
        { id: 3, name: 'Doge', price: 0.12 },
      ]);
      setLoading(false);
    }, 1000);
  };

  useEffect(() =&amp;gt; {
    fetchCoinData();
  }, []);

  // Notice: No HTML here, just passing data down!
  return (
    &amp;lt;CryptoList 
      coins={coins} 
      isLoading={loading} 
      onRefresh={fetchCoinData} 
    /&amp;gt;
  );
};

export default CryptoListContainer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🏆 Why Should You Do This? (Use Cases)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Reusability (The Outfit Change)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can use the same CryptoList UI to display data from a different source (like a "Favorites" list vs "All Coins" list) without rewriting the styling logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Separation of Concerns (Mental Health)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you need to fix a styling bug (margin issues, ugh), you open the Presentational file. When the data isn't loading, you open the Container. You don't have to scroll past 400 lines of logic to find the &lt;/p&gt; tag.

&lt;p&gt;&lt;strong&gt;3. Designer/Developer Harmony&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have a designer on your team who knows HTML/CSS but is scared of useEffect, they can work safely in the Presentational files without accidentally creating an infinite render loop that crashes the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  🕳️ The Pitfalls (The "Gotchas")
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. The "Hook" Twist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Plot twist! Since React Hooks (useCustomHook) came out in 2019, strictly creating "Container Components" (class-style) is less common.&lt;br&gt;
Nowadays, the Container is often replaced by a Custom Hook.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Old Way:&lt;br&gt;
Container Component wraps UI Component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;New Way:&lt;br&gt;
UI Component calls useCryptoData() hook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verdict:&lt;br&gt;
The concept (separation of logic/view) is still king, but the implementation has shifted.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Over-Engineering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don't create a Container/Presenter pair for a simple "Submit Button." If a component is 10 lines of code, splitting it into two files just makes you look pretentious. Keep it simple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Prop Drilling Hell&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have containers inside containers inside containers, passing props down becomes a nightmare. If you find yourself passing user={user} down 15 levels, stop. Get help. Use Context.&lt;/p&gt;

&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;The Container/Presentational pattern is like separating your laundry into "Whites" and "Colors." It takes a little extra effort upfront, but it prevents your codebase from turning into a muddy, grey mess later on.&lt;/p&gt;

&lt;p&gt;Keep your UI dumb and your logic smart, and your React app will be a happy place. 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding Hoisting in JavaScript: Why Can We Use `var` Before Declaration?</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Tue, 25 Mar 2025 19:37:37 +0000</pubDate>
      <link>https://dev.to/masudursourav/understanding-hoisting-in-javascript-why-can-we-use-var-before-declaration-3fio</link>
      <guid>https://dev.to/masudursourav/understanding-hoisting-in-javascript-why-can-we-use-var-before-declaration-3fio</guid>
      <description>&lt;p&gt;Hoisting is a fundamental concept in JavaScript that often confuses beginners. You might have seen situations where a variable declared using &lt;code&gt;var&lt;/code&gt; is accessed even before it is defined in the code, without throwing an error. How does that work?&lt;/p&gt;

&lt;p&gt;To understand this, let's dive into hoisting, the JavaScript execution context, and how the JavaScript engine processes code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Hoisting?
&lt;/h2&gt;

&lt;p&gt;Hoisting is JavaScript’s default behavior of moving variable and function declarations to the top of their scope before execution. This means JavaScript allocates memory for variables and functions during the creation phase of execution, making them available before the code actually runs.&lt;/p&gt;

&lt;p&gt;But there’s an important distinction:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Function declarations&lt;/strong&gt; are &lt;strong&gt;hoisted with their definitions&lt;/strong&gt;, meaning you can call a function before declaring it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variables declared&lt;/strong&gt; with &lt;code&gt;var&lt;/code&gt; &lt;strong&gt;are hoisted but initialized with &lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;, meaning you can reference them before declaration, but they won't hold their actual value until the assignment line is executed. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables are hoisted but not initialized, so accessing them before declaration results in a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The JavaScript Execution Context and Hoisting
&lt;/h2&gt;

&lt;p&gt;If don't know what is JavaScript Execution Context or doesn't have a full understanding of it read my this article : &lt;br&gt;
&lt;a href="https://dev.to/masudursourav/behind-the-scenes-of-javascript-how-execution-works-with-execution-context-call-stac-4bip"&gt;&lt;br&gt;
Behind the Scenes of JavaScript: How Execution Works with Execution Context &amp;amp; Call Stack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript executes code in two phases inside the &lt;strong&gt;Execution Context&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Creation Phase (Memory Allocation)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;The JavaScript engine scans the code and sets up the execution context.&lt;/li&gt;
&lt;li&gt;It &lt;strong&gt;allocates memory&lt;/strong&gt; for variables and functions.&lt;/li&gt;
&lt;li&gt;Functions are stored with their full definitions.&lt;/li&gt;
&lt;li&gt;Variables declared with &lt;code&gt;var&lt;/code&gt; are set to &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables are stored but are not initialized, causing the &lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt; error if accessed before declaration.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Execution Phase (Code Execution)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript runs the code line by line.&lt;/li&gt;
&lt;li&gt;Variable values get assigned during execution.&lt;/li&gt;
&lt;li&gt;Function calls are executed where they appear.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Example: Hoisting with &lt;code&gt;var&lt;/code&gt;
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(x); // Output: undefined
var x = 10;
console.log(x); // Output: 10

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

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Behind the Scenes (How JavaScript Executes It)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;During the Creation Phase, JavaScript sees &lt;code&gt;var x = 10;&lt;/code&gt; and does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declares &lt;code&gt;x&lt;/code&gt; and assigns it &lt;code&gt;undefined&lt;/code&gt; in memory.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;console.log(x);&lt;/code&gt; at the top executes, printing undefined.&lt;/li&gt;
&lt;li&gt;When the execution reaches &lt;code&gt;x = 10;&lt;/code&gt;, it assigns &lt;code&gt;10&lt;/code&gt; to &lt;code&gt;x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The second &lt;code&gt;console.log(x);&lt;/code&gt; prints &lt;code&gt;10&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hoisting behavior explains why &lt;code&gt;console.log(x)&lt;/code&gt; doesn’t throw an error but prints undefined instead.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Doesn’t &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; Work the Same Way?
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(y); // ReferenceError: Cannot access 'y' before initialization
let y = 20;

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

&lt;/div&gt;


&lt;p&gt;Here, &lt;code&gt;y&lt;/code&gt; is hoisted, but it remains uninitialized in a &lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt; until the execution reaches &lt;code&gt;let y = 20;&lt;/code&gt;. This protects developers from accidental errors by ensuring variables cannot be accessed before assignment.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hoisting with Functions
&lt;/h2&gt;

&lt;p&gt;Unlike &lt;code&gt;var&lt;/code&gt;, function declarations are fully hoisted with their definitions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;greet(); // Output: Hello, World!

function greet() {
    console.log("Hello, World!");
}

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

&lt;/div&gt;



&lt;p&gt;JavaScript hoists the entire function definition, so calling &lt;code&gt;greet()&lt;/code&gt; before its declaration works perfectly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Hoisting moves variable and function declarations to the top of their scope before execution.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; variables are hoisted and initialized as &lt;code&gt;undefined&lt;/code&gt;, allowing access before declaration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are hoisted but remain uninitialized, causing a &lt;code&gt;ReferenceError&lt;/code&gt; if accessed before declaration.&lt;/li&gt;
&lt;li&gt;Function declarations are fully hoisted, meaning they can be called before being defined.&lt;/li&gt;
&lt;li&gt;Hoisting helps JavaScript interpret code efficiently but can lead to unexpected behavior if not understood properly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices to Avoid Hoisting Issues
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Always declare variables at the beginning of their scope.&lt;/li&gt;
&lt;li&gt;Prefer &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; over &lt;code&gt;var&lt;/code&gt; to avoid unintended &lt;code&gt;undefined&lt;/code&gt; values.&lt;/li&gt;
&lt;li&gt;Declare and initialize variables at the same time to avoid unexpected results.&lt;/li&gt;
&lt;li&gt;Use arrow function (&lt;code&gt;const func = () =&amp;gt; {}&lt;/code&gt;) instead of function declarations if you don’t want them to be hoisted.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Behind the Scenes of JavaScript: How Execution Works with Execution Context &amp; Call Stack</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Sat, 22 Mar 2025 04:18:08 +0000</pubDate>
      <link>https://dev.to/masudursourav/behind-the-scenes-of-javascript-how-execution-works-with-execution-context-call-stac-4bip</link>
      <guid>https://dev.to/masudursourav/behind-the-scenes-of-javascript-how-execution-works-with-execution-context-call-stac-4bip</guid>
      <description>&lt;p&gt;Since there’s a lot to cover, grab a coffee and stay focused! Each section connects to the next, so if you skip one, you might miss something important. Let’s dive in and make sense of it all together!&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution of JavaScript:
&lt;/h2&gt;

&lt;p&gt;JavaScript runs code one step at a time because it's a synchronous, single-threaded language. But how does it manage everything? &lt;/p&gt;

&lt;p&gt;It all comes down to the execution context, which is like a backstage manager for your code. JavaScript uses the call stack to keep track of what’s running. Every piece of code gets its own execution context, starting with a global execution context and adding temporary ones as needed.&lt;/p&gt;

&lt;p&gt;So, what exactly is an execution context, and how does it work? Let’s break it down! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Context in JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a container or box-like model consisting of two blocks. The first block manages memory allocation for variables and functions, using a key-value pair mapping. This is also known as the variable environment. The second block handles line-by-line code execution and is referred to as the thread of execution. It's important to note that JavaScript can only execute one line or command at a time. Upon running JavaScript code, an execution context is immediately created to facilitate program execution.&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%2Fdh5iqs44mm2ho1v80jr1.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%2Fdh5iqs44mm2ho1v80jr1.png" alt="Fig of Execution context of JS" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Memory block also known as Variable Environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code block also known as the thread of execution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example for in-depth exploration:&lt;br&gt;
Here I will use the example which is most commonly used to understand execution context of JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. var n = 2;
2. function square(num) {
3.         var squareValue = num * num;
4.         return squareValue;
5. }
6. var squareOfTwo = square(n);
7. var squareOfThree = square(3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execution context have two phases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Memory creation phase&lt;/li&gt;
&lt;li&gt;Code execution phase&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Here all variables name will be the key and stored on the memory as code execution isn't happened yet all the values of the variable will be &lt;code&gt;undefined&lt;/code&gt;. The functions name and body will be stored on the memory block as it is.&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%2F5prqnylqkde590lx8bb1.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%2F5prqnylqkde590lx8bb1.png" alt="Memory Creation Phase" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All variables value will be &lt;code&gt;undefined&lt;/code&gt; in this phase&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Functions will be stored in memory without any change of it's body.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;Phase 2: Code Execution&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Here all the command or statement of the code executed line by line top to bottom. While executing line by line it assign the value of the key in the memory block and skip the body of a function until it invoked on the code. Function is a beautiful entity in JavaScript. In JavaScript for every function there will be a function execution context or temporally execution context. &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%2Fcsxrjptf7rtt8thznz4j.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%2Fcsxrjptf7rtt8thznz4j.png" alt="Functional execution context" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we can see in that after executing the 1st line of the code n is not undefined anymore it gets replaced by 2.&lt;/p&gt;

&lt;p&gt;After executing 1st line the code execution skip the function and try to execute the 6th line and here this encounter a function invoke. So, as I said before a new functional or temporally execution context will be created. There will be also 2 phases as global execution context. When a functional execution context encounter a return the it get deleted from the call stack.&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%2Fsegpiiis3hx223sp5v28.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%2Fsegpiiis3hx223sp5v28.png" alt="Functional execution context" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, memory creation phase happened on functional execution context and as parameter also a variable of the function. Then it stored in memory as &lt;code&gt;undefined&lt;/code&gt; initially. After the memory creation phase the code execution phase start. The value of &lt;code&gt;num = n&lt;/code&gt; so, &lt;code&gt;num = 2&lt;/code&gt; and &lt;code&gt;squareValue = num * num&lt;/code&gt; so, &lt;code&gt;squareValue = 2 * 2 = 4&lt;/code&gt;.&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%2Fewe1auv3egq7x8cos1h8.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%2Fewe1auv3egq7x8cos1h8.png" alt="Functional execution context" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this on code execution in functional execution context encounter return. As I said previously if code execution in a function encounter return  the functional execution context of that function deleted immediately.So for our code the functional execution context get deleted and it returns the value to the global execution context. In the line of 6 after invoke the function we get the value of &lt;code&gt;squareOfTwo&lt;/code&gt; or &lt;code&gt;squareOfTwo = 4&lt;/code&gt;&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%2F1larbu3v7uddy0xqqgg7.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%2F1larbu3v7uddy0xqqgg7.png" alt="Functional execution context" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you know what happen while executing the 7th line of the code. Here, is another function invoke.Another functional execution context will be created and it will go through all two phases of execution context and finally get deleted. You can try it by your own. Now the mystery is how JavaScript handle all those complex global and functional execution? Simply with the call stack of JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Execution context with Call Stack:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Call Stack is like a to-do list for your code, built with execution contexts. Think of it as a stack of boxes. The bottom box is the Global Execution Context – the starting point. When a function runs, a new box (its Function Execution Context) gets stacked on top. Once that function finishes, its box is removed, or 'popped' off. This keeps happening until all function boxes are gone, and finally, the Global box is also removed, signaling the end of your program's run.&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%2F33royebvdu8xvafb140b.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%2F33royebvdu8xvafb140b.png" alt="Call stack of js" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this explanation helped you understand how JavaScript runs. It's like a neat little dance of boxes and lists, right? If you still don't think JavaScript is interesting, maybe you just haven't seen all it can do yet. Try learning more about it – you might find it's cooler than you thought.&lt;/p&gt;

&lt;p&gt;After this article read the article below to know about JavaScript hoisting :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/masudursourav/understanding-hoisting-in-javascript-why-can-we-use-var-before-declaration-3fio"&gt;Understanding Hoisting in JavaScript: Why Can We Use &lt;code&gt;var&lt;/code&gt; Before Declaration?&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How Make Text-Formatter with Download functionality with JS</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Wed, 05 Jan 2022 18:54:32 +0000</pubDate>
      <link>https://dev.to/masudursourav/how-make-text-formatter-with-download-functionality-with-js-408l</link>
      <guid>https://dev.to/masudursourav/how-make-text-formatter-with-download-functionality-with-js-408l</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%2Fs5m824wxxrk3kdpo85kv.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%2Fs5m824wxxrk3kdpo85kv.png" alt=" " width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey,&lt;br&gt;
Hope you all are doing good. Today we are going to learn how to make a Text-Formatter or Case converter with JS and little bit of HTML and CSS. First what is a text-formatter or case converter. It is a simple application which will format your text in a proper way. TextFormatter is the text engine that provides services for formatting text and breaking text lines. TextFormatter can handle different text character formats and paragraph styles, and includes support for international text layout. &lt;/p&gt;

&lt;p&gt;What we will need for this. We just need a input field and some button and we will write some logic with JS to make those proper. &lt;/p&gt;

&lt;p&gt;first start with the HTML.Here is my HTML code: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.html&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;&amp;lt;!Doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Case Converter&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;div class="title"&amp;gt;&amp;lt;h1&amp;gt;Case Converter&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div class="text"&amp;gt;
    &amp;lt;textarea&amp;gt;&amp;lt;/textarea&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div class="buttons"&amp;gt;
    &amp;lt;button id="upper-case"&amp;gt;Upper Case&amp;lt;/button&amp;gt;
    &amp;lt;button id="lower-case"&amp;gt;Lower Case&amp;lt;/button&amp;gt;
    &amp;lt;button id="proper-case"&amp;gt;Proper Case&amp;lt;/button&amp;gt;
    &amp;lt;button id="sentence-case"&amp;gt;Sentence Case&amp;lt;/button&amp;gt;
    &amp;lt;button id="save-text-file"&amp;gt;Save The File&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;script src="main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML looks so simple right? Yes, this project will also very easy for you. Let discuss about the HTML first. Here we have a textarea and five buttons. The first button which called Uppercase will convert all letters to uppercase. The button which called lowercase will convert all case to lower case .Proper case will make fist letter of every word capital or uppercase and Sentence case will make all the text to sentence case. What about the Save the file button ? With this you can download your converted text into a .txt file. &lt;/p&gt;

&lt;p&gt;We added our main.js file at script tag and we link our CSS style sheet with the link tag inside the head. I hope you understand what I did into the HTML file. &lt;/p&gt;

&lt;p&gt;Now we will add some style init.You can style your application how you like. Here is my style file:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;style.css&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;@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab&amp;amp;display=swap');
button{
    background-color: #FFA07A;
    padding: 0.7rem;
    border: none;
    border-radius: 0.3rem;
    margin: 1rem;
    font-size: large;
}
.buttons{
    text-align: center;
}
textarea{
    width: 70rem;
    height: 27rem;
    border-radius: 1rem;
    padding: 1rem;
    outline: none;
    font-size: 2rem;
    font-family: 'Roboto Slab', serif;
}
.text{
    text-align: center;
}
.title{
    text-align: center;
}
@media only screen and (max-width:  480px) {
    textarea{
     height: 10rem;
     width: 25rem;
    }
  }
  @media only screen and (max-width:  1080px) {
    textarea{
     height: 15rem;
     width: 30rem;
    }
  }

  @media only screen and (max-width:  1480px) {
    textarea{
     height: 45rem;
     width: 22rem;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I added some media query also I hope you know why we add media query. media query is for make the application or webpage responsive for many device. &lt;/p&gt;

&lt;p&gt;Now, Add some logic with JS or we can say add some brain to our application. Without brain human can't do anything neither our webpage or application. &lt;/p&gt;

&lt;p&gt;first we have to get the input from the user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let input = document.querySelector("textarea");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;by this we are selecting textarea to get data form here in future. After that it is time to add some functionality in our uppercase button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("upper-case").addEventListener("click",function (){
    let string = input.value;
    input.value = string.toUpperCase();
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here we used pre-built function is .toUpperCase() which make all letter of string to the uppercase.&lt;/p&gt;

&lt;p&gt;The lowercase button functionality also same&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("lower-case").addEventListener("click",function (){
     let string = input.value;
     input.value = string.toLowerCase();
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here we used pre-built function is .toLowerCase() which make all letter of string to the uppercase.&lt;/p&gt;

&lt;p&gt;Here the full of my JavaScript code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;main.js&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;let input = document.querySelector("textarea");
document.getElementById("upper-case").addEventListener("click",function (){
    let string = input.value;
    input.value = string.toUpperCase();
 });
 document.getElementById("lower-case").addEventListener("click",function (){
     let string = input.value;
     input.value = string.toLowerCase();
 });
 function properCase (str) {
     if ((str===null) || (str===''))
         return false;
     else
         str = str.toString();

     return str.replace(/\w\S*/g,
         function(txt){return txt.charAt(0).toUpperCase() +
             txt.substr(1).toLowerCase();});
 }

 document.getElementById("proper-case").addEventListener("click",function (){
     let string = input.value;
     let newString = properCase(string);
     input.value = newString;
 });

 function sentenceCase(theString) {
     let newString = theString.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});
     return newString;
 }
 document.getElementById("sentence-case").addEventListener("click",function (){
     let string = input.value;
     let newString = sentenceCase(string);
     input.value = newString;
 });

 function download(filename, text) {
     let element = document.createElement('a');
     element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
     element.setAttribute('download', filename);

     element.style.display = 'none';
     document.body.appendChild(element);

     element.click();

     document.body.removeChild(element);
 }
 document.getElementById("save-text-file").addEventListener("click",function () {
     let string = input.value;
     download("text.txt" , string);
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading this.&lt;/p&gt;

&lt;p&gt;My project's live site : &lt;a href="https://masudursourav.github.io/Case-Converter/" rel="noopener noreferrer"&gt;Live&lt;/a&gt;&lt;br&gt;
Project's Source file : &lt;a href="https://github.com/masudursourav/Case-Converter" rel="noopener noreferrer"&gt;Source&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Follow me on&lt;br&gt;&lt;br&gt;
 &lt;a href="https://twitter.com/knowsourav" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://www.linkedin.com/in/masudursourav/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://github.com/masudursourav" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://masudur.me/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Create a IP Finder Web Application With JS</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Sun, 02 Jan 2022 18:58:35 +0000</pubDate>
      <link>https://dev.to/masudursourav/how-to-create-a-ip-finder-web-application-with-js-4mac</link>
      <guid>https://dev.to/masudursourav/how-to-create-a-ip-finder-web-application-with-js-4mac</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%2Fx9lqfl58wj1jnu5jghhe.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%2Fx9lqfl58wj1jnu5jghhe.png" alt=" " width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey,&lt;br&gt;
If you are new in JavaScrip it will be interesting for you. Here you can learn to use API on JS. It will be a very very easy project for you. First you have to learn what is an API. API stands for Application Programming Interface pretty messy right but it is a fun thing. In easy way API will send you some data you just have to show them in your Webpage you have to just learn how to fetch a API and how to show the data on your webpage. If you want to learn more about the API just &lt;a href="https://www.youtube.com/watch?v=s7wmiS2mSXY" rel="noopener noreferrer"&gt;click here&lt;/a&gt; and watch the video. It will explain you in a easy way. But again you don't have to learn the internal processing of an API.&lt;/p&gt;

&lt;p&gt;First, We have to write some code for our HTML page. Here is a simple code which I used you can use this or write by your own :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Index.html&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;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Find Your IP&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div class="main-items"&amp;gt;
        &amp;lt;div class="main-text"&amp;gt;
            &amp;lt;h1&amp;gt;Here Is Your IP :&amp;lt;/h1&amp;gt;
            &amp;lt;h2 class="ip"&amp;gt;&amp;lt;/h2&amp;gt;
            &amp;lt;h1&amp;gt;Your ISP is :&amp;lt;/h1&amp;gt;
            &amp;lt;h2 class="isp"&amp;gt;&amp;lt;/h2&amp;gt;
            &amp;lt;h1&amp;gt;Your Location :&amp;lt;/h1&amp;gt;
            &amp;lt;h2 class="location"&amp;gt;&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will look so simple without any styles you probably know that HTML without CSS it almost like a man without cloths. So, let's put some cloths on our HTML webpage. HA! HA! HA!,&lt;br&gt;
Here is my CSS style file but here again you can style your own webpage in your own way. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;style.css&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;@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:ital,wght@1,500&amp;amp;display=swap');
body {
    font-family: 'Fira Sans', sans-serif;
    background-image: linear-gradient(90deg, rgba(2, 0, 36, 1) 0%, rgba(9, 9, 119, 1) 24%, rgba(9, 9, 121, 1) 35%, rgba(0, 212, 255, 1) 100%);
}

h1 {
    color: rgb(42, 81, 209);
}

.main-text {
    width: 25em;
    background-color: aliceblue;
    text-align: center;
    border: 1em solid rgb(73, 167, 230);
    border-radius: 2em;
}

.main-text h1 {
    margin: .5em;
}

.main-items {
    display: flex;
    justify-content: center;
    align-content: center;
    margin-top: 7em;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will add some brain on our webpage which call JavaScript. First we will have to fetch the API if you don't know how to fetch a API watch the video he explained this clearly &lt;a href="https://www.youtube.com/watch?v=cuEtnrL9-H0" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; . get your own API link from &lt;a href="https://www.ipify.org/" rel="noopener noreferrer"&gt;ipify&lt;/a&gt; . Then fetch the API in this way :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('Your URL provided by ipify')
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; changeTheDom(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here fetch getting response from ipify API and .json making this as json . Then you data is sending on changeTheDom function.&lt;/p&gt;

&lt;p&gt;Here the changeTheDom function code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function changeTheDom(data) {
    let IP = data.ip;
    let dom1 = document.querySelector('.ip');
    dom1.innerHTML = IP;
    let ISP = data.isp;
    let dom2 = document.querySelector('.isp');
    dom2.innerHTML = ISP;
    let dom3 = document.querySelector('.location');
    dom3.innerHTML = data.location.city + ' , ' + data.location.region + ' , ' + data.location.country;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this piece of function we are changing the DOM we are getting the ip element by data.ip. We selected the ip class by querySelector and replacing its innerHTML value with IP.And in this way we changed other values also. &lt;/p&gt;

&lt;p&gt;Thanks for reading .&lt;br&gt;
My project's live site : &lt;a href="https://masudursourav.github.io/Find-Your-IP-With-JS/" rel="noopener noreferrer"&gt;Live&lt;/a&gt;&lt;br&gt;
Project's Source file : &lt;a href="https://github.com/masudursourav/Find-Your-IP-With-JS" rel="noopener noreferrer"&gt;Source&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Follow me on&lt;br&gt;&lt;br&gt;
 &lt;a href="https://twitter.com/knowsourav" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://www.linkedin.com/in/masudursourav/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://github.com/masudursourav" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://masudur.me/" rel="noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>css</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
