<?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.us-east-2.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>Everything You Need To Know About DNS (Domain Name System)</title>
      <dc:creator>Masudur Rahman Sourav</dc:creator>
      <pubDate>Sat, 12 Sep 2026 15:48:54 +0000</pubDate>
      <link>https://dev.to/masudursourav/everything-you-need-to-know-about-dns-domain-name-system-40d7</link>
      <guid>https://dev.to/masudursourav/everything-you-need-to-know-about-dns-domain-name-system-40d7</guid>
      <description>&lt;p&gt;Imagine trying to memorize the phone number of every person you’ve ever met. Instead, you use a contacts app you type "Jhon," and your phone dials 555-0199. The Domain Name System (DNS) is the internet's contacts app. It translates human-friendly domain names (like netflix.com) into the machine-friendly IP addresses (like 192.0.2.1) that computers use to route data globally.&lt;/p&gt;

&lt;p&gt;The Real-World Analogy: Navigating a Mega-City&lt;br&gt;
Think of finding a website like searching for a specific specialty store in a massive, unfamiliar city:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local Cache&lt;/strong&gt;: First, you check your own pockets (Browser or OS cache) to see if you have the address written down from a previous visit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recursive Resolver&lt;/strong&gt;: If you don't, you ask a local hotel concierge ( ISP ) to find it for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Root Server&lt;/strong&gt;: The concierge doesn't know, so they call the city's central directory. The central directory points them to the commercial district manager.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLD Server&lt;/strong&gt;: The district manager (who handles all .com commerce) points the concierge to the building's specific property manager.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authoritative Server&lt;/strong&gt;: The property manager checks their official tenant ledger and gives the concierge the exact suite number.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fll1do8oq3nzivyigb2fm.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fll1do8oq3nzivyigb2fm.jpg" alt="The DNS resolution journey. Source: GodfriedEdelman / Getty Images" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Check Local Cache&lt;/strong&gt;:Browser and OS Level.&lt;/p&gt;

&lt;p&gt;Before asking the internet, your browser checks its own memory. If the IP isn't there, it asks your computer's Operating System cache. If you've visited the site recently, the journey ends here in milliseconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Query the Recursive Resolver&lt;/strong&gt;:Usually your ISP.&lt;/p&gt;

&lt;p&gt;If the OS doesn't know, it sends the request to a DNS Resolver (often run by your Internet Service Provider, or a public one like Google's 8.8.8.8). This server acts as your personal detective, taking on the heavy lifting of tracking down the IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Ask the Root Server&lt;/strong&gt;:The top of the internet hierarchy.&lt;/p&gt;

&lt;p&gt;The resolver asks one of the 13 logical Root Name Servers worldwide. The root server doesn't know the exact IP, but it reads the very end of your URL (the .com or .org part) and directs the resolver to the correct Top-Level Domain server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Ask the TLD Server&lt;/strong&gt;:Top-Level Domain Manager.&lt;/p&gt;

&lt;p&gt;The resolver now queries the specific .com TLD server. This server manages all .com domains globally. It checks its records for your specific domain name (e.g., netflix.com) and points the resolver to the domain's Authoritative Name Server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Query the Authoritative Name Server&lt;/strong&gt;:The final answer.&lt;/p&gt;

&lt;p&gt;The resolver reaches the Authoritative Name Server (managed by whoever hosts the domain's DNS, like AWS Route53 or Cloudflare). This server holds the exact, official DNS records. It hands over the final IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.Return and Cache&lt;/strong&gt;:Speeding up future visits.&lt;/p&gt;

&lt;p&gt;The resolver returns the IP address to your web browser so it can load the page. Crucially, the resolver, your OS, and your browser all save (cache) this answer for a set period known as the Time-to-Live (TTL)—to skip this entire process next time.&lt;/p&gt;
&lt;h2&gt;
  
  
  The DNS Record Toolkit
&lt;/h2&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhyrkh67676ggug836u95.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhyrkh67676ggug836u95.png" alt="The DNS Record Toolkit" width="800" height="729"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Why System Designers &amp;amp; Software Engineers Must Master DNS
&lt;/h2&gt;

&lt;p&gt;To an everyday user, DNS is just a lookup tool. To a system designer, DNS is the frontline traffic cop of a global architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Load Balancing and Latency&lt;/strong&gt; DNS isn't static. Advanced DNS setups use geolocation routing to analyze where a user is calling from. If a user in Tokyo requests your app, DNS can intelligently hand them the IP address of your Japanese data center, while giving a New York user the IP of your US East data center. This slashes latency before the user even connects to a server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;High Availability and Failover&lt;/strong&gt; If a hurricane takes out your primary data center, your app goes down. An engineer with strong DNS knowledge will configure automated health checks and failover routing. If the primary IP stops responding, the DNS server instantly stops giving out that IP and seamlessly redirects all new traffic to a backup facility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The TTL Trap (Time-to-Live)&lt;/strong&gt; Every DNS record has a TTL—a timer dictating how long devices should cache the answer. If a system designer is planning a major server migration but leaves the TTL set to 24 hours, users' browsers will stubbornly try to connect to the old, dead server for a full day. Mastering TTL is the difference between a zero-downtime migration and a catastrophic outage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Microservice Discovery&lt;/strong&gt; Inside modern cloud applications, hundreds of tiny, independent services (like a payment service and a shopping cart service) need to talk to each other. Because containers spin up and down constantly, their internal IP addresses change by the minute. Internal DNS allows "Service A" to find "Service B" simply by calling its name, completely abstracting away the chaotic IP swapping underneath.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security Posture&lt;/strong&gt; DNS is a major attack vector. Attackers use "DNS Spoofing" (cache poisoning) to trick a resolver into saving a fake IP address, silently redirecting your users to a malicious clone of your app. Engineers must understand how to implement DNSSEC (DNS Security Extensions) to cryptographically sign their records, guaranteeing users are truly talking to the authoritative source.&lt;/p&gt;
&lt;h2&gt;
  
  
  Security
&lt;/h2&gt;

&lt;p&gt;Imagine a world where anyone could swap out the street signs in your neighborhood. You try to drive to your bank, but a fake sign directs you to a perfect replica of the bank run by thieves. That’s the exact vulnerability built into the original design of DNS.&lt;/p&gt;

&lt;p&gt;Because DNS was built in the 1980s an era of high trust and low security it assumed every answer it received was honest. Today, system designers and engineers must build defenses against this assumption.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Threat: DNS Spoofing (Cache Poisoning)
&lt;/h2&gt;

&lt;p&gt;When your local resolver (like your ISP) asks the internet for the IP address of mybank.com, it waits for a response. In a DNS Spoofing attack, a hacker races to answer the resolver before the legitimate authoritative server can.&lt;/p&gt;

&lt;p&gt;If the hacker wins the race, they hand the resolver a fake IP address pointing to their malicious server. Worse, the resolver caches (memorizes) this fake answer. Now, every single person using that ISP who types in mybank.com is silently redirected to the hacker's fake login page.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjjhvnyxh1bgej80n6vke.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjjhvnyxh1bgej80n6vke.jpg" alt="DNS spoofing tricks resolvers into caching fake IP addresses.. Source: bsd studio / Getty Images" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Shield: DNSSEC (DNS Security Extensions)
&lt;/h2&gt;

&lt;p&gt;To stop someone from forging street signs, you need a way to prove who put the sign there. DNSSEC acts like a digital wax seal on every DNS answer.&lt;/p&gt;

&lt;p&gt;Instead of just returning the IP address (the A Record), a DNSSEC-enabled server returns the IP address and a cryptographic signature (the RRSIG record).&lt;/p&gt;

&lt;p&gt;Here is how the chain of trust works:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Zone Signing Key (ZSK)&lt;/strong&gt;: Your DNS provider uses a private key to mathematically sign your DNS records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Key Signing Key (KSK)&lt;/strong&gt;: To prove the ZSK is legitimate, a stronger key (the KSK) signs the ZSK.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Chain of Trust&lt;/strong&gt;: Your KSK is verified by the Top-Level Domain (like .com), which is verified by the Root Server.&lt;/p&gt;

&lt;p&gt;When a user's resolver receives the answer, it uses public keys to verify the signature. If a hacker tries to spoof the answer, they won't have your private key. The signature will fail, the resolver will reject the fake IP, and the user is protected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engineering Reality Check&lt;/strong&gt;: Implementing DNSSEC isn't a simple toggle switch. It requires careful key management. If your keys expire or roll over incorrectly, resolvers will reject your legitimate records, effectively deleting your website from the internet.&lt;/p&gt;
&lt;h2&gt;
  
  
  How DNS handles load balancing?
&lt;/h2&gt;

&lt;p&gt;If you build a blazing-fast application but host it exclusively in New York, a user in Tokyo will still experience a sluggish, frustrating delay. The speed of light is a hard physical limit, and every network hop adds latency.&lt;/p&gt;

&lt;p&gt;To solve this, system designers deploy applications globally and use two powerful DNS techniques to ensure users are always connected to the server closest to them: &lt;strong&gt;Geographic Routing&lt;/strong&gt; and &lt;strong&gt;DNS Anycast&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Geographic Routing (Geo-DNS): The Smart Operator
&lt;/h2&gt;

&lt;p&gt;Think of Geo-DNS like calling a national pizza delivery number. You dial one central number, but the system looks at your area code and connects you to the specific franchise five minutes from your house.&lt;/p&gt;

&lt;p&gt;Instead of an area code, Geo-DNS looks at the IP address of the user's recursive resolver.&lt;/p&gt;

&lt;p&gt;When the DNS query reaches your authoritative server, the server doesn't just hand out a static answer. Instead, it:&lt;/p&gt;

&lt;p&gt;Compares the user's IP against a massive, continuously updated GeoIP database.&lt;/p&gt;

&lt;p&gt;Determines the user is located in Tokyo.&lt;/p&gt;

&lt;p&gt;Looks at your routing policy and returns the specific IP address of your Tokyo data center, rather than your New York or London facilities.&lt;/p&gt;

&lt;p&gt;This happens at the application logic layer of DNS. The DNS server is actively making a decision to hand out &lt;strong&gt;different answers&lt;/strong&gt; (different IP addresses) based on who is asking.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/editor/Masudur-Rahman-Sourav/embed/01a09487-e14a-7afe-8ebd-aeca2ba865db?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  2. DNS Anycast: The Network Illusion
&lt;/h2&gt;

&lt;p&gt;If Geo-DNS is a smart operator handing out different addresses, Anycast is an illusion where multiple physical locations share the exact same address.&lt;/p&gt;

&lt;p&gt;Think of the emergency number "911". There isn't just one giant 911 call center for the entire country. There are thousands. But you dial the exact same number everywhere, and the underlying phone network routes you to the closest one.&lt;/p&gt;

&lt;p&gt;Anycast does this for IP addresses using the internet's core routing protocol, BGP (Border Gateway Protocol).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unicast (Standard)&lt;/strong&gt;: One IP address points to exactly one physical server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anycast&lt;/strong&gt;: Multiple physical servers across the globe announce to the internet that they are the destination for a single IP address (like Google's famous 8.8.8.8 DNS resolver).&lt;/li&gt;
&lt;/ul&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgfjx4n6tcnye9rrkf5ti.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgfjx4n6tcnye9rrkf5ti.png" alt="Unicast vs. Anycast network topology. Source: Brandsec" width="739" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a user's computer sends a packet to an Anycast IP, the internet's core routers look at the map and simply send the packet down the shortest physical path. The user naturally hits the server closest to them without the DNS server needing to perform any GeoIP lookups.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Engineers Love Anycast for Security
&lt;/h2&gt;

&lt;p&gt;Anycast isn't just about speed; it is the ultimate defense against Distributed Denial of Service (DDoS) attacks.&lt;/p&gt;

&lt;p&gt;If a massive botnet tries to flood a Unicast IP with malicious traffic, that single server gets overwhelmed and dies. If a botnet attacks an Anycast IP, the malicious traffic from a compromised computer in Brazil goes to the Brazilian server, while the attack traffic from Germany goes to the German server. The attack is naturally fragmented and absorbed by your global edge network, rather than concentrating on a single point of failure.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo41q6rvgjt977abaqqw3.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo41q6rvgjt977abaqqw3.png" alt="Engineers Love Anycast for Security" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How BGP Actually Calculates The Shortest Path?
&lt;/h2&gt;

&lt;p&gt;The internet is not a single, giant cloud; it is a massive patchwork quilt of smaller, independent networks. These networks run by ISPs (like Comcast or Vodafone), tech giants (like Google or AWS), and large universities—are called &lt;strong&gt;Autonomous Systems (AS)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you want to send data from an AS in London to an AS in Tokyo, you need a way to figure out which overlapping patches of the quilt to cross. That is exactly what &lt;strong&gt;BGP (Border Gateway Protocol)&lt;/strong&gt; does. It is the postal sorting system of the internet.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft3rtf6r4b6ta8nz0hgt8.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft3rtf6r4b6ta8nz0hgt8.jpg" alt="BGP connecting two Autonomous Systems (AS). Source: PyNet Labs" width="739" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How BGP Routes Traffic: The "AS Path"
&lt;/h2&gt;

&lt;p&gt;nside your home network, your router uses protocols that measure connection speeds, bandwidth, or latency to find the fastest path. BGP does not care about any of that.&lt;/p&gt;

&lt;p&gt;BGP is a &lt;strong&gt;Path Vector Protocol&lt;/strong&gt;. Its primary metric for determining the "best" or "shortest" route is simply counting the number of Autonomous Systems the data has to jump through. This list of hops is called the &lt;strong&gt;AS_PATH&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Announcement: A router in AS-500 tells its neighbor, "Hey, I can reach IP address 1.1.1.1."&lt;/li&gt;
&lt;li&gt;The Propagation: That neighbor (AS-400) tells its neighbor, "I can reach 1.1.1.1, and the path is [AS-400, AS-500]."&lt;/li&gt;
&lt;li&gt;The Decision: Your local ISP router (AS-100) might receive two announcements for 1.1.1.1.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Path A: &lt;a href="https://dev.to4%20hops"&gt; AS-200, AS-300, AS-400, AS-500 &lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Path B: &lt;a href="https://dev.to2%20hops"&gt; AS-600, AS-500 &lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your router looks at the AS_PATH length, sees that Path B has fewer hops, and updates its routing table to send all traffic for 1.1.1.1 toward AS-600.&lt;/p&gt;

&lt;h2&gt;
  
  
  BGP Meets Anycast: The Shortest Path Wins
&lt;/h2&gt;

&lt;p&gt;In a standard setup, only one AS in the world announces a specific IP address. But in an Anycast setup (used by Cloudflare, AWS Route53, and Google DNS), multiple data centers across the globe announce the exact same IP address simultaneously.&lt;/p&gt;

&lt;p&gt;Because BGP is fundamentally designed to find the shortest AS_PATH to a given destination, Anycast exploits this feature perfectly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Center A (New York) announces it hosts 8.8.8.8.&lt;/li&gt;
&lt;li&gt;Data Center B (Tokyo) announces it hosts 8.8.8.8.&lt;/li&gt;
&lt;li&gt;Data Center C (London) announces it hosts 8.8.8.8.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a user in Paris tries to reach 8.8.8.8, their ISP's BGP router looks at the global routing tables. It sees that the AS_PATH to London is only 2 hops, New York is 5 hops, and Tokyo is 8 hops. BGP automatically sends the Parisian user's traffic to London.&lt;/p&gt;

&lt;h2&gt;
  
  
  BGP Anycast Routing Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/editor/Masudur-Rahman-Sourav/embed/01a0962f-f4ef-74ea-8533-11a2fb0bdd9a?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Engineers Must Understand BGP
&lt;/h2&gt;

&lt;p&gt;While Anycast and BGP provide incredible resilience, they rely on a system built in 1989 that operates entirely on "trust."&lt;/p&gt;

&lt;p&gt;If an engineer misconfigures a BGP router in a small ISP in Brazil and accidentally announces, "I have a 1-hop path to Google's servers," the global internet might believe them. This is called a BGP Route Leak or BGP Hijacking. Traffic intended for Google will suddenly flood into that small Brazilian ISP, crashing their network and taking Google offline for millions of users.&lt;/p&gt;

&lt;p&gt;Understanding BGP means understanding that the internet's core routing is a fragile web of trust, and deploying Anycast requires extreme care in how you announce your IP addresses to the global backbone.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do we prevent BGP Hijacking?
&lt;/h2&gt;

&lt;p&gt;BGP was built on a handshake system if a router claims it owns an IP address, the rest of the internet generally believes it. This trust model is what enables a &lt;strong&gt;BGP Hijack&lt;/strong&gt;: a malicious (or misconfigured) network simply announces to the world, "I am the shortest path to Google's IP addresses." Without verification, global traffic blindly reroutes into the hijacker's network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RPKI (Resource Public Key Infrastructure)&lt;/strong&gt; is the cryptographic upgrade the internet needs to fix this. It replaces blind trust with mathematically verifiable proof of ownership.&lt;/p&gt;

&lt;h2&gt;
  
  
  How RPKI Secures the Route
&lt;/h2&gt;

&lt;p&gt;Think of RPKI like a digital passport control for BGP route announcements.&lt;/p&gt;

&lt;p&gt;Before an Autonomous System (AS) can legitimately announce an IP prefix to the internet, the true owner of that IP block must create a cryptographic certificate. This certificate is called a &lt;strong&gt;ROA (Route Origin Authorization)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A ROA explicitly states two things:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The IP Prefix&lt;/strong&gt;: (e.g., 192.0.2.0/24)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Origin AS&lt;/strong&gt;: The exact Autonomous System Number (e.g., AS65005) authorized to announce it.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd5hznrluz0892kw7yfrs.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd5hznrluz0892kw7yfrs.png" alt="RPKI uses ROAs to authorize route origins.. Source: phoenixNAP" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Route Origin Validation (ROV) in Action
&lt;/h2&gt;

&lt;p&gt;When a major ISP (like Comcast or AT&amp;amp;T) runs a BGP router with RPKI enforced, it performs &lt;strong&gt;Route Origin Validation (ROV)&lt;/strong&gt; on every announcement it receives.&lt;/p&gt;

&lt;p&gt;Here is how the router filters the traffic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Valid&lt;/strong&gt;: The BGP announcement says AS65005 originates 192.0.2.0/24. The router checks the global RPKI database, finds a matching ROA, and accepts the route. Traffic flows normally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invalid (The Hijack)&lt;/strong&gt;: A malicious network, AS65002, suddenly announces 192.0.2.0/24. The router checks the RPKI database. The ROA says only AS65005 is allowed to announce those IPs. The router instantly marks the malicious announcement as Invalid and drops it. The hijack is blocked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unknown&lt;/strong&gt;: If the IP owner hasn't created a ROA yet, the route is marked "Unknown." Most routers will still accept this to avoid breaking the internet, but they will prefer "Valid" routes if a conflict arises.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  BGP Hijack &amp;amp; RPKI Protection Simulator
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/editor/Masudur-Rahman-Sourav/embed/01a0963a-1660-7796-9942-e6f766a9b41e?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Why RPKI Matters to System Designers
&lt;/h2&gt;

&lt;p&gt;For a software engineer or system designer, understanding RPKI is critical for protecting the application layer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;DDoS Mitigation&lt;/strong&gt;: Attackers often use BGP route leaks to sinkhole your traffic or overwhelm a small segment of your network. Registering your IPs with strict ROAs ensures that major transit providers will drop malicious reroutes before they impact your users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compliance &amp;amp; Trust&lt;/strong&gt;: If you are designing fintech, healthcare, or government systems, traffic interception is a catastrophic breach. RPKI guarantees that your data physically reaches the correct data center and isn't silently diverted to a rogue network for packet sniffing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Fat Finger" Defense&lt;/strong&gt;: Most BGP leaks aren't malicious; they are typos by tired engineers. RPKI ensures that if an engineer at a regional ISP accidentally announces your IP space, the global internet will cryptographically reject the typo, preventing an accidental global outage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How BGP Relates To CDNs?
&lt;/h2&gt;

&lt;p&gt;Without a CDN, every single user across the globe has to travel to your one "Origin Server" (let's say, in New York) to fetch a website's images, videos, and HTML. A user in Sydney might wait 300 milliseconds just for the data to travel back and forth.&lt;/p&gt;

&lt;p&gt;CDNs like Cloudflare, Fastly, and Akamai solve this by building hundreds of mini data centers called Points of Presence (PoPs) or Edge Servers—in almost every major city on Earth. They tie all of these servers together using BGP Anycast.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3h0dg10ocbcixnt8yb1a.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3h0dg10ocbcixnt8yb1a.jpg" alt="CDNs deploy hundreds of Edge servers globally, all sharing the same Anycast IP.. Source: goleiro35 / Getty Images" width="799" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The CDN + Anycast Workflow
&lt;/h2&gt;

&lt;p&gt;When you put your application behind a CDN, you configure your DNS so that yourwebsite.com resolves to an Anycast IP address provided by the CDN (e.g., 104.16.124.96).&lt;/p&gt;

&lt;p&gt;Every single CDN Edge Server in the world announces to the internet that it is 104.16.124.96.&lt;/p&gt;

&lt;p&gt;Here is exactly what happens when a user in Sydney types in your URL:&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;BGP Routes to the Edge&lt;/strong&gt;:The Sydney user's ISP looks at the BGP routing tables. It sees that the shortest physical path to 104.16.124.96 is the CDN's Sydney Edge Server, not the one in New York or London. The user is instantly connected to a server in their own city.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Check the Cache (Cache Hit)&lt;/strong&gt;:Blazing fast response.The Sydney Edge Server checks its local hard drives: "Do I have a copy of &lt;a href="https://yourwebsite.com/logo.png" rel="noopener noreferrer"&gt;yourwebsite.com/logo.png&lt;/a&gt;?" If another user in Sydney recently loaded that image, the Edge Server will have it saved (a Cache Hit). It sends the image to the user in 10 milliseconds. The request never even touches your New York server.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Contact the Origin (Cache Miss)&lt;/strong&gt;:Fetching the master copy.If the Sydney Edge Server does not have the image (a Cache Miss), it acts as a proxy. The Edge Server opens a dedicated, high-speed connection back to your New York Origin Server, fetches the image, sends it to the user, and saves a copy for the next person in Sydney.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcc3famd4ysbhyirzc4y9.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcc3famd4ysbhyirzc4y9.png" alt="A Cache Miss requires a trip to the Origin, but subsequent requests are served from the Edge.. Source: RocketCDN" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why System Designers Rely on CDNs
&lt;/h2&gt;

&lt;p&gt;Deploying a CDN isn't just about making images load faster; it fundamentally changes the architecture and economics of scaling a global application.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdjl8p58ibvt5x8fsy0ad.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdjl8p58ibvt5x8fsy0ad.png" alt="Designers Rely on CDNs" width="800" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/editor/Masudur-Rahman-Sourav/embed/01a0964a-354f-7c4a-99ce-8422fbb20244?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>network</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <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>
