<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Umar Hayat</title>
    <description>The latest articles on Forem by Umar Hayat (@6116hayat).</description>
    <link>https://forem.com/6116hayat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1079478%2F3b976146-116c-434d-b4ed-e171128a8d84.jpg</url>
      <title>Forem: Umar Hayat</title>
      <link>https://forem.com/6116hayat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/6116hayat"/>
    <language>en</language>
    <item>
      <title>Control Flow in JavaScript: If, Else, and Switch</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sat, 28 Mar 2026 13:54:04 +0000</pubDate>
      <link>https://forem.com/6116hayat/control-flow-in-javascript-if-else-and-switch-e7n</link>
      <guid>https://forem.com/6116hayat/control-flow-in-javascript-if-else-and-switch-e7n</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey readers — welcome back 👋&lt;/p&gt;

&lt;p&gt;I hope you’re doing great. After learning about variables and operators, you now know how to store data and perform operations on it. Good. Solid foundation.&lt;/p&gt;

&lt;p&gt;By the way, this blog is part of the JavaScript series.&lt;/p&gt;

&lt;p&gt;If you haven’t checked them out yet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blog 1 — &lt;a href="https://dev.to/6116hayat/javascript-variables-and-data-types-explained-beginner-friendly-guide-2j62"&gt;JavaScript Variables&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Blog 2 — &lt;a href="https://dev.to/6116hayat/javascript-operators-the-basics-you-need-to-know-1nmk"&gt;JavaScript Operator&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we move to something more interesting.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll learn about the &lt;strong&gt;flow of a program&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And by flow, I mean &lt;strong&gt;control flow&lt;/strong&gt; — which is just a fancy way of saying &lt;em&gt;decision-making in code&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With flow of program I mean, control flow. Control flow is just a fancy term of decision making.&lt;/p&gt;

&lt;p&gt;In real life, we constantly make decisions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If it’s raining → take an umbrella.&lt;/li&gt;
&lt;li&gt;If marks are low → prepare for a lecture at home.&lt;/li&gt;
&lt;li&gt;If salary hits → order food.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Programs work the same way.&lt;/p&gt;

&lt;p&gt;We give them conditions.&lt;br&gt;
If the condition is satisfied, they respond with a specific action.&lt;/p&gt;

&lt;p&gt;Today, we’ll learn how to teach JavaScript to make decisions.&lt;/p&gt;

&lt;p&gt;Let’s go 🚀&lt;/p&gt;


&lt;h2&gt;
  
  
  🚦 What is Control Flow?
&lt;/h2&gt;

&lt;p&gt;Control Flow is the traffic director of programming — it determines which statements are executed in a program. &lt;/p&gt;

&lt;p&gt;Default nature of JavaScript is to execute from top to bottom. &lt;/p&gt;

&lt;p&gt;Control flow statements let us change the order, based on conditions, loops or keywords.&lt;/p&gt;

&lt;p&gt;Developers tend to manage control flow statements based on their output conditions. &lt;/p&gt;

&lt;p&gt;Whenever the conditions are matched, the program just branches out of the control flow and gets executed with result. &lt;/p&gt;
&lt;h3&gt;
  
  
  Simple Analogy:
&lt;/h3&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%2F1scpfpy3yq46ia5gustr.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%2F1scpfpy3yq46ia5gustr.png" alt="Choice Situation" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are various kinds of control flow statements for creating branches, we’ll discuss few upcoming topics. &lt;/p&gt;


&lt;h2&gt;
  
  
  🔍 The &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;if-else&lt;/code&gt; Statement
&lt;/h2&gt;
&lt;h3&gt;
  
  
  ⁜Basic &lt;code&gt;if&lt;/code&gt; Syntax
&lt;/h3&gt;

&lt;p&gt;Personally, it’s my favorite one. It feels like someone who overthinks everything.&lt;/p&gt;

&lt;p&gt;“What if this?”&lt;br&gt;
“What if that?”&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;if(...)&lt;/code&gt; statement evaluates a condition in parenthesis and, if the result is true, executes a block of code.&lt;/p&gt;

&lt;p&gt;Basic Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// code runs if condition is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;marks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;marks&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Congrats, your ass got saved from dad&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// my parents are stict 🥲&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The condition is &lt;code&gt;marks &amp;gt;= 40&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We check → is 35 greater than or equal to 40?&lt;/li&gt;
&lt;li&gt;The answer is false.&lt;/li&gt;
&lt;li&gt;So the code inside the block does not run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;The condition can get complex too — but let’s not scare ourselves yet.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⁜The &lt;code&gt;if - else&lt;/code&gt; Statement
&lt;/h3&gt;

&lt;p&gt;We can this as a modified version of the &lt;code&gt;if&lt;/code&gt; statement. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; clause gives the operation to do other things if the condition is falsy.&lt;/p&gt;

&lt;p&gt;Basic Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs if true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs if false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;marks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;marks&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Congrats, you passed!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Better luck next time... maybe bribe the professor with snacks?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// I'd to pass &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now we have two clear paths:&lt;/p&gt;

&lt;p&gt;→ Condition true → first block runs&lt;/p&gt;

&lt;p&gt;→ Condition false → &lt;code&gt;else&lt;/code&gt; block runs&lt;/p&gt;

&lt;p&gt;Only one of them executes.&lt;/p&gt;

&lt;p&gt;Let me give you another example…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// You playing FIFA with your friend&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;personWon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;friend&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Ouch!!&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;personWon&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;friend&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Blame the loss on lag, the controller, and the ref 🎮😤&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Boo him. Tease him. Screenshot the score. Eternal reminder activated 📸🔥&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Guess the output of this one…&lt;/p&gt;




&lt;h2&gt;
  
  
  🪜The &lt;code&gt;else if&lt;/code&gt; Ladder
&lt;/h2&gt;

&lt;p&gt;Besides &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt;, sometimes two conditions are just not enough.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if-else&lt;/code&gt; only gives us two paths.&lt;/p&gt;

&lt;p&gt;When we need multiple checks, we use the &lt;code&gt;else if&lt;/code&gt; ladder.&lt;/p&gt;

&lt;p&gt;Instead of writing many separate &lt;code&gt;if&lt;/code&gt; statements, we chain them together.&lt;/p&gt;

&lt;p&gt;The conditions are checked from top to bottom.&lt;/p&gt;

&lt;p&gt;As soon as JavaScript finds the first true condition, it runs that block — and stops checking further.&lt;/p&gt;

&lt;p&gt;Basic Syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs if condition1 is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs if condition2 is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// runs if none are true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favSuperHero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Spiderman&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favSuperHero&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Batman&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Personality Traits: Rich | Daring | Mysterious 🦇&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favSuperHero&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tony Stark&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Personality Traits: Cool | Tech Genius | Confident 🤖&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favSuperHero&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Spiderman&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Personality Traits: Funny | Responsible | Relatable 🕷️&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You didn’t choose a valid superhero.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code checks each condition one by one.&lt;/p&gt;

&lt;p&gt;Since the value is &lt;code&gt;"Spiderman"&lt;/code&gt;, it skips the first two and runs the third block.&lt;/p&gt;

&lt;p&gt;Order matters here.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;walletHasMoney&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;feeling&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;broke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;feeling&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;generous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;walletHasMoney&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tonight we feast like kings 👑&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;feeling&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;happy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;walletHasMoney&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fine. One snack each. Share properly.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;feeling&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sarcastic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I support you emotionally, not financially.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;walletHasMoney&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bro I’m one transaction away from homelessness.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Let’s pretend we already ate.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to figure out which condition becomes true.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 The &lt;code&gt;switch&lt;/code&gt; Statement
&lt;/h2&gt;

&lt;p&gt;When dealing with multiple conditions, we have another tool — the &lt;code&gt;switch&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;switch&lt;/code&gt; is often cleaner than writing many &lt;code&gt;else if&lt;/code&gt; statements, especially when checking one variable against many specific values.&lt;/p&gt;

&lt;p&gt;Basic Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expression&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;// code&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;// code&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nx"&gt;value3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;// code&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;// default code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;case&lt;/code&gt;&lt;/strong&gt; → Represents a possible value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;break&lt;/code&gt;&lt;/strong&gt; → Stops execution so the program doesn’t continue to the next case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;default&lt;/code&gt;&lt;/strong&gt; → Runs if no case matches (like &lt;code&gt;else&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Monday&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;day&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Monday&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Start of the week 😴&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Friday&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Weekend mood activated 🎉&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sunday&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rest day 😌&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Just another regular day.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript compares the value using strict equality (&lt;code&gt;===&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;day&lt;/code&gt; is &lt;code&gt;"Monday"&lt;/code&gt;, the first case runs.&lt;/p&gt;

&lt;p&gt;If we forget &lt;code&gt;break&lt;/code&gt;, execution continues to the next cases.&lt;/p&gt;

&lt;p&gt;This is called fall-through.&lt;/p&gt;

&lt;p&gt;If we forget &lt;code&gt;break&lt;/code&gt;, execution continues to the next case — and we will see output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Start&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;week&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;😴&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Weekend&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;mood&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;activated&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;🎉&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;day&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;😌&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🙃 Ending Thought
&lt;/h2&gt;

&lt;p&gt;Control flow is where JavaScript actually starts to feel alive. &lt;/p&gt;

&lt;p&gt;As real-life scenarios, we can now create decisions in our program. Until now, we were just creating variables and operating on them using operators. &lt;/p&gt;

&lt;p&gt;But with &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;else if&lt;/code&gt;, and &lt;code&gt;switch&lt;/code&gt;, we’re teaching our program &lt;strong&gt;how to think&lt;/strong&gt; — how to choose, react, and respond based on situations.&lt;/p&gt;

&lt;p&gt;Thing of it as telling the computer: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If this happens, do this.&lt;/p&gt;

&lt;p&gt;If not, try something else.&lt;/p&gt;

&lt;p&gt;And if nothing matches… handle it anyway.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  ➡️ What to do next?
&lt;/h3&gt;

&lt;p&gt;I would say, practice is the key. &lt;/p&gt;

&lt;p&gt;The more you practice control flow, the better your problem-solving mindset becomes. You’ll start seeing real-life situations in conditions and branches — and that’s when you know you’re growing as a developer.&lt;/p&gt;

&lt;p&gt;So keep experimenting.&lt;/p&gt;

&lt;p&gt;Break the code. Fix it. Reorder conditions. Remove a &lt;code&gt;break&lt;/code&gt; and see what happens.&lt;/p&gt;

&lt;p&gt;Till then, &lt;/p&gt;

&lt;p&gt;Keep Learning | Keep Breaking | Be Curious &lt;/p&gt;

&lt;p&gt;PEACE OUT ✌️&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Operators: The Basics You Need to Know</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Wed, 11 Mar 2026 10:22:28 +0000</pubDate>
      <link>https://forem.com/6116hayat/javascript-operators-the-basics-you-need-to-know-1nmk</link>
      <guid>https://forem.com/6116hayat/javascript-operators-the-basics-you-need-to-know-1nmk</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey readers — welcome to my corner of the internet.&lt;/p&gt;

&lt;p&gt;The last time we saw each other, we explored the basics of &lt;strong&gt;JavaScript variables and data types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/6116hayat/javascript-variables-and-data-types-explained-beginner-friendly-guide-2j62"&gt;Blog Link — Variables and Datatypes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started that blog from a complete beginner’s point of view, and honestly, that was intentional. When you’re learning JavaScript — or any programming language — your fundamentals matter a lot.&lt;/p&gt;

&lt;p&gt;Learning a new language can feel exciting, but sometimes it can also throw confusing concepts at you out of nowhere. If your basics aren’t clear, those concepts can knock you out pretty quickly.&lt;/p&gt;

&lt;p&gt;So instead of rushing ahead, we’re laying another strong foundation today.&lt;/p&gt;

&lt;p&gt;Let’s talk about &lt;strong&gt;Operators&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧰 Operators: The tools that work on your variables
&lt;/h2&gt;

&lt;p&gt;In the previous blog, we talked about &lt;strong&gt;variables as boxes that store values&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But storing something in a box is only half the story.&lt;/p&gt;

&lt;p&gt;Imagine keeping something in a box but never opening it or using what’s inside. That would feel like a waste, right?&lt;/p&gt;

&lt;p&gt;The same thing happens with variables in programming. They store data in memory — but we need a way to &lt;strong&gt;work with that stored data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;operators&lt;/strong&gt; come in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Operators&lt;/strong&gt; are special symbols or keywords that perform operations on values or variables — such as arithmetic, comparison, assignment, or logic.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Simple Analogy
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Variables = Boxes that store values&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operators = Tools that work on those values&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nc"&gt;Operands &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;       &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;Operator&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Operands are simply the &lt;strong&gt;values or variables that operators work on&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript has many types of operators, but we’ll focus on the most common ones that developers use every day.&lt;/p&gt;




&lt;h2&gt;
  
  
  ➕ Arithmetic Operators — Doing Math in JavaScript
&lt;/h2&gt;

&lt;p&gt;Alright, let’s start with something familiar.&lt;/p&gt;

&lt;p&gt;You’ve been using these since your &lt;strong&gt;school math days&lt;/strong&gt; — the good old arithmetic operators.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Arithmetic Operators&lt;/strong&gt; perform basic mathematical operations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These are the ones developers use all the time.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remainder (Modulus)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;leta&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;letb&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// addition&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 13&lt;/span&gt;

&lt;span class="c1"&gt;// subtraction&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 7&lt;/span&gt;

&lt;span class="c1"&gt;// multiplication&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 30&lt;/span&gt;

&lt;span class="c1"&gt;// division&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 3.33&lt;/span&gt;

&lt;span class="c1"&gt;// modulus → gives remainder of division&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let’s Focus on a Special One
&lt;/h3&gt;

&lt;h3&gt;
  
  
  ⇒ Modulus Operator &lt;code&gt;%&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;modulus operator&lt;/strong&gt; returns the &lt;strong&gt;remainder after division&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why 2?&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="nx"&gt;goes&lt;/span&gt; &lt;span class="nx"&gt;into&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="nx"&gt;two&lt;/span&gt; &lt;span class="nx"&gt;times&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="err"&gt;×&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;remainder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that remainder is what &lt;code&gt;%&lt;/code&gt; returns.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-world use case
&lt;/h3&gt;

&lt;p&gt;One common use of &lt;code&gt;%&lt;/code&gt; is checking &lt;strong&gt;even or odd numbers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Even numbers divide perfectly by 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;letnumber&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// true → number is even&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty useful, right?&lt;/p&gt;

&lt;p&gt;Now that we can &lt;strong&gt;calculate values&lt;/strong&gt;, let’s move on to comparing them.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Comparison Operators — Asking Questions in Code
&lt;/h2&gt;

&lt;p&gt;Comparison operators help our code &lt;strong&gt;ask questions&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Comparison Operators&lt;/strong&gt; compare two values and return a Boolean result — either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These are heavily used inside &lt;strong&gt;conditions and decision-making&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Common comparison operators include:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equal to&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;===&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Strict equal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;letmyAge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;letdogAge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myAge&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;dogAge&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I’m older than the dog 🐶&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Wait… is the dog older?!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;letcatFavorite&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fish&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;letofferedFood&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;broccoli&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;catFavorite&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="nx"&gt;offeredFood&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The cat gives you a judgmental stare 😾&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The cat is happy and purrs 🐱&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚠️ Important Concept: &lt;code&gt;==&lt;/code&gt; vs &lt;code&gt;===&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This is one of the &lt;strong&gt;first important JavaScript lessons beginners learn&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;==&lt;/code&gt; (Loose Equality)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Compares values&lt;/li&gt;
&lt;li&gt;Allows &lt;strong&gt;type conversion (type coercion)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript converts values internally before comparing them.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;===&lt;/code&gt; (Strict Equality)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Compares &lt;strong&gt;both value and type&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Does &lt;strong&gt;not&lt;/strong&gt; perform type conversion&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="c1"&gt;// false (number vs string)&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="c1"&gt;// false (number vs boolean)&lt;/span&gt;
&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practice
&lt;/h3&gt;

&lt;p&gt;Most developers prefer using &lt;code&gt;===&lt;/code&gt; because it avoids unexpected type conversions and keeps code predictable.&lt;/p&gt;

&lt;p&gt;So whenever possible, it’s safer to rely on &lt;strong&gt;strict equality&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Alright, now that we can compare values, let’s combine multiple conditions.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Logical &amp;amp; Assignment Operators — Making decisions and Updating Values
&lt;/h2&gt;




&lt;h3&gt;
  
  
  Logical Operators
&lt;/h3&gt;

&lt;p&gt;Logical operators help us &lt;strong&gt;combine conditions&lt;/strong&gt; and make decisions in code.&lt;/p&gt;

&lt;p&gt;They are commonly used with &lt;code&gt;if&lt;/code&gt; statements, loops, and other control flows.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&amp;amp;&amp;amp;&lt;/td&gt;
&lt;td&gt;AND&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if both operands are true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;!&lt;/td&gt;
&lt;td&gt;NOT&lt;/td&gt;
&lt;td&gt;Inverts the Boolean value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Life with mom 😭&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;momHome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;badGrades&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cleanedRoom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// AND&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;momHome&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;badGrades&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Mom is home AND you got bad grades = Trouble 😭&lt;/span&gt;

&lt;span class="c1"&gt;// OR&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;badGrades&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;cleanedRoom&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Bad grades OR messy room = Still trouble 😬&lt;/span&gt;

&lt;span class="c1"&gt;// NOT&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;cleanedRoom&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// NOT cleaned room = Mom is angry 🧹&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Logical operators make it possible to &lt;strong&gt;build complex conditions&lt;/strong&gt; in our programs.&lt;/p&gt;




&lt;h3&gt;
  
  
  Assignment Operators
&lt;/h3&gt;

&lt;p&gt;Now let’s talk about updating variables&lt;/p&gt;

&lt;p&gt;This is a basic assignment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the JavaScript has shortcuts that make this neater:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// same as score =  score + 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Common Assignment Operators:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Assign value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add and assign&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtract and assign&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;points&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;points&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;span class="nx"&gt;points&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These shortcuts make your code shorter and cleaner.&lt;/p&gt;




&lt;h2&gt;
  
  
  📝 Assignment Section
&lt;/h2&gt;




&lt;h3&gt;
  
  
  1️⃣ Perform arithmetic operations:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/*
Calculate:
i) a + b
ii) a - b
iii) a * b
iv) a % b

*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2️⃣ Compare values
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Observe the differences&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3️⃣ Logical condition
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hasTicket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;hasTicket&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// guess the output...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 Ending Thought
&lt;/h2&gt;

&lt;p&gt;Operators are the &lt;strong&gt;actions of JavaScript&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;They allow us to perform calculations, compare values, combine conditions, and update variables based on our needs.&lt;/p&gt;

&lt;p&gt;Without operators, variables would simply sit there in memory doing nothing.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;variables are boxes that store your data&lt;/strong&gt;, then &lt;strong&gt;operators are the tools you use to work with what’s inside those boxes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And once you start combining variables with the right operators, that’s when your programs actually start doing something useful.&lt;/p&gt;

&lt;p&gt;That’s it folks.&lt;/p&gt;

&lt;p&gt;Till then —&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KEEP LEARNING | BE CURIOUS | PEACE OUT ✌️&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>JavaScript Variables and Data Types Explained (Beginner-Friendly Guide)</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Thu, 26 Feb 2026 06:00:36 +0000</pubDate>
      <link>https://forem.com/6116hayat/javascript-variables-and-data-types-explained-beginner-friendly-guide-2j62</link>
      <guid>https://forem.com/6116hayat/javascript-variables-and-data-types-explained-beginner-friendly-guide-2j62</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey readers — welcome back to the series 👋&lt;/p&gt;

&lt;p&gt;Recently, I’ve been writing a lot of JavaScript code. And the more I understand it, the more fascinated I become.&lt;/p&gt;

&lt;p&gt;Trust me when I say this — JavaScript isn’t just an ordinary programming language. It feels like a side character in a TV show who got one unexpected chance to shine… and ended up becoming the hero.&lt;/p&gt;

&lt;p&gt;It’s not a perfect language. It has quirks. But the audacity of developers constantly improving it makes it powerful.&lt;/p&gt;

&lt;p&gt;Before we dive into &lt;strong&gt;JavaScript variables and data types&lt;/strong&gt;, let’s take a quick look at how it all started.&lt;/p&gt;

&lt;p&gt;Let’s get going 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧐 JavaScript and Its origins
&lt;/h2&gt;

&lt;p&gt;In its early days, JavaScript was created to serve browsers. It worked alongside HTML and CSS to make web pages interactive.&lt;/p&gt;

&lt;p&gt;Back then, it wasn’t designed for large applications. Many quick decisions were made — and some of those decisions caused strange behaviors. Later, these became known as &lt;strong&gt;JavaScript quirks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Everything changed in 2009 with the release of &lt;strong&gt;Node.js&lt;/strong&gt;. JavaScript moved beyond the browser and into backend development.&lt;/p&gt;

&lt;p&gt;Now developers could build full-fledged server-side applications using JavaScript.&lt;/p&gt;

&lt;p&gt;Today, JavaScript powers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend applications&lt;/li&gt;
&lt;li&gt;Backend systems&lt;/li&gt;
&lt;li&gt;Mobile apps&lt;/li&gt;
&lt;li&gt;Desktop applications&lt;/li&gt;
&lt;li&gt;Even smart devices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The language is standardized under &lt;strong&gt;ECMAScript&lt;/strong&gt; by &lt;strong&gt;ECMA International&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Despite its quirks, JavaScript keeps evolving — and it remains the language of the web.&lt;/p&gt;

&lt;p&gt;Now that you know the story, let’s have our first proper handshake with JavaScript by learning its key concepts:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Variables and Data Types in JavaScript&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 1. Variables — The “Boxes” That Store Information
&lt;/h2&gt;

&lt;p&gt;Most of the time, a JavaScript application needs to work on the information. &lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;💬 Chat Application — storing user info, messages, chat history&lt;/li&gt;
&lt;li&gt;🎮 Game — storing username, score, enemies defeated, power-ups collected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To work on such applications we use, variables. &lt;/p&gt;

&lt;h3&gt;
  
  
  Generic definition:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;variable&lt;/strong&gt; is a &lt;strong&gt;named container&lt;/strong&gt; used to store data values that can be referenced and manipulated in a program.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Simple analogy
&lt;/h3&gt;

&lt;p&gt;A variable is like a box of with a name tag. We put something inside (a value), and whenever we need it, we look inside the box.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why we need variables?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reuse data without rewriting it&lt;/li&gt;
&lt;li&gt;Track changes (e.g., user’s score)&lt;/li&gt;
&lt;li&gt;Make code readable and dynamic&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hayat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// stores text&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// stores a number&lt;/span&gt;
&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// updates the value (now age = 10)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ 2. Declaring Variables — &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;So far, we’ve understood what variables are and how they are used.&lt;/p&gt;

&lt;p&gt;Now, let’s look at the &lt;strong&gt;three ways to declare variables&lt;/strong&gt; in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var&lt;/code&gt; &lt;br&gt;
    - &lt;strong&gt;Can be redeclared&lt;/strong&gt; — We can declare the same variable again.&lt;br&gt;
    - &lt;strong&gt;Can be updated&lt;/strong&gt; — Values can be changed&lt;br&gt;
    - &lt;strong&gt;Function scoped&lt;/strong&gt; — Works inside a function, not block (&lt;code&gt;{}&lt;/code&gt;) scoped.&lt;br&gt;
    - &lt;strong&gt;Old way&lt;/strong&gt; — Used before ES6 (not used now)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```jsx
var x = 10; 
var x = 20; // allowed
x = 30; // allowed
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;code&gt;let&lt;/code&gt;&lt;br&gt;
    - &lt;strong&gt;Cannot be redeclared&lt;/strong&gt; — In the same scope&lt;br&gt;
    - &lt;strong&gt;Can be updated&lt;/strong&gt; — Value can be changed&lt;br&gt;
    - &lt;strong&gt;Blocked scoped&lt;/strong&gt; — Works only inside &lt;code&gt;{}&lt;/code&gt; block&lt;br&gt;
    - &lt;strong&gt;Modern way&lt;/strong&gt; — Introduced in ES6 (recommended)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```jsx
let y = 10;
y = 20; // allowed
// let y = 30; =&amp;gt; not allowed
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;code&gt;const&lt;/code&gt;&lt;br&gt;&lt;br&gt;
    - &lt;strong&gt;Cannot be redeclared&lt;/strong&gt; — In same scope&lt;br&gt;
    - &lt;strong&gt;Cannot be updated&lt;/strong&gt; — Value cannot changed&lt;br&gt;
    - &lt;strong&gt;Block scoped&lt;/strong&gt; — Same as &lt;code&gt;let&lt;/code&gt;.&lt;br&gt;
    - &lt;strong&gt;Best for fixed values&lt;/strong&gt; — Use when value should not change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```jsx
const z  = 10;
// z = 20; =&amp;gt; not allowed
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fd6abemcj9kygtzvallwm.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%2Fd6abemcj9kygtzvallwm.png" alt="JS Variables" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ⭐ Pro Tips:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Default to &lt;code&gt;const&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Always start by declaring variables with &lt;code&gt;const&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It prevents accidental reassignment&lt;/li&gt;
&lt;li&gt;Makes the code safer and predictable&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;let&lt;/code&gt; only when you know the value will change

&lt;ul&gt;
&lt;li&gt;If a variable need to be updated later&lt;/li&gt;
&lt;li&gt;Common in loops or counters&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Avoid using &lt;code&gt;var&lt;/code&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; is scoped, can cause unexpected behavior.&lt;/li&gt;
&lt;li&gt;Modern JavaScript prefers &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔤 3. Primitive Data Types — The Type of Data Inside the Box
&lt;/h2&gt;

&lt;p&gt;After declaring variables, the next step is understanding &lt;strong&gt;what kind of data&lt;/strong&gt; they store.&lt;/p&gt;

&lt;p&gt;A wise line from my mentor:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Writing code becomes easy when you know what datatype you are operating on.  ~ &lt;a href="https://x.com/Hiteshdotcom" rel="noopener noreferrer"&gt;Hitesh Choudhary&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are more data types in JavaScript, but we’ll focus on the essential ones.&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%2F0roagnzanccfhi94d6u7.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%2F0roagnzanccfhi94d6u7.png" alt="DataTypes" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Number
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;12.345&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bigInt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1234567890123456789012345678901234567890&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// bigInt (+ve|-ve)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number type represents both integer and floating-point numbers.&lt;/p&gt;

&lt;p&gt;There are many operations for numbers, e.g. &lt;code&gt;*&lt;/code&gt;, division &lt;code&gt;/&lt;/code&gt;, addition &lt;code&gt;+&lt;/code&gt;, subtraction &lt;code&gt;-&lt;/code&gt;, and so on.&lt;/p&gt;




&lt;h3&gt;
  
  
  String
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// double quotes&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;str2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Single quotes are ok too&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// single quotes&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;phrase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`can embed another &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Backticks (embed)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A string in JavaScript is a sequence of characters used to represent text.  Anything written inside quotes (&lt;code&gt;""&lt;/code&gt;, &lt;code&gt;''&lt;/code&gt;) is considered a string.&lt;/p&gt;




&lt;h3&gt;
  
  
  Boolean
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isHuman&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// yes is Human&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isAlien&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no, not an alien&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Boolean has only two values: &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. It is mainly used for decision making. {Explicitly no value}&lt;/p&gt;

&lt;p&gt;Boolean are used in: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conditional&lt;/li&gt;
&lt;li&gt;Comparison&lt;/li&gt;
&lt;li&gt;Logical&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Null
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yourPrivacy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="c1"&gt;// you don't have any privacy, sorry!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The null is special datatype which represents “nothing”, “empty” or “value unknown”. &lt;/p&gt;

&lt;p&gt;The above code states that &lt;code&gt;yourPrivacy&lt;/code&gt; is unknown.&lt;/p&gt;




&lt;h3&gt;
  
  
  Undefined
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;replyFromCrush&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// which is hard for me personally&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The undefined is also a special value and stands apart. It makes a type of its own just like null. &lt;/p&gt;

&lt;p&gt;Undefined means it has been declared but value has not been assigned.&lt;/p&gt;

&lt;p&gt;The above code states that &lt;code&gt;replyFromCrush&lt;/code&gt; exists but has no value.&lt;/p&gt;

&lt;p&gt;I have many other things today, but this is a blog, not a book so keeping things concise hehe. &lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 4. Understanding Scope — Where Your Variables Live
&lt;/h2&gt;

&lt;p&gt;This is one concept that quietly causes bugs if ignored.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generic definition:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt; determines where variables are accessible in your code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Simple Definition:
&lt;/h3&gt;

&lt;p&gt;Scope decides in which "room" a variable life and who can access it.&lt;/p&gt;




&lt;h3&gt;
  
  
  The house Analogy:
&lt;/h3&gt;

&lt;p&gt;Your program is a &lt;strong&gt;house&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;Each room is a scope. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The living room = Global Scope&lt;/li&gt;
&lt;li&gt;The bedroom = Function Scope&lt;/li&gt;
&lt;li&gt;The cupboard inside the bedroom = Block Scope&lt;/li&gt;
&lt;/ul&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;🏠 The Living Room (Global Scope)&lt;/p&gt;

&lt;p&gt;If you keep a TV in a living room:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sony&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// variable in Global Scope&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Everyone in the house can access it. &lt;/p&gt;

&lt;p&gt;✔️ Bedroom can access it &lt;/p&gt;

&lt;p&gt;✔️ Kitchen can access it&lt;/p&gt;

&lt;p&gt;✔️ Balcony can access it&lt;/p&gt;

&lt;p&gt;Because it's a global scope. &lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;🛏️ The Bedroom (Function Scope)&lt;/p&gt;

&lt;p&gt;Now inside the bedroom you keep a laptop.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bedroom&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;laptop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MacBook&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// variable inside a function scope&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Only people inside the bedroom can use this laptop. &lt;/p&gt;

&lt;p&gt;If someone in living room asks for laptop → Error because the laptop is inside that room only&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// console.log(laptop) =&amp;gt; ❌ Gives Error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;✔️ Bedroom can access laptop&lt;/p&gt;

&lt;p&gt;❌ Kitchen can’t access it&lt;/p&gt;

&lt;p&gt;❌ Balcony can’t access it&lt;/p&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3. 🗄️ The Cupboard (Block Scope)
&lt;/h3&gt;

&lt;p&gt;Inside the room, there’s a cupboard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bedroom&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secretMoney&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// variable in block scope&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The money stays inside the cupboard.&lt;/p&gt;

&lt;p&gt;✔ Accessible inside the cupboard&lt;br&gt;&lt;br&gt;
❌ Not accessible in the bedroom&lt;br&gt;&lt;br&gt;
❌ Not accessible in the living room  &lt;/p&gt;




&lt;h2&gt;
  
  
  The Rule
&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.amazonaws.com%2Fuploads%2Farticles%2Fc2alb0fru6adxsiq78d2.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%2Fc2alb0fru6adxsiq78d2.png" alt="House Analogy" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Things in the big room (global) → everyone can access
&lt;/li&gt;
&lt;li&gt;Things in the smaller room (function) → only inside the room
&lt;/li&gt;
&lt;li&gt;Things in the cupboard (block) → only inside that block&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🫧 Ending Thought
&lt;/h2&gt;

&lt;p&gt;That’s its folks — &lt;/p&gt;

&lt;h3&gt;
  
  
  🗝️ Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript is an amazing language, despite of being quirky.&lt;/li&gt;
&lt;li&gt;Variables are labelled boxes or say it as containers for data.&lt;/li&gt;
&lt;li&gt;Different versions for creating based on various purposes&lt;/li&gt;
&lt;li&gt;Primitive types define what kind of data you’re storing.&lt;/li&gt;
&lt;li&gt;Scope determines where a variable is accessible.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🚀 What to Do Next?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create your own variables.&lt;/li&gt;
&lt;li&gt;Experiment with &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Try different data types.&lt;/li&gt;
&lt;li&gt;Print results using &lt;code&gt;console.log()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Practice is where understanding becomes mastery.&lt;/p&gt;




&lt;p&gt;Till then, &lt;/p&gt;

&lt;p&gt;Stay Productive, Stay Curious!! Peach Out ✌️&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Thinking in JavaScript</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sun, 22 Feb 2026 04:39:24 +0000</pubDate>
      <link>https://forem.com/6116hayat/thinking-in-javascript-15me</link>
      <guid>https://forem.com/6116hayat/thinking-in-javascript-15me</guid>
      <description>&lt;p&gt;Hey fellow readers…&lt;/p&gt;

&lt;p&gt;Long time no see.&lt;/p&gt;

&lt;p&gt;Thank you all for the amazing response to the networking series. I didn’t know that even in this generation of AI and instant solutions, people would still prefer blogs for real knowledge.&lt;/p&gt;

&lt;p&gt;I guess quality content always finds its audience.&lt;/p&gt;

&lt;p&gt;With that incredible response, I’m starting another blog series on the topic mentioned above:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THINKING IN JS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This series will cover topics related to JavaScript like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables &amp;amp; Data Types&lt;/li&gt;
&lt;li&gt;Control Flow&lt;/li&gt;
&lt;li&gt;JavaScript Arrays — Advanced Arrays&lt;/li&gt;
&lt;li&gt;Functions — Arrow Functions&lt;/li&gt;
&lt;li&gt;And more along the way…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see where it takes us.&lt;/p&gt;

&lt;p&gt;Honestly speaking…&lt;/p&gt;

&lt;p&gt;I’m just a learner documenting my journey and learning through these series. I hope to provide the best resources and guide you through my blog.&lt;/p&gt;

&lt;p&gt;And if something goes off track, I know you’ve got my back — the comment section is always open.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding HTML Tags and Elements</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sat, 14 Feb 2026 11:09:44 +0000</pubDate>
      <link>https://forem.com/6116hayat/understanding-html-tags-and-elements-3b07</link>
      <guid>https://forem.com/6116hayat/understanding-html-tags-and-elements-3b07</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;🌟 Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hey Reader —&lt;/p&gt;

&lt;p&gt;Lately, I’ve been tight on schedule and barely finding time to publish blogs.&lt;/p&gt;

&lt;p&gt;But I’ve always believed something simple:&lt;/p&gt;

&lt;p&gt;If you truly love doing something, you’ll find a way.&lt;/p&gt;

&lt;p&gt;So here I am again — sharing another blog, this time about something people often underestimate… &lt;strong&gt;HTML&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Yes, HTML.&lt;/p&gt;

&lt;p&gt;Most people rush past it. They want React, Node, AI, Web3 — all the shiny stuff. But here’s the truth:&lt;/p&gt;

&lt;p&gt;If your HTML fundamentals are weak, everything built on top of it becomes shaky.&lt;/p&gt;

&lt;p&gt;And here’s something even more serious — writing clean, semantic HTML can save companies thousands of dollars in accessibility-related legal issues. Poor structure isn’t just messy — it can become a compliance problem.&lt;/p&gt;

&lt;p&gt;So today, let’s clear the fog.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🦴 HTML: The skeleton of web&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s start simple.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is HTML?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML (HyperText Markup Language) is not a programming language.&lt;/p&gt;

&lt;p&gt;It is a markup language used to structure content on the web.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of a webpage like a human body:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🦴 HTML → Skeleton (structure)&lt;/li&gt;
&lt;li&gt;🎨 CSS → Appearance (style)&lt;/li&gt;
&lt;li&gt;🧠 JavaScript → Behavior (logic)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without HTML, there is nothing to style or interact with.&lt;/p&gt;

&lt;p&gt;It defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Headings&lt;/li&gt;
&lt;li&gt;Paragraphs&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Links&lt;/li&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Sections&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short — it tells the browser what exists on the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Little History
&lt;/h3&gt;

&lt;p&gt;HTML was created in 1991 by Tim Berners-Lee while working at CERN.&lt;/p&gt;

&lt;p&gt;His goal wasn’t just formatting documents.&lt;/p&gt;

&lt;p&gt;He wanted a universal way to structure information and make it accessible across computer systems worldwide.&lt;/p&gt;

&lt;p&gt;It started as a tool for knowledge sharing.&lt;/p&gt;

&lt;p&gt;And today, it powers the entire web.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🧱 HTML tags: the building blocks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we understand why HTML matters, let’s zoom into the real stars — &lt;strong&gt;tags&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The very first version of HTML included only 18 tags like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; , &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h1&amp;gt; - &amp;lt;h6&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;,  &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Today, HTML has over 140 tags.&lt;/p&gt;

&lt;p&gt;Relax.&lt;br&gt;
You’ll regularly use maybe 20–30 of them.&lt;/p&gt;

&lt;p&gt;Basic Structure of a Tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;opening-tag&amp;gt;&lt;/span&gt; Content goes here &lt;span class="nt"&gt;&amp;lt;closing-tag&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; Hello World &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what’s happening:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; → Opening tag&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Hello World&lt;/code&gt; → Content&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; → Closing tag&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🔍Tag vs Elements: spot the difference&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Just remember the simple definition about them:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tags : A tag is the instruction written inside angle brackets.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Elements: An element is the complete structure:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me give a demonstration through simple Image:&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%2Fyt3bfoy5y8kf7xnhs8g4.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%2Fyt3bfoy5y8kf7xnhs8g4.png" alt="Tag Elements" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to know more about the Tags - Elements.&lt;/p&gt;

&lt;p&gt;Check out 👉 : &lt;a href="https://stackoverflow.com/questions/8937384/what-is-the-difference-between-html-tags-and-elements" rel="noopener noreferrer"&gt;What is the difference between HTML tags and elements? - Stack Overflow&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🏷️ Opening, Closing &amp;amp; Self-Closing Tags
&lt;/h2&gt;

&lt;p&gt;Let me explain more about Tags (btw I love to over express myself, hehehe)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Opening &amp;amp; Closing Tags

&lt;ul&gt;
&lt;li&gt;Consider a duo tags. (one in start &amp;amp; other at the end)&lt;/li&gt;
&lt;li&gt;Opening Tag: Starts an element. Written inside angle brackets. Example 
&lt;/li&gt;
&lt;li&gt;Closing Tag: Ends an element. Same as the opening tag but with a forward slash. Example &lt;/li&gt;
&lt;li&gt;Together, they wrap around content.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&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%2Fg9dfgqo96g9v91ko8zvm.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%2Fg9dfgqo96g9v91ko8zvm.png" alt="HTML Tag Structure" width="800" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Self Closing Tags 

&lt;ul&gt;
&lt;li&gt;Some tags don’t need a closing tag because they don’t wrap content.&lt;/li&gt;
&lt;li&gt;Example: &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; / &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; / &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&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%2F3bpbtrukbtbmft5x2m0l.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%2F3bpbtrukbtbmft5x2m0l.png" alt="HTML self" width="800" height="351"&gt;&lt;/a&gt;    &lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Common HTML Tags You Should Know
&lt;/h2&gt;

&lt;p&gt;Here are the essential ones every beginner must understand:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tag&lt;/th&gt;
&lt;th&gt;Usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;–&lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Headings (largest to smallest)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Paragraph&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Link&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Image&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Line break&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Unordered list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ordered list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List item&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Block container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inline container&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Master these first.&lt;/p&gt;

&lt;p&gt;Everything else builds from here.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;🎭 How elements behave&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;So, I can see you really getting the hang of the tags.&lt;/p&gt;

&lt;p&gt;No doubt that you got yourself an amazing writer 🙃&lt;/p&gt;

&lt;p&gt;In the browser blog, we understood how the HTML parser works and parses HTML. &lt;/p&gt;

&lt;p&gt;There are few HTML tags, where it forces the elements to behave differently on the screen. Let’s have a look at them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Block Elements:

&lt;ul&gt;
&lt;li&gt;Block elements always starts with new line&lt;/li&gt;
&lt;li&gt;It takes the full width of parent container&lt;/li&gt;
&lt;li&gt;Used for larger structures like sections, paragraphs, or headings&lt;/li&gt;
&lt;li&gt;Examples &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;–&lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Inline Elements:

&lt;ul&gt;
&lt;li&gt;Inline elements do not start with new line&lt;/li&gt;
&lt;li&gt;It takes as much width as the content&lt;/li&gt;
&lt;li&gt;Used for styling or linking small parts of text.&lt;/li&gt;
&lt;li&gt;Examples &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Quick Comparison
&lt;/h3&gt;

&lt;p&gt;Block → Full-width structure&lt;/p&gt;

&lt;p&gt;Inline → Small content inside structure&lt;/p&gt;

&lt;p&gt;Understanding this saves you from layout confusion later.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔎 Pro Tip: Inspect Real HTML
&lt;/h2&gt;

&lt;p&gt;Here’s something powerful.&lt;/p&gt;

&lt;p&gt;Right-click on any website → Click “Inspect”.&lt;/p&gt;

&lt;p&gt;You’ll see the actual HTML behind it.&lt;/p&gt;

&lt;p&gt;Browsers read HTML line by line and build a structure called the DOM (Document Object Model). That structure is what gets rendered on your screen.&lt;/p&gt;

&lt;p&gt;The internet is basically one giant open classroom.&lt;/p&gt;

&lt;p&gt;Use it.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;💡 Ending thought&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;That’s the foundation of HTML — simple, but powerful.&lt;/p&gt;

&lt;p&gt;People often underestimate it because it looks easy.&lt;/p&gt;

&lt;p&gt;But writing clean, semantic, well-structured HTML is a skill.&lt;/p&gt;

&lt;p&gt;It improves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accessibility&lt;/li&gt;
&lt;li&gt;SEO&lt;/li&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;li&gt;Maintainability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And yes — it can prevent legal headaches too.&lt;/p&gt;

&lt;p&gt;I’m still improving as a writer, just like you’re improving as a developer.&lt;/p&gt;

&lt;p&gt;We build step by step.&lt;/p&gt;

&lt;p&gt;Till then…&lt;/p&gt;

&lt;p&gt;Stay curious.&lt;/p&gt;

&lt;p&gt;Keep building.&lt;/p&gt;

&lt;p&gt;And respect the skeleton before decorating the body.&lt;/p&gt;

&lt;p&gt;PEACE OUT ✌️&lt;/p&gt;




</description>
      <category>tutorial</category>
      <category>learning</category>
      <category>beginners</category>
      <category>html</category>
    </item>
    <item>
      <title>How a Browser Works: A Beginner-Friendly Guide to Browser Internals</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Mon, 09 Feb 2026 07:48:46 +0000</pubDate>
      <link>https://forem.com/6116hayat/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals-p76</link>
      <guid>https://forem.com/6116hayat/how-a-browser-works-a-beginner-friendly-guide-to-browser-internals-p76</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;You know the funny thing about marathons?&lt;/p&gt;

&lt;p&gt;Once you survive a few, you start thinking you’re David Goggins.&lt;/p&gt;

&lt;p&gt;I just wrapped up a full networking series — DNS, IPs, connections, the whole deal.&lt;/p&gt;

&lt;p&gt;You can read it here:  &lt;a href="https://dev.to/6116hayat/networking-blog-series-recap-205j"&gt;Networking Blog Series Recap - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But there was one elephant in the room.&lt;/p&gt;

&lt;p&gt;We talked about &lt;strong&gt;how browsers connect&lt;/strong&gt; to the internet —&lt;/p&gt;

&lt;p&gt;never about &lt;strong&gt;how browsers actually show things on your screen&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That question bothered me.&lt;/p&gt;

&lt;p&gt;So if it bothered you too… welcome. 😄&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What a Browser Really Is
&lt;/h2&gt;

&lt;p&gt;We talk a lot about IPs, DNS, and servers.&lt;/p&gt;

&lt;p&gt;But what actually happens &lt;em&gt;inside&lt;/em&gt; the browser?&lt;/p&gt;




&lt;h3&gt;
  
  
  🧭 Browser ≠ Website Opener
&lt;/h3&gt;

&lt;p&gt;(More than just a website opener)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is a browser? &lt;br&gt;
A browser acts as a &lt;strong&gt;network client&lt;/strong&gt;, connecting users to servers and turning responses into visuals.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A browser is best thought of as a &lt;strong&gt;network client&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connects users to servers&lt;/li&gt;
&lt;li&gt;Requests data over the network&lt;/li&gt;
&lt;li&gt;Translates raw responses into something humans can understand&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So why isn’t a browser just a “website opener”? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It actively participates in networking&lt;/li&gt;
&lt;li&gt;Multiple internal components work together&lt;/li&gt;
&lt;li&gt;It acts as a bridge between &lt;strong&gt;client and server&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It turns text and files into visuals and interactions&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  ⌨️ Address bar → URL → request
&lt;/h3&gt;

&lt;p&gt;Let’s zoom into the simplest flow:&lt;/p&gt;

&lt;p&gt;Address bar → URL → Request → Response → Page&lt;/p&gt;

&lt;p&gt;Step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You type a URL in the address bar&lt;/li&gt;
&lt;li&gt;The browser sends a request to a server&lt;/li&gt;
&lt;li&gt;The server responds with data (HTML, CSS, JS, images)&lt;/li&gt;
&lt;li&gt;The browser processes that data and shows you a page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple on the surface.&lt;/p&gt;

&lt;p&gt;Wild underneath.&lt;/p&gt;




&lt;h3&gt;
  
  
  🏗️ Main parts of a browser (high-level overview)
&lt;/h3&gt;

&lt;p&gt;No jargon overload. Just the essentials.&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%2Fzssuqgw05y6yuhfm3dyx.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%2Fzssuqgw05y6yuhfm3dyx.png" alt="BroswerParts" width="800" height="695"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;🌐 Network Layer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handles all communication with servers&lt;/li&gt;
&lt;li&gt;Sends HTTP/HTTPS requests&lt;/li&gt;
&lt;li&gt;Receives HTML, CSS, JS, images&lt;/li&gt;
&lt;li&gt;Basically: the browser’s internet department&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  ⚙️ Browser Engine
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The coordinator of everything&lt;/li&gt;
&lt;li&gt;Passes data between:

&lt;ul&gt;
&lt;li&gt;Networking layer&lt;/li&gt;
&lt;li&gt;Rendering engine&lt;/li&gt;
&lt;li&gt;JavaScript engine&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Decides &lt;em&gt;what happens next&lt;/em&gt;
&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  🎨 Rendering Engine
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The main worker behind what you see&lt;/li&gt;
&lt;li&gt;Parses HTML and CSS&lt;/li&gt;
&lt;li&gt;Builds the DOM&lt;/li&gt;
&lt;li&gt;Paints pixels on the screen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this, the web would just be text files.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧩 JavaScript Engine
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Executes JavaScript code&lt;/li&gt;
&lt;li&gt;Enables interactivity and dynamic behavior&lt;/li&gt;
&lt;li&gt;Handles logic, events, and updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why websites feel alive.&lt;/p&gt;




&lt;h3&gt;
  
  
  📦 Data Storage
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Stores cookies, cache, and local data&lt;/li&gt;
&lt;li&gt;Helps pages load faster&lt;/li&gt;
&lt;li&gt;Prevents repeating expensive network work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yes, your browser remembers things. On purpose.&lt;/p&gt;




&lt;h3&gt;
  
  
  🖥️ User Interface (UI)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Address bar, tabs, buttons, bookmarks&lt;/li&gt;
&lt;li&gt;Everything you directly interact with&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The visible layer of a very invisible machine.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚙️ Browser Engine and Rendering engine
&lt;/h3&gt;

&lt;p&gt;They sound similar. They’re not.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Browser Engine&lt;/th&gt;
&lt;th&gt;Rendering Engine&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Role&lt;/td&gt;
&lt;td&gt;Coordinates the browser&lt;/td&gt;
&lt;td&gt;Draws the page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Focus&lt;/td&gt;
&lt;td&gt;Control, communication, flow&lt;/td&gt;
&lt;td&gt;Visual output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Handles&lt;/td&gt;
&lt;td&gt;Networking, UI, JS engine&lt;/td&gt;
&lt;td&gt;HTML, CSS, layout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Examples&lt;/td&gt;
&lt;td&gt;Blink, Gecko, WebKit&lt;/td&gt;
&lt;td&gt;WebCore, Gecko layout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output&lt;/td&gt;
&lt;td&gt;Decisions&lt;/td&gt;
&lt;td&gt;Pixels&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Browser engine&lt;/strong&gt; = manager&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rendering engine&lt;/strong&gt; = artist&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌐 How Browser understands Web Page
&lt;/h2&gt;

&lt;p&gt;(From internet files to structured meaning)&lt;/p&gt;

&lt;p&gt;Ever wondered what happens &lt;em&gt;after&lt;/em&gt; the browser receives files?&lt;/p&gt;

&lt;p&gt;How does code turn into structure?&lt;/p&gt;




&lt;h3&gt;
  
  
  📡 How HTML, CSS, and JS are fetched
&lt;/h3&gt;

&lt;p&gt;Let’s keep this &lt;strong&gt;super simple&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The core flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser fetches HTML, CSS, JS&lt;/li&gt;
&lt;li&gt;HTML is parsed → DOM&lt;/li&gt;
&lt;li&gt;CSS is parsed → CSSOM&lt;/li&gt;
&lt;li&gt;DOM + CSSOM → Render Tree&lt;/li&gt;
&lt;li&gt;Layout &amp;amp; paint → pixels on screen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s the browser lifecycle in five steps.&lt;/p&gt;




&lt;h3&gt;
  
  
  📄 Turning HTML into DOM
&lt;/h3&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%2Flfwgby3usqb5fk9vhwsx.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%2Flfwgby3usqb5fk9vhwsx.png" alt="HTMLdom" width="800" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DOM (Document Object Model)&lt;br&gt;
A tree-line structure representing HTML&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Becomes a tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="err"&gt;└──&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="err"&gt;└──&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rendering engine builds this structure while parsing HTML.&lt;/p&gt;

&lt;p&gt;Fun fact:&lt;br&gt;
HTML parsing is forgiving.&lt;br&gt;
Errors don’t crash the browser — they get handled gracefully.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎨 Turning CSS into CSSOM
&lt;/h3&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%2Fq3ue5nm5krtvyg1ckqp7.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%2Fq3ue5nm5krtvyg1ckqp7.png" alt="CSSOM" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;CSSOM (CSS Object Model)&lt;/strong&gt;:&lt;br&gt;
 Another tree structure, but for styles.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```css
h1 { color: red; font-size: 20px; }
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Becomes rules like:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```powershell
h1
 ├── color: red
 └── font-size: 20px
```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How it happens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser finds the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag&lt;/li&gt;
&lt;li&gt;Fetches the CSS file&lt;/li&gt;
&lt;li&gt;Parses it into the CSSOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Styles now have structure.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧮 What parsing means (simple Example)
&lt;/h3&gt;

&lt;p&gt;I’ve used the word &lt;em&gt;parsing&lt;/em&gt; a lot — time to demystify it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parsing&lt;/strong&gt; means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Converting raw text into a structured format a computer can understand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just like how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A sentence has grammar&lt;/li&gt;
&lt;li&gt;A math expression has structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Parsing turns chaos into meaning.&lt;/p&gt;

&lt;p&gt;Not magic. Just rules.&lt;/p&gt;




&lt;h2&gt;
  
  
  🖥️ How a Page Is Drawn on the screen
&lt;/h2&gt;

&lt;p&gt;(Turning structure into pixels)&lt;/p&gt;

&lt;p&gt;This is where everything comes together.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔗 How DOM and CSSOM work together
&lt;/h3&gt;

&lt;p&gt;Think like a developer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML = skeleton&lt;/li&gt;
&lt;li&gt;CSS = makeup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or more formally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOM = structure&lt;/li&gt;
&lt;li&gt;CSSOM = style&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;DOM + CSSOM = Render Tree&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Render Tree&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;You may I ask what is render tree&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Render Tree&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contains only visible elements&lt;/li&gt;
&lt;li&gt;Knows what goes where&lt;/li&gt;
&lt;li&gt;Knows what color, size, and style&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It updates whenever DOM or CSSOM changes.&lt;/p&gt;




&lt;h3&gt;
  
  
  📐 How layout decides size and position
&lt;/h3&gt;

&lt;p&gt;First step of rendering.&lt;/p&gt;

&lt;p&gt;Browser calculates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Element sizes&lt;/li&gt;
&lt;li&gt;Positions&lt;/li&gt;
&lt;li&gt;Spacing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This process is called &lt;strong&gt;layout&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When something changes (resize, DOM update):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Layout recalculates&lt;/li&gt;
&lt;li&gt;This is called &lt;strong&gt;reflow&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🖌️ How painting adds colors and text
&lt;/h3&gt;

&lt;p&gt;Second step of rendering.&lt;/p&gt;

&lt;p&gt;Now the browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applies colors&lt;/li&gt;
&lt;li&gt;Draws text&lt;/li&gt;
&lt;li&gt;Adds borders, shadows, images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of sketch → then coloring.&lt;/p&gt;




&lt;h3&gt;
  
  
  🟦 How everything finally shows up on screen
&lt;/h3&gt;

&lt;p&gt;Final step.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Layers are combined&lt;/li&gt;
&lt;li&gt;Pixels are pushed to the screen&lt;/li&gt;
&lt;li&gt;Page becomes visible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And this process can happen &lt;strong&gt;many times per second&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Browsers are fast. Like, scary fast.&lt;/p&gt;




&lt;h2&gt;
  
  
  ☺️ Ending Thought
&lt;/h2&gt;

&lt;p&gt;Browsers were ignored for a long time — treated as just tools.&lt;/p&gt;

&lt;p&gt;But once you understand what’s happening underneath,&lt;/p&gt;

&lt;p&gt;you realize they’re more like &lt;strong&gt;operating systems for the web&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;One of my teachers once said:&lt;/p&gt;

&lt;p&gt;I would like to quote my teacher here&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Browsers are so powerful that plain HTML is enough to light up pixels on a screen.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And honestly…&lt;/p&gt;

&lt;p&gt;That &lt;em&gt;is&lt;/em&gt; kind of magical.&lt;/p&gt;

&lt;p&gt;That’s it, folks —&lt;/p&gt;

&lt;p&gt;see you in the next marathon 🏃‍♂️&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>learning</category>
      <category>beginners</category>
      <category>browser</category>
    </item>
    <item>
      <title>Networking Blog Series Recap</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sat, 31 Jan 2026 20:34:25 +0000</pubDate>
      <link>https://forem.com/6116hayat/networking-blog-series-recap-205j</link>
      <guid>https://forem.com/6116hayat/networking-blog-series-recap-205j</guid>
      <description>&lt;p&gt;Oh boii!! 😄&lt;br&gt;&lt;br&gt;
That was one &lt;strong&gt;heck of a blog marathon&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is my &lt;strong&gt;first-ever tech blog series&lt;/strong&gt;, and I went straight for networking—because why not start with &lt;em&gt;the thing that literally connects the entire world&lt;/em&gt;, right?&lt;/p&gt;

&lt;p&gt;This series is a journey.&lt;br&gt;&lt;br&gt;
Not just definitions and diagrams, but imagining &lt;strong&gt;how devices talk&lt;/strong&gt;, how packets travel, how DNS plays matchmaker, and how the internet quietly runs our lives while we’re busy doom-scrolling.&lt;/p&gt;

&lt;p&gt;If you’ve ever wondered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What actually happens when you type a URL?&lt;/li&gt;
&lt;li&gt;Why TCP insists on handshakes like a polite human 🤝&lt;/li&gt;
&lt;li&gt;Why UDP just… sends it and moves on 🚀&lt;/li&gt;
&lt;li&gt;What &lt;code&gt;curl&lt;/code&gt; is really doing behind that terminal command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then yeah—this series is for you.&lt;/p&gt;

&lt;p&gt;If you’re done with &lt;strong&gt;“internet magic ✨” explanations&lt;/strong&gt; and want to understand the &lt;em&gt;real plumbing&lt;/em&gt; behind the web, dive in 👇&lt;/p&gt;

&lt;h2&gt;
  
  
  📘 Networking Blog Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blog 1:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Understanding Network Devices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 2:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS Resolution Works&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 3:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/dns-record-types-explained-2m7g"&gt;DNS Record Types Explained&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 4:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c"&gt;TCP vs UDP: When to Use What, and How TCP Relates to HTTP&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 5:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-577"&gt;TCP 3-Way Handshake&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 6:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/getting-started-with-curl-423k"&gt;Getting Started with cURL&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My goal is simple:&lt;br&gt;&lt;br&gt;
to turn &lt;strong&gt;“the internet just works”&lt;/strong&gt; into &lt;strong&gt;“ohhh… &lt;em&gt;that’s&lt;/em&gt; how it works.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If even one person walks away less confused and more curious, mission accomplished 🚀&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%2Fww9n1i5ckdn0siws2957.gif" 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%2Fww9n1i5ckdn0siws2957.gif" alt="Gojo" width="450" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>learning</category>
      <category>beginners</category>
      <category>networking</category>
    </item>
    <item>
      <title>Networking Blog Series Recap</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sat, 31 Jan 2026 20:34:25 +0000</pubDate>
      <link>https://forem.com/6116hayat/networking-blog-series-recap-5561</link>
      <guid>https://forem.com/6116hayat/networking-blog-series-recap-5561</guid>
      <description>&lt;p&gt;Oh boii!! 😄&lt;br&gt;&lt;br&gt;
That was one &lt;strong&gt;heck of a blog marathon&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is my &lt;strong&gt;first-ever tech blog series&lt;/strong&gt;, and I went straight for networking—because why not start with &lt;em&gt;the thing that literally connects the entire world&lt;/em&gt;, right?&lt;/p&gt;

&lt;p&gt;This series is a journey.&lt;br&gt;&lt;br&gt;
Not just definitions and diagrams, but imagining &lt;strong&gt;how devices talk&lt;/strong&gt;, how packets travel, how DNS plays matchmaker, and how the internet quietly runs our lives while we’re busy doom-scrolling.&lt;/p&gt;

&lt;p&gt;If you’ve ever wondered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What actually happens when you type a URL?&lt;/li&gt;
&lt;li&gt;Why TCP insists on handshakes like a polite human 🤝&lt;/li&gt;
&lt;li&gt;Why UDP just… sends it and moves on 🚀&lt;/li&gt;
&lt;li&gt;What &lt;code&gt;curl&lt;/code&gt; is really doing behind that terminal command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then yeah—this series is for you.&lt;/p&gt;

&lt;p&gt;If you’re done with &lt;strong&gt;“internet magic ✨” explanations&lt;/strong&gt; and want to understand the &lt;em&gt;real plumbing&lt;/em&gt; behind the web, dive in 👇&lt;/p&gt;

&lt;h2&gt;
  
  
  📘 Networking Blog Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blog 1:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Understanding Network Devices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 2:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS Resolution Works&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 3:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/dns-record-types-explained-2m7g"&gt;DNS Record Types Explained&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 4:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c"&gt;TCP vs UDP: When to Use What, and How TCP Relates to HTTP&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 5:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-577"&gt;TCP 3-Way Handshake&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blog 6:&lt;/strong&gt; &lt;a href="https://dev.to/6116hayat/getting-started-with-curl-423k"&gt;Getting Started with cURL&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My goal is simple:&lt;br&gt;&lt;br&gt;
to turn &lt;strong&gt;“the internet just works”&lt;/strong&gt; into &lt;strong&gt;“ohhh… &lt;em&gt;that’s&lt;/em&gt; how it works.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If even one person walks away less confused and more curious, mission accomplished 🚀&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%2Fww9n1i5ckdn0siws2957.gif" 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%2Fww9n1i5ckdn0siws2957.gif" alt="Gojo" width="450" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>learning</category>
      <category>beginners</category>
      <category>networking</category>
    </item>
    <item>
      <title>Getting Started with cURL</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Sat, 31 Jan 2026 17:14:29 +0000</pubDate>
      <link>https://forem.com/6116hayat/getting-started-with-curl-423k</link>
      <guid>https://forem.com/6116hayat/getting-started-with-curl-423k</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey reader — welcome back 👋&lt;/p&gt;

&lt;p&gt;I tried to change the NPC line… but failed again 🙄&lt;/p&gt;

&lt;p&gt;This is my &lt;strong&gt;9th and final blog&lt;/strong&gt; in the Networking series, and honestly, it’s been a great learning experience for me too. The goal of this series was simple:&lt;/p&gt;

&lt;p&gt;to understand the &lt;strong&gt;gears and mechanisms behind something as simple as a search working&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you’ve been following along from the start — that’s amazing 🙌&lt;/p&gt;

&lt;p&gt;If not, no worries. These blogs are always here to help you build a solid foundation in networking.&lt;/p&gt;

&lt;p&gt;Blog 1:  &lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Understanding Network Devices - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 2: &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS Resolution Works - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 3: &lt;a href="https://dev.to/6116hayat/dns-record-types-explained-2m7g"&gt;DNS Record Types Explained - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 4: &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c"&gt;TCP vs UDP: When to Use What, and How TCP Relates to HTTP - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 5: &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-577"&gt;TCP 3-way Handshake - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this final blog, I’ll introduce you to another tool — &lt;strong&gt;just like &lt;code&gt;dig&lt;/code&gt;&lt;/strong&gt; — that developers absolutely love: &lt;strong&gt;cURL&lt;/strong&gt;. &lt;/p&gt;




&lt;h2&gt;
  
  
  💻 How we talk to Servers?
&lt;/h2&gt;

&lt;p&gt;In the previous blogs, we learned how data travels from &lt;strong&gt;LAN → WAN&lt;/strong&gt;, the devices involved, how domain names map to IP addresses, and how TCP and UDP work.&lt;/p&gt;

&lt;p&gt;Now it’s time to focus on &lt;strong&gt;how we actually talk to servers&lt;/strong&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%2F7ojqssnly9dwhqecapc1.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%2F7ojqssnly9dwhqecapc1.png" alt="Client-Server" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🗄️ What Is a Server?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A server is a computer that provides information or services to other computers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In today’s world, every app or service you use — Instagram, Google, Netflix — runs on servers somewhere.&lt;/p&gt;

&lt;p&gt;Your phone or laptop acts as a &lt;strong&gt;client&lt;/strong&gt;, requesting data from these servers.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧑 Client → Server → Response
&lt;/h3&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You open a website&lt;/li&gt;
&lt;li&gt;Your browser sends a request to a web server&lt;/li&gt;
&lt;li&gt;The server sends a response back&lt;/li&gt;
&lt;li&gt;Your browser displays it for you&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That request–response cycle is the backbone of the internet.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 Using cURL to Talk to a Server
&lt;/h2&gt;

&lt;p&gt;Developers often need to communicate with servers &lt;strong&gt;without a browser&lt;/strong&gt; — for testing, debugging, or understanding raw responses.&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;cURL&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;h2&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%2Ft0894hi6zfdo1sgbioua.png" alt="cURL" width="800" height="566"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ⚙️ What Is cURL?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;cURL (Client URL) is a command-line tool that lets a client (your computer) communicate with a server using a URL to fetch or send data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cURL runs in your terminal&lt;/li&gt;
&lt;li&gt;It sends requests to servers&lt;/li&gt;
&lt;li&gt;It shows you the raw responses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use it to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch web pages&lt;/li&gt;
&lt;li&gt;Download files&lt;/li&gt;
&lt;li&gt;Test APIs&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔬 Your First cURL command
&lt;/h3&gt;

&lt;p&gt;Let’s try a simple example.&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%2F5yl7na6zvjo830r7f21i.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%2F5yl7na6zvjo830r7f21i.png" alt="cURL -I" width="606" height="34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What this means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;curl&lt;/code&gt; → invokes the tool&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; → fetches only the response headers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http://www.google.com&lt;/code&gt; → the target URL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sends a request to Google’s server&lt;/li&gt;
&lt;li&gt;Receives a response containing:

&lt;ul&gt;
&lt;li&gt;Status code (like &lt;code&gt;200 OK&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Headers (metadata about the response)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;The response will look something like this:&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%2Fyuwsbwt1xefo8j0olf7h.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%2Fyuwsbwt1xefo8j0olf7h.png" alt="cURL-Resp" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🎉 A Fun cURL Example
&lt;/h2&gt;

&lt;p&gt;Try this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;curl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ascii.live/parrot&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;//ascii.live/parrot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy-paste it into your terminal…&lt;/p&gt;

&lt;p&gt;and boom — you’ll see a &lt;strong&gt;parrot dancing&lt;/strong&gt;🦜💃&lt;/p&gt;

&lt;p&gt;To stop the madness, press &lt;strong&gt;CTRL + C&lt;/strong&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%2Fadcmlpyfs563bivmbwq6.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%2Fadcmlpyfs563bivmbwq6.png" alt="cURL parrot" width="626" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More info here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/hugomd/ascii-live" rel="noopener noreferrer"&gt;GitHub – ascii-live&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, cURL can be fun too.&lt;/p&gt;




&lt;h2&gt;
  
  
  📃 cURL and API’s
&lt;/h2&gt;

&lt;p&gt;Now let’s talk about APIs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An API (Application Programming Interface) is a server designed to communicate with programs instead of people.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&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%2Fjeqgj7djoqhhplsc122y.png" alt="API-req" width="800" height="725"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔑 Basic API Requests with cURL
&lt;/h3&gt;

&lt;h3&gt;
  
  
  GET — Receive Data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.example.com/users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fetches a list of users from the API.&lt;/p&gt;




&lt;h3&gt;
  
  
  POST — Send Data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST https://api.example.com/users &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-H&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-d&lt;/span&gt;&lt;span class="s1"&gt;'{"name":"Alice","age":25}'&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This sends new user data to the API.&lt;/p&gt;




&lt;h3&gt;
  
  
  📌 Why Developers Use cURL for APIs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Quickly test endpoints&lt;/li&gt;
&lt;li&gt;No need to write application code&lt;/li&gt;
&lt;li&gt;Easily inspect status codes, headers, and responses&lt;/li&gt;
&lt;li&gt;Great for debugging backend issues&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  😗 Ending Thought
&lt;/h2&gt;

&lt;p&gt;This blog series has been &lt;strong&gt;one heck of a journey&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We covered the fundamentals that give you a real understanding of how the internet works behind the scenes.&lt;/p&gt;

&lt;p&gt;If you’ve been reading consistently — thank you.&lt;/p&gt;

&lt;p&gt;If not, give it a try. It will genuinely change how you look at the web.&lt;/p&gt;

&lt;p&gt;Till then —&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See ya, Amigos 🦩&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>TCP 3-way Handshake</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Fri, 30 Jan 2026 17:35:42 +0000</pubDate>
      <link>https://forem.com/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-577</link>
      <guid>https://forem.com/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-577</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey Reader — welcome back&lt;/p&gt;

&lt;p&gt;Okay, that &lt;em&gt;did&lt;/em&gt; sound like an NPC. Let’s fix that.&lt;/p&gt;

&lt;p&gt;In last blog, we really had an intense discussions about the internet rules. &lt;/p&gt;

&lt;p&gt;If you’ve been following along, you should already have a rough mental map of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how devices connect,&lt;/li&gt;
&lt;li&gt;how DNS finds servers,&lt;/li&gt;
&lt;li&gt;and how TCP and UDP choose &lt;em&gt;how&lt;/em&gt; data moves.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If not, quick catch-up here:&lt;/p&gt;

&lt;p&gt;Blog 1: &lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Understanding Network Devices - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 2: &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS Resolution Works - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 3: &lt;a href="https://dev.to/6116hayat/dns-record-types-explained-2m7g"&gt;DNS Record Types Explained - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 4: &lt;a href="https://dev.to/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c"&gt;TCP vs UDP: When to Use What, and How TCP Relates to HTTP - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The more I learn about this stuff, the more I understand why the internet is considered one of humanity’s greatest inventions.&lt;br&gt;
Sometimes it honestly feels like I’m debugging packets with Iron Man holograms floating around me.&lt;/p&gt;

&lt;p&gt;Anyway — before I drift again — let’s talk TCP.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧨 When Data has no Rules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🤔 Internet with &amp;amp; without rules
&lt;/h3&gt;

&lt;p&gt;Imagine a highway.&lt;/p&gt;

&lt;p&gt;No traffic lights.&lt;/p&gt;

&lt;p&gt;No lanes.&lt;/p&gt;

&lt;p&gt;No signs.&lt;/p&gt;

&lt;p&gt;Just vibes.&lt;/p&gt;

&lt;p&gt;Every car rushes forward trying to win. Very GTA energy. Fun for chaos — terrible for reaching a destination.&lt;/p&gt;

&lt;p&gt;That’s what the internet looks like &lt;em&gt;without rules&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;On the internet, cars are &lt;strong&gt;data packets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And the “rules” are called &lt;strong&gt;protocols&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;With protocols:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data arrives reliably&lt;/li&gt;
&lt;li&gt;Packets stay in order&lt;/li&gt;
&lt;li&gt;No duplication&lt;/li&gt;
&lt;li&gt;Errors are detected and corrected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without protocols:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Packets get lost&lt;/li&gt;
&lt;li&gt;Order breaks&lt;/li&gt;
&lt;li&gt;Duplicates appear&lt;/li&gt;
&lt;li&gt;Corrupted data slips through&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chaos. Every time.&lt;/p&gt;




&lt;h3&gt;
  
  
  🚫 Why Internet cannot rely on “best effort” alone
&lt;/h3&gt;

&lt;p&gt;The internet’s core design is &lt;strong&gt;best effort delivery&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The network &lt;em&gt;tries&lt;/em&gt; to deliver packets&lt;/li&gt;
&lt;li&gt;But it makes &lt;strong&gt;zero promises&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a packet is lost, delayed, duplicated, or reordered — the network shrugs and moves on.&lt;/p&gt;

&lt;p&gt;That’s fine for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;video streaming&lt;/li&gt;
&lt;li&gt;voice calls&lt;/li&gt;
&lt;li&gt;casual browsing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But it’s disastrous for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;file downloads&lt;/li&gt;
&lt;li&gt;emails&lt;/li&gt;
&lt;li&gt;online payments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When correctness matters, &lt;em&gt;best effort isn’t enough&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;TCP&lt;/strong&gt; enters.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 TCP and 3-way handshake
&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.amazonaws.com%2Fuploads%2Farticles%2Fsanq7dpnhv0vbfkgtc0k.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%2Fsanq7dpnhv0vbfkgtc0k.png" alt="Handshake" width="800" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we have seen TCP in the last blog and discussed its meaning and full-form and where to use TCP , I won’t be able to repeat myself. &lt;/p&gt;

&lt;p&gt;Don’t worry I will explain TCP here but in short…&lt;/p&gt;

&lt;p&gt;You are always welcomed to checkout the last blog as well the series&lt;/p&gt;

&lt;h3&gt;
  
  
  🌐 TCP: Reliable Connections
&lt;/h3&gt;

&lt;p&gt;TCP (Transmission Control Protocol) sits at the &lt;strong&gt;transport layer&lt;/strong&gt; and is the backbone of reliable internet communication.&lt;/p&gt;

&lt;p&gt;Key traits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connection-oriented&lt;/li&gt;
&lt;li&gt;Reliable delivery&lt;/li&gt;
&lt;li&gt;Ordered data transfer&lt;/li&gt;
&lt;li&gt;No duplication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TCP doesn’t just send data.&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;builds trust first&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🤝 Why a handshake is Needed
&lt;/h3&gt;

&lt;p&gt;Before sending data, TCP asks one simple question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Are you there — and are you ready?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The handshake:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Confirms both sides are reachable&lt;/li&gt;
&lt;li&gt;Synchronizes sequence numbers&lt;/li&gt;
&lt;li&gt;Establishes reliability rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only after this agreement does data flow.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔄️ TCP 3-Way Handshake
&lt;/h3&gt;

&lt;p&gt;The TCP 3-way handshake establishes a reliable connection before data transfer begins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The three steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;SYN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Client: “I want to connect. Here’s my starting sequence number.”&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;SYN-ACK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Server: “I hear you. Here’s mine — and I acknowledge yours.”&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ACK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Client: “Acknowledged. Let’s begin.”&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this, the connection is live.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why three steps?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Both sides confirm readiness&lt;/li&gt;
&lt;li&gt;Both sides acknowledge each other&lt;/li&gt;
&lt;li&gt;No assumptions, no guessing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s reliability by design.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This guarantees both devices are fully ready and “in sync”&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🗣️ Conversation Analogy:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Client: “Hey, can we talk? My first word will be number 100.” (SYN)&lt;/li&gt;
&lt;li&gt;Server: “Sure! I heard you. My first word will be number 300.” (SYN-ACK)&lt;/li&gt;
&lt;li&gt;Client: “Got it, I’ll listen starting at 300.” (ACK)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 Reliable Data Transfer and Connection Closure:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Data Transfer After Handshake
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Once the handshake is established, data flows in segments&lt;/li&gt;
&lt;li&gt;Each segments has a unique number known as sequence number, receiver acknowledges receipt.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Role of Sequence Numbers and Ack’s
&lt;/h3&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%2Fbodwz4yexyvcgojg0sa5.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%2Fbodwz4yexyvcgojg0sa5.png" alt="Sequence" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sequence number ensure data arrives in order&lt;/li&gt;
&lt;li&gt;Acks confirms successful delivery&lt;/li&gt;
&lt;li&gt;If an ACK is missing, the sender knows something is wrong&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Detecting Packet Loss &amp;amp; prevention
&lt;/h3&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%2F5zd8dpsigjad7v38h0fq.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%2F5zd8dpsigjad7v38h0fq.png" alt="Detection_Loss" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCP uses timeouts and duplicates ACK’s to detect lost packets&lt;/li&gt;
&lt;li&gt;If a packet is lost, TCP retransmits it to maintain reliability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ensuring Correctness
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;TCP checks data integrity using &lt;strong&gt;checksums&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If corrupted data is detected, it is discarded and retransmitted.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  😁 Ending Thought
&lt;/h2&gt;

&lt;p&gt;I’m trying my best to stay consistent with this series, but time management is starting to hit hard.&lt;br&gt;
So for the next few blogs, the long introductions and ending thoughts might take a back seat.&lt;/p&gt;

&lt;p&gt;The focus will stay the same though:&lt;br&gt;
understanding how the internet actually works — clearly, honestly, and without magic.&lt;/p&gt;

&lt;p&gt;Humor may go quiet for a bit, but the learning won’t.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>TCP vs UDP: When to Use What, and How TCP Relates to HTTP</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Wed, 28 Jan 2026 22:08:04 +0000</pubDate>
      <link>https://forem.com/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c</link>
      <guid>https://forem.com/6116hayat/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http-1h6c</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction
&lt;/h2&gt;

&lt;p&gt;Hey Reader — welcome back&lt;/p&gt;

&lt;p&gt;The opening line already sounds like an NPC, never mind. &lt;/p&gt;

&lt;p&gt;This networking series has been stretching my brain in the best way possible.&lt;/p&gt;

&lt;p&gt;Every post peels back another layer of how the internet actually works — not the magical version we imagine, but the engineered one.&lt;/p&gt;

&lt;p&gt;So far, we’ve talked about:&lt;/p&gt;

&lt;p&gt;Blog 1: &lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Understanding Network Devices - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 2: &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS Resolution Works - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blog 3: &lt;a href="https://dev.to/6116hayat/dns-record-types-explained-38a0"&gt;DNS Record Types Explained - DEV Community&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now comes the next question:&lt;/p&gt;

&lt;p&gt;Once the destination is known… how does data actually travel?&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;TCP and UDP&lt;/strong&gt; come in — the rules of the internet.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 TCP vs UDP — Two Ways Data Travels
&lt;/h2&gt;

&lt;p&gt;Humans love rules.&lt;br&gt;
Turns out, the internet does too.&lt;/p&gt;

&lt;p&gt;Once computers started talking to each other at scale, rules became unavoidable.&lt;/p&gt;

&lt;p&gt;Without rules, data would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get lost&lt;/li&gt;
&lt;li&gt;Arrive out of order&lt;/li&gt;
&lt;li&gt;Or never arrive at all&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TCP and UDP are the transport-layer rules that prevent that chaos.&lt;/p&gt;




&lt;h3&gt;
  
  
  📜 Why Internet Needs Rules?
&lt;/h3&gt;

&lt;p&gt;The internet is like a busy highway.&lt;/p&gt;

&lt;p&gt;Without traffic rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cars would crash&lt;/li&gt;
&lt;li&gt;Some would never reach their destination&lt;/li&gt;
&lt;li&gt;Others would arrive completely out of order&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the internet, those “cars” are &lt;strong&gt;data packets&lt;/strong&gt;, and the rules they follow live in the &lt;strong&gt;transport layer&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔎 What happens After DNS
&lt;/h3&gt;

&lt;p&gt;When DNS finishes its job, a human-readable domain like &lt;code&gt;example.com&lt;/code&gt; is resolved into an IP address like &lt;code&gt;93.184.216.34&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once that’s done:&lt;/p&gt;

&lt;p&gt;The destination is known&lt;/p&gt;

&lt;p&gt;Now the real work begins: moving data&lt;/p&gt;

&lt;p&gt;At this point, the transport layer decides:&lt;/p&gt;

&lt;p&gt;Should this data arrive reliably and in order?&lt;/p&gt;

&lt;p&gt;Or should it arrive as fast as possible, even if some is lost?&lt;/p&gt;

&lt;p&gt;The answer determines whether &lt;strong&gt;TCP or UDP&lt;/strong&gt; is used.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚚 What are TCP and UDP?
&lt;/h2&gt;

&lt;p&gt;The transport layer includes several protocols, but the internet mostly relies on two:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TCP — Transmission Control Protocol&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UDP — User Datagram Protocol&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They solve the same problem — moving data — but with very different priorities.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✅ TCP: Transmission Control Protocol
&lt;/h3&gt;

&lt;p&gt;Before jumping into a definition, the name itself explains a lot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transmission&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending data from one system to another&lt;/li&gt;
&lt;li&gt;Data is split into smaller packets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Control&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCP doesn’t send data blindly&lt;/li&gt;
&lt;li&gt;It controls the flow using:

&lt;ul&gt;
&lt;li&gt;Sequencing (ordering packets)&lt;/li&gt;
&lt;li&gt;Error checking&lt;/li&gt;
&lt;li&gt;Acknowledgements&lt;/li&gt;
&lt;li&gt;Flow control&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Protocol&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A shared set of rules that both sides understand&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TCP&lt;/strong&gt; is a rulebook that ensures data is transmitted &lt;strong&gt;reliably, in order, and correctly&lt;/strong&gt;, even if it means being slower.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  ⚡ UDP: User Datagram Protocol
&lt;/h3&gt;

&lt;p&gt;UDP takes a very different approach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Refers to the application sending or receiving data&lt;/li&gt;
&lt;li&gt;The application decides how to handle loss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Datagram&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each packet is independent&lt;/li&gt;
&lt;li&gt;No guarantee of order or delivery&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Protocol&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A lightweight set of rules for fast communication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;UDP is a fast, connectionless protocol that sacrifices reliability for speed — ideal for real-time communication.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔑 Key Differences
&lt;/h3&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%2F39uz685h1rvv0gy878hz.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%2F39uz685h1rvv0gy878hz.png" alt="TCP-UDP" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&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;TCP&lt;/th&gt;
&lt;th&gt;UDP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Connection&lt;/td&gt;
&lt;td&gt;Connection-oriented&lt;/td&gt;
&lt;td&gt;Connectionless&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reliability&lt;/td&gt;
&lt;td&gt;Guaranteed delivery&lt;/td&gt;
&lt;td&gt;Best-effort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ordering&lt;/td&gt;
&lt;td&gt;Maintained&lt;/td&gt;
&lt;td&gt;Not guaranteed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speed&lt;/td&gt;
&lt;td&gt;Slower&lt;/td&gt;
&lt;td&gt;Faster&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Overhead&lt;/td&gt;
&lt;td&gt;Higher&lt;/td&gt;
&lt;td&gt;Minimal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Common Uses&lt;/td&gt;
&lt;td&gt;Web, email, files&lt;/td&gt;
&lt;td&gt;Streaming, gaming, calls&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;p&gt;TCP ⇒ safe and reliable, but slower&lt;/p&gt;

&lt;p&gt;UDP ⇒ fast and lightweight, but less reliable&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 When to use TCP vs UDP
&lt;/h2&gt;

&lt;p&gt;The choice depends on one question:&lt;/p&gt;

&lt;p&gt;What matters more — correctness or speed?&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%2F97ahree8enhsgmh5f4kp.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%2F97ahree8enhsgmh5f4kp.png" alt="UseCase" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🖥️ When to Use TCP
&lt;/h3&gt;

&lt;p&gt;Use TCP when &lt;strong&gt;correctness matters more than speed&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌍 Web browsing (HTTP/HTTPS)&lt;/li&gt;
&lt;li&gt;📂 File transfers (FTP, SFTP)&lt;/li&gt;
&lt;li&gt;📧 Emails (SMTP, IMAP, POP3)&lt;/li&gt;
&lt;li&gt;🖥️ Remote access (SSH)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If losing or reordering data breaks meaning, TCP is the right choice.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎮 When to Use UDP
&lt;/h3&gt;

&lt;p&gt;Use UDP when &lt;strong&gt;speed matters more than perfection&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎥 Video streaming&lt;/li&gt;
&lt;li&gt;🎮 Online gaming&lt;/li&gt;
&lt;li&gt;📞 Voice and video calls&lt;/li&gt;
&lt;li&gt;🌐 DNS lookups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In real-time systems, late data is often worse than missing data.&lt;/p&gt;




&lt;h2&gt;
  
  
  📑 What HTTP Fits
&lt;/h2&gt;

&lt;p&gt;Here’s where beginners often get confused&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP is not a transport protocol.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP operates at the &lt;strong&gt;application layer&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It defines how clients and servers communicate&lt;/li&gt;
&lt;li&gt;It relies on transport protocols underneath&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧩 What HTTP Is (and Isn’t)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ A protocol for client–server communication&lt;/li&gt;
&lt;li&gt;❌ Not responsible for packet delivery&lt;/li&gt;
&lt;li&gt;❌ Not the same as TCP or UDP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;HTTP defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Request methods (GET, POST)&lt;/li&gt;
&lt;li&gt;Headers and status codes&lt;/li&gt;
&lt;li&gt;Request–response structure&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 How HTTP Relates to TCP
&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.amazonaws.com%2Fuploads%2Farticles%2Fzamhlbyarihil06hyyrt.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%2Fzamhlbyarihil06hyyrt.png" alt="HTTP-TCP" width="492" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HTTP does not replace TCP — it &lt;strong&gt;runs on top of it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The flow looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Browser creates an HTTP request&lt;/li&gt;
&lt;li&gt;HTTP passes data to TCP&lt;/li&gt;
&lt;li&gt;TCP ensures reliable delivery&lt;/li&gt;
&lt;li&gt;IP routes packets across the network&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;HTTP defines what is said.&lt;br&gt;
TCP defines how it safely arrives.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP ≠ TCP&lt;/li&gt;
&lt;li&gt;HTTP depends on a transport protocol&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Most HTTP traffic uses TCP&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(HTTP/3 uses QUIC over UDP — a story for later)&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤯 Ending Thought
&lt;/h2&gt;

&lt;p&gt;The beauty of the internet lies in its layers.&lt;/p&gt;

&lt;p&gt;Each protocol focuses on one responsibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DNS finds &lt;em&gt;where&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;TCP and UDP decide &lt;em&gt;how&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;HTTP defines &lt;em&gt;what&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the next time a webpage loads, a video streams, or a game responds instantly — remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It’s not magic.&lt;/p&gt;

&lt;p&gt;It’s rules, layers, and very good engineering.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See you in the next blog. 🚀&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>chaicode</category>
    </item>
    <item>
      <title>DNS Record Types Explained</title>
      <dc:creator>Umar Hayat</dc:creator>
      <pubDate>Wed, 28 Jan 2026 10:03:05 +0000</pubDate>
      <link>https://forem.com/6116hayat/dns-record-types-explained-38a0</link>
      <guid>https://forem.com/6116hayat/dns-record-types-explained-38a0</guid>
      <description>&lt;h2&gt;
  
  
  🎙️ Introduction:
&lt;/h2&gt;

&lt;p&gt;Hey reader — welcome back. &lt;/p&gt;

&lt;p&gt;Wait…  (huff) let me breathe.&lt;/p&gt;

&lt;p&gt;This blog series is really giving me marathon vibes. Not because I’m running out of idea ideas — but because turning understanding into clear writing takes time, patience, and a lot of rewrites&lt;/p&gt;

&lt;p&gt;As promised — I’m here with another network blog. &lt;/p&gt;

&lt;p&gt;This is the third post in my networking series:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/6116hayat/understanding-network-devices-3gg1"&gt;Blog 1: Networking Devices&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;Blog 2: How DNS resolution works&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the last blog, we explored how DNS works behind the scenes.&lt;br&gt;
This time, we’ll go one layer deeper and understand DNS record types — the actual information DNS stores and serves.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; give you technical jargon with simple meaning.&lt;/p&gt;

&lt;p&gt;Let’s go 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 Why DNS Needs Records (Not Just Names)
&lt;/h2&gt;

&lt;p&gt;Like we discussed in the last blog — the internet works with &lt;strong&gt;numbers&lt;/strong&gt;, even though we use &lt;strong&gt;names&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But just having names and numbers isn’t enough.&lt;/p&gt;

&lt;p&gt;The internet needs a reliable way to decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;where to send web traffic&lt;/li&gt;
&lt;li&gt;where to send emails&lt;/li&gt;
&lt;li&gt;who controls a domain&lt;/li&gt;
&lt;li&gt;how a domain proves its identity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DNS records exist to answer different questions about the domain.&lt;/p&gt;

&lt;p&gt;Think of DNS records as instructions, not just mappings.&lt;/p&gt;

&lt;p&gt;They tell the internet what to do with different kinds of requests.&lt;/p&gt;




&lt;h3&gt;
  
  
  ❓ What is DNS? (Quick Revision)
&lt;/h3&gt;

&lt;p&gt;Let’s quickly revise from the last blog.&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%2Fng9va4yjv1n2m3qliri3.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%2Fng9va4yjv1n2m3qliri3.png" alt="High level DNS.png" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DNS (Domain Name System) converts human-friendly domain names into IP addresses so browsers can load websites.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Humans prefer names. Machines prefer numbers. &lt;/p&gt;

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

&lt;p&gt;When you  search &lt;strong&gt;google.com&lt;/strong&gt;, your system eventually needs something like: &lt;code&gt;142.250.190.14&lt;/code&gt; to connect it further for information. &lt;/p&gt;

&lt;p&gt;That’s how the connection actually happens.&lt;/p&gt;

&lt;p&gt;We won’t go deeper here — we already covered that in —  &lt;a href="https://dev.to/6116hayat/how-dns-resolution-works-24i9"&gt;How DNS resolution works&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we’ll focus on &lt;strong&gt;DNS records&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  📑 Why DNS Records are needed
&lt;/h3&gt;

&lt;p&gt;A modern domain does many jobs, not just one. &lt;/p&gt;

&lt;p&gt;The same domain may need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;serve a website&lt;/li&gt;
&lt;li&gt;route emails&lt;/li&gt;
&lt;li&gt;act as an alias for another name&lt;/li&gt;
&lt;li&gt;verify ownership for services&lt;/li&gt;
&lt;li&gt;define who controls its DNS data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So one domain needs &lt;strong&gt;multiple kinds of information&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s where DNS records come in.&lt;/p&gt;

&lt;p&gt;One domain contains many categories of information — that’s where DNS records comes into play. &lt;/p&gt;

&lt;p&gt;Each DNS record solves one specific problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;web traffic&lt;/li&gt;
&lt;li&gt;email traffic&lt;/li&gt;
&lt;li&gt;authority&lt;/li&gt;
&lt;li&gt;verification&lt;/li&gt;
&lt;li&gt;redirection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of one overloaded answer, DNS gives clear, separate answers — using different record types.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 The Core DNS Records (And the Problems They Solve)
&lt;/h2&gt;

&lt;p&gt;Imagine if a domain handled only one type of data.&lt;/p&gt;

&lt;p&gt;Email traffic would collide with web traffic.&lt;br&gt;
Aliases would break.&lt;br&gt;
Ownership would be unclear.&lt;/p&gt;

&lt;p&gt;To keep things organized and scalable, DNS uses &lt;strong&gt;different record types&lt;/strong&gt; to route different kinds of traffic.&lt;/p&gt;

&lt;p&gt;Let’s go through them one by one.&lt;/p&gt;




&lt;h3&gt;
  
  
  🏛️ NS Record — Who is responsible for Domain
&lt;/h3&gt;

&lt;p&gt;I explained NS records in my previous blog, but they’re important enough to revisit.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;NS (Name Server) record&lt;/strong&gt; answers one simple question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Who should I ask next for the real DNS information?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;NS records define &lt;strong&gt;authority&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;They tell the internet which name servers are responsible for a domain’s DNS data.&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NS records don’t point to websites&lt;/li&gt;
&lt;li&gt;They don’t point to mail servers&lt;/li&gt;
&lt;li&gt;They point to decision-makers&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ol&gt;
&lt;li&gt;A client requests &lt;code&gt;google.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;DNS checks which name servers are authoritative&lt;/li&gt;
&lt;li&gt;The request is delegated to &lt;code&gt;ns1.google.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;That server provides the next answer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NS records &lt;strong&gt;delegate responsibility&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;They don’t point to websites or mail servers&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🖥️ A Record — Domain to IPv4 Address
&lt;/h3&gt;

&lt;p&gt;The A record is the most common DNS record.&lt;/p&gt;

&lt;p&gt;Its job is simple:&lt;/p&gt;

&lt;p&gt;Map a domain name to an IPv4 address.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="http://google.com/" rel="noopener noreferrer"&gt;google.com&lt;/a&gt; → 142.250.190.14&lt;/p&gt;

&lt;p&gt;When your browser loads a website, this is usually the record it ultimately needs.&lt;/p&gt;

&lt;p&gt;Without A records, computers wouldn’t know &lt;strong&gt;where&lt;/strong&gt; to send web requests.&lt;/p&gt;




&lt;h3&gt;
  
  
  📱 AAAA Record — Domain to IPv6 Address
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;AAAA record&lt;/strong&gt; does the same job as an A record — but with &lt;strong&gt;IPv6&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A record → IPv4&lt;/p&gt;

&lt;p&gt;AAAA record → IPv6&lt;/p&gt;

&lt;p&gt;IPv6 exists because IPv4 addresses are limited and mostly exhausted.&lt;/p&gt;

&lt;p&gt;Important points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AAAA does not replace A records&lt;/li&gt;
&lt;li&gt;Both can exist together&lt;/li&gt;
&lt;li&gt;Browsers prefer IPv6 if available&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most users, this happens automatically.&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%2Fb4yfszaz58a0l6fc5rtk.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%2Fb4yfszaz58a0l6fc5rtk.png" alt="A vs AAAA.png" width="683" height="461"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔗 CNAME Record — One Name Pointing to Another
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;CNAME record - (Canonical Name record) maps one domain name (an alias) to another domain name (the canonical/true name)&lt;/p&gt;
&lt;/blockquote&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%2Fhr5yj0h2zx0taavbtfkc.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%2Fhr5yj0h2zx0taavbtfkc.png" alt="CNAME" width="419" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of pointing to an IP address, it points to &lt;strong&gt;another domain&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="http://www.example.com/" rel="noopener noreferrer"&gt;`www.example.com&lt;/a&gt; → &lt;a href="http://example.com/" rel="noopener noreferrer"&gt;example.com&lt;/a&gt;` &lt;/p&gt;

&lt;p&gt;DNS basically says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Go look at the real name instead.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Analogy:&lt;/p&gt;

&lt;p&gt;CNAME = nickname&lt;/p&gt;

&lt;p&gt;A/AAAA = real address&lt;/p&gt;




&lt;h3&gt;
  
  
  📬 MX Record — How Email Finds Your Mail Server
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;MX record - (Mail Exchange record) record tells the world which mail servers are responsible for receiving email for a domain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Web traffic and email traffic are handled differently&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It tells the world which mail server is responsible for receiving emails for a domain.&lt;/li&gt;
&lt;li&gt;Instead of pointing to an IP address, it points to mail  server’s domain name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short: An MX record tells email where to go.&lt;/p&gt;




&lt;h3&gt;
  
  
  📝 TXT Record — Extra Information and Verification
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;TXT record -  Text record&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Originally, it was meant for human-readable notes.&lt;br&gt;
Today, it’s mostly used by machines.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It lets you add any text information to your domain’s DNS&lt;/li&gt;
&lt;li&gt;It doesn’t point to IP addresses or domains&lt;/li&gt;
&lt;li&gt;It holds text used for verification and security&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TXT records store &lt;strong&gt;proof and instructions&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔄 How All DNS Records Work Together for One Website
&lt;/h2&gt;

&lt;p&gt;Individually, each record is simple.&lt;/p&gt;

&lt;p&gt;Together, they form a coordinated system.&lt;/p&gt;

&lt;p&gt;Each one handles a specific responsibility, but together they ensure that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;websites load correctly&lt;/li&gt;
&lt;li&gt;emails are delivered&lt;/li&gt;
&lt;li&gt;domains are secure&lt;/li&gt;
&lt;li&gt;ownership is clear&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🌍 A DNS Setup for a single domain
&lt;/h3&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%2Fkihhxnzfylsyr2dx7zxb.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%2Fkihhxnzfylsyr2dx7zxb.png" alt="FullDNS" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A typical DNS setup includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A / AAAA&lt;/strong&gt; → Web server IPs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CNAME&lt;/strong&gt; → Aliases (like &lt;code&gt;www&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MX&lt;/strong&gt; → Email routing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TXT&lt;/strong&gt; → Verification and security&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NS&lt;/strong&gt; → Authoritative name servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple Example&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;example.com&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;A&lt;/code&gt; → &lt;code&gt;93.184.216.34&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CNAME&lt;/code&gt; → &lt;code&gt;www.example.com → example.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MX&lt;/code&gt; → &lt;code&gt;mail.example.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TXT&lt;/code&gt; → &lt;code&gt;"v=spf1 include:_spf.google.com ~all"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NS&lt;/code&gt; → &lt;code&gt;ns1.hosting.com&lt;/code&gt;, &lt;code&gt;ns2.hosting.com&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🤔 Common Beginner Confusions
&lt;/h3&gt;

&lt;p&gt;If this feels heavy, that’s normal.&lt;/p&gt;

&lt;p&gt;DNS takes time to fully click.&lt;/p&gt;

&lt;p&gt;Let’s clear some common doubts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;IPv4 vs IPv6

&lt;ul&gt;
&lt;li&gt;IPv4: 32-bit addresses (~4.3 billion)&lt;/li&gt;
&lt;li&gt;IPv6: 128-bit addresses (~3.4×10³⁸)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;IPv6 is more scalable, efficient, and future-proof.&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;A vs CNAME

&lt;ul&gt;
&lt;li&gt;A record → domain to IP address&lt;/li&gt;
&lt;li&gt;CNAME → domain to another domain&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A = direct address&lt;/p&gt;

&lt;p&gt;CNAME = nickname&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;NS  vs MX&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NS → who controls the domain’s DNS&lt;/li&gt;
&lt;li&gt;MX → who handles email for the domain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NS → the “phonebook” that stores all DNS records&lt;/p&gt;

&lt;p&gt;MX → the “mailroom” that directs email to the right server&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  💡Ending Thought
&lt;/h2&gt;

&lt;p&gt;DNS isn’t magic — it’s a system of &lt;strong&gt;organized answers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Each DNS record has a clear role:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A and AAAA connect domains to servers&lt;/li&gt;
&lt;li&gt;CNAME handles aliases&lt;/li&gt;
&lt;li&gt;MX routes email&lt;/li&gt;
&lt;li&gt;TXT verifies and secures&lt;/li&gt;
&lt;li&gt;NS defines authority&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They work quietly in the background — like hardworking parents — making sure everything reaches the right place.&lt;/p&gt;

&lt;p&gt;And honestly, that’s what good internet infrastructure looks like.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
      <category>beginners</category>
      <category>chaicode</category>
    </item>
  </channel>
</rss>
