<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ismile Hossain</title>
    <description>The latest articles on DEV Community by Ismile Hossain (@iamismile).</description>
    <link>https://dev.to/iamismile</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%2F220492%2F582a3089-abf7-4c71-8565-da378251c85f.png</url>
      <title>DEV Community: Ismile Hossain</title>
      <link>https://dev.to/iamismile</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamismile"/>
    <language>en</language>
    <item>
      <title>Understanding Scope in Go</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Wed, 11 Jun 2025 09:10:16 +0000</pubDate>
      <link>https://dev.to/iamismile/understanding-scope-in-go-1m61</link>
      <guid>https://dev.to/iamismile/understanding-scope-in-go-1m61</guid>
      <description>&lt;p&gt;Scope is one of the most important foundational concepts in Go (and any programming language). If you understand it well, it will help you write clearer code, avoid subtle bugs, and even master more advanced topics like closures and concurrency.&lt;/p&gt;

&lt;p&gt;Let’s explore what scope is, how it works in Go, and how you can remember it, using a simple office building analogy.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧐 What is Scope?
&lt;/h2&gt;

&lt;p&gt;Scope refers to &lt;strong&gt;where a variable can be seen and used in your code&lt;/strong&gt;. It's like a permission system: who can read a variable depends on where it was declared.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 Think of it like a note you wrote&lt;/strong&gt;&lt;br&gt;
Not everyone can see your note. It depends on &lt;strong&gt;where you left it&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you tape it to your office’s main wall, everyone in the department can see it.&lt;/li&gt;
&lt;li&gt;If you hide it in your desk drawer, only you can read it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This "visibility boundary" is what scope means in programming.&lt;/p&gt;


&lt;h2&gt;
  
  
  🏢 The Company Building Analogy
&lt;/h2&gt;

&lt;p&gt;Imagine your Go program as a &lt;strong&gt;company office building&lt;/strong&gt;. Each part of the building has different levels of access and visibility.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Real-World Office Element&lt;/th&gt;
&lt;th&gt;Go Code Equivalent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🗂️ Departments (e.g. HR, IT)&lt;/td&gt;
&lt;td&gt;Packages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🛋️ Meeting rooms inside departments&lt;/td&gt;
&lt;td&gt;Functions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🗄️ Drawers inside meeting rooms&lt;/td&gt;
&lt;td&gt;Code blocks (&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📝 Notes lying around&lt;/td&gt;
&lt;td&gt;Variables&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;🧱 Scope Hierarchy (Top → Bottom)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;🏢 Package Level &lt;span class="o"&gt;(&lt;/span&gt;Department Wall Notes&lt;span class="o"&gt;)&lt;/span&gt;
└── 🛋️ Function Level &lt;span class="o"&gt;(&lt;/span&gt;Meeting Room Table Notes&lt;span class="o"&gt;)&lt;/span&gt;
    └── 🗄️ Block Level &lt;span class="o"&gt;(&lt;/span&gt;Drawer Notes&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📌 Rule of Thumb&lt;/strong&gt;: You can always read notes from &lt;strong&gt;above&lt;/strong&gt;, but not &lt;strong&gt;beside&lt;/strong&gt; or &lt;strong&gt;below&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you're in a drawer (block), you can read the table (function) and wall (package) notes. &lt;/li&gt;
&lt;li&gt;But if you're on the department floor (package level), you cannot see inside someone's drawer.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧭 What is Lexical Scope?
&lt;/h2&gt;

&lt;p&gt;Go uses &lt;strong&gt;lexical scope&lt;/strong&gt; (also called &lt;strong&gt;static scope&lt;/strong&gt;), which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scope is determined &lt;strong&gt;by the position of code&lt;/strong&gt;, not by how the program runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inner scopes can access outer variables&lt;/strong&gt;, but outer scopes can't see inside.&lt;/li&gt;
&lt;li&gt;The visibility of variables is decided at &lt;strong&gt;compile time&lt;/strong&gt;, not runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;📌  In our analogy:&lt;/strong&gt; If you're in a drawer, you can see notes on the meeting room table and department wall, but someone on the department floor can't see notes inside someone's drawer.&lt;/p&gt;




&lt;h3&gt;
  
  
  📝 Basic Scope Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;outer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"I'm at package level"&lt;/span&gt; &lt;span class="c"&gt;// 🏢 Department wall note&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;inner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"I'm at function level"&lt;/span&gt; &lt;span class="c"&gt;// 🛋️ Meeting room table note&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Can read wall notes&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Can read table notes&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Can still read wall notes&lt;/span&gt;
    &lt;span class="c"&gt;// fmt.Println(inner) // ❌ Error: can't read inside a meeting room&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🗄️ Block Scope in Action
&lt;/h3&gt;

&lt;p&gt;Variables declared in blocks like &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; are only visible inside those blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="c"&gt;// 🛋️ Table note&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;            &lt;span class="c"&gt;// 🗄️ Drawer note&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;            &lt;span class="c"&gt;// ✅ Can modify outer table note&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Can read both: 10, 2&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Still 10&lt;/span&gt;
    &lt;span class="c"&gt;// fmt.Println(y) // ❌ Error: y is not accessible here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Loops Also Create Block Scopes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;loops&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Loop %d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 🗄️ Drawer note&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// fmt.Println(i)       // ❌ Not accessible&lt;/span&gt;
    &lt;span class="c"&gt;// fmt.Println(message) // ❌ Not accessible&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;loops&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;h3&gt;
  
  
  👥 Variable Shadowing: The Impostor Notes
&lt;/h3&gt;

&lt;p&gt;Shadowing occurs when you declare a variable with the same name in a nested scope. It temporarily hides the outer one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Global Alice"&lt;/span&gt; &lt;span class="c"&gt;// 🏢 Wall note&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;meeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Local Bob"&lt;/span&gt; &lt;span class="c"&gt;// 🛋️ Table note (shadows global)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"In meeting:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "Local Bob"&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Block Charlie"&lt;/span&gt; &lt;span class="c"&gt;// 🗄️ Drawer note (shadows Bob)&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"In block:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "Block Charlie"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Back in meeting:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "Local Bob"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Global:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;meeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Still global:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔍 Note&lt;/strong&gt;: Each &lt;code&gt;var name = ...&lt;/code&gt; is a new variable, not a reassignment. It creates a shadow, not an override.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚨 Warning&lt;/strong&gt;: Shadowing can confuse readers and introduce subtle bugs. Use distinct variable names where clarity matters.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔒 Package Scope: Public vs Private
&lt;/h3&gt;

&lt;p&gt;In Go, &lt;strong&gt;capitalization determines visibility across packages&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;lowercase&lt;/strong&gt; → private to the package (🏢 department-only notes)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uppercase&lt;/strong&gt; → exported, visible to other packages (📢 public announcement)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Package Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// File: mypackage/data.go&lt;/span&gt;
&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;mypackage&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;secretKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hidden"&lt;/span&gt;    &lt;span class="c"&gt;// 🔒 Only visible in mypackage&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;PublicData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"everyone"&lt;/span&gt; &lt;span class="c"&gt;// 📢 Visible to other packages&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;privateFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;        &lt;span class="c"&gt;// 🔒 Private&lt;/span&gt;
    &lt;span class="c"&gt;// Only callable in this package&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;PublicFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;         &lt;span class="c"&gt;// 📢 Exported&lt;/span&gt;
    &lt;span class="c"&gt;// Callable from outside&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cross-Package Access Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// File: main.go&lt;/span&gt;
&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"myproject/mypackage"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mypackage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PublicData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Works&lt;/span&gt;
    &lt;span class="n"&gt;mypackage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PublicFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;            &lt;span class="c"&gt;// ✅ Works&lt;/span&gt;

    &lt;span class="c"&gt;// fmt.Println(mypackage.secretKey)  // ❌ Compile error&lt;/span&gt;
    &lt;span class="c"&gt;// mypackage.privateFunc()           // ❌ Compile error&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 A Note on Closures and Scope
&lt;/h2&gt;

&lt;p&gt;Closures are functions that &lt;strong&gt;capture&lt;/strong&gt; variables from their surrounding scope, even after the outer function has exited.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;makeCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;  &lt;span class="c"&gt;// 🛋️ Table note that's "captured"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="c"&gt;// Modifies the captured variable&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;counter1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;makeCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;counter2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;makeCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter1&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c"&gt;// 1&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter1&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c"&gt;// 2&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter2&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c"&gt;// 1 (separate instance)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter1&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c"&gt;// 3&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🔁 Each returned function remembers the scope it was created in, even if that scope is "gone" in the normal program flow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;💡 Why This Works&lt;/strong&gt;&lt;br&gt;
Go &lt;strong&gt;moves captured variables like &lt;code&gt;count&lt;/code&gt; to the heap&lt;/strong&gt;, so they live beyond the lifetime of the outer function. That’s why &lt;code&gt;counter1()&lt;/code&gt; and &lt;code&gt;counter2()&lt;/code&gt; don’t interfere with each other.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope defines where a variable can be accessed&lt;/strong&gt; - think of it as visibility boundaries in your office building.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Go uses lexical (static) scope&lt;/strong&gt; - it's based on where you write code, not how the program runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inner scopes can access outer variables, but not the other way around&lt;/strong&gt; - you can read notes from above, but not below.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variable shadowing creates new variables with the same name&lt;/strong&gt; - be careful not to accidentally shadow when you meant to reassign.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Closures capture variables from their surrounding scope&lt;/strong&gt; - even after the outer function ends, the captured variables remain accessible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Package capitalization determines cross-package visibility&lt;/strong&gt; - lowercase for private, Uppercase for exported.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>CORS Explained: From Toy Boxes to Technical Implementation</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Sun, 18 May 2025 12:25:37 +0000</pubDate>
      <link>https://dev.to/iamismile/cors-explained-from-toy-boxes-to-technical-implementation-gom</link>
      <guid>https://dev.to/iamismile/cors-explained-from-toy-boxes-to-technical-implementation-gom</guid>
      <description>&lt;h2&gt;
  
  
  🧠 CORS Explained Like You're 5
&lt;/h2&gt;

&lt;p&gt;Imagine this: You have a &lt;strong&gt;toy box&lt;/strong&gt; (your website running in the browser), and you love playing with your &lt;strong&gt;own toys&lt;/strong&gt; (your own data).&lt;/p&gt;

&lt;p&gt;One day, you try to grab a toy from your &lt;strong&gt;friend’s toy box&lt;/strong&gt; (another website’s data).&lt;br&gt;
But your &lt;strong&gt;mom&lt;/strong&gt; (the browser) stops you and says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hold on! I don’t know if your friend’s parents said it’s okay for you to borrow their toys!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is where &lt;strong&gt;CORS (Cross-Origin Resource Sharing)&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧑‍🍳 The Server = Your Friend’s Parent&lt;/strong&gt;&lt;br&gt;
When you try to grab the toy, your &lt;strong&gt;mom&lt;/strong&gt; doesn’t just say "yes" or "no" by herself.&lt;br&gt;
She actually asks your &lt;strong&gt;friend’s parent&lt;/strong&gt; (the server):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, is it okay if my kid plays with your kids’ toys?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If your friend’s parent says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📝 "Sure! I wrote a permission slip (CORS headers) that says it’s okay!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then your &lt;strong&gt;mom&lt;/strong&gt; lets you take the toy and play with it. 🎉&lt;br&gt;
But if your friend’s parent says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;❌ "Nope. My kids’ toys are only for them and not for anyone else."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then your mom stops you and says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Sorry, no permission, no playing!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So basically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Same toy box? No problem.&lt;/li&gt;
&lt;li&gt;🚫 Different toy box? Need permission (CORS).&lt;/li&gt;
&lt;li&gt;🔒 No permission? No playing!&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🔒 What is CORS?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CORS (Cross-Origin Resource Sharing)&lt;/strong&gt; is a &lt;strong&gt;security feature enforced by browsers&lt;/strong&gt;. It controls how a web page running in one &lt;strong&gt;origin (protocol + domain + port)&lt;/strong&gt; can make requests to a &lt;strong&gt;different origin&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By default, browsers block cross-origin requests made from JavaScript for security reasons.&lt;/p&gt;
&lt;h3&gt;
  
  
  🌐 What is an "Origin"?
&lt;/h3&gt;

&lt;p&gt;An origin includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Protocol&lt;/strong&gt;: &lt;code&gt;http://&lt;/code&gt; vs &lt;code&gt;https://&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain&lt;/strong&gt;: &lt;code&gt;example.com&lt;/code&gt; vs &lt;code&gt;api.example.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: &lt;code&gt;:80&lt;/code&gt; vs &lt;code&gt;:8080&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If &lt;strong&gt;any of these differ&lt;/strong&gt;, it's considered a &lt;strong&gt;cross-origin request&lt;/strong&gt; and CORS rules apply.&lt;/p&gt;


&lt;h2&gt;
  
  
  📍 Example Scenario
&lt;/h2&gt;

&lt;p&gt;You have a frontend app hosted at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: &lt;code&gt;https://myfrontend.com&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And you try to fetch data from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend API&lt;/strong&gt;: &lt;code&gt;https://api.othersite.com/data&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the domains are different, this is a cross-origin request. Unless &lt;code&gt;https://api.othersite.com&lt;/code&gt; explicitly allows it, the browser will &lt;strong&gt;block the request&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✅ How CORS Works
&lt;/h2&gt;

&lt;p&gt;When the browser sees a cross-origin request, it may first send a &lt;strong&gt;preflight request&lt;/strong&gt; (an &lt;code&gt;OPTIONS&lt;/code&gt; request), to ask the server:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hey, can I make this request from &lt;code&gt;https://myfrontend.com&lt;/code&gt;?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the server replies with the right headers like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: https://myfrontend.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the browser says, "Cool, I'm allowed to proceed." And sends the actual request.&lt;/p&gt;

&lt;p&gt;If the header is missing or doesn't match, the browser blocks the request.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛫 Preflight Request Flow
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Browser&lt;/strong&gt;: Sends &lt;code&gt;OPTIONS&lt;/code&gt; request with details.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt;: Responds with CORS headers (if allowed).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser&lt;/strong&gt;: If okay, sends the actual request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Visual Flow Diagram&lt;/strong&gt;&lt;br&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%2Foj6rp7cl4ab12mb8c0j6.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%2Foj6rp7cl4ab12mb8c0j6.png" alt="Preflight Request" width="508" height="356"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 Sample HTTP Preflight Request
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Request&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPTIONS /data HTTP/1.1  
Origin: https://example-frontend.com  
Access-Control-Request-Method: POST  
Access-Control-Request-Headers: Content-Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 204 No Content  
Access-Control-Allow-Origin: https://example-frontend.com  
Access-Control-Allow-Methods: POST  
Access-Control-Allow-Headers: Content-Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔐 Why CORS Matters
&lt;/h2&gt;

&lt;p&gt;Imagine you're logged into your &lt;strong&gt;bank&lt;/strong&gt; in one tab. Without CORS, a malicious site in another tab could silently access your bank data just because you’re logged in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CORS stops that&lt;/strong&gt;. It ensures that &lt;strong&gt;only trusted origins&lt;/strong&gt; can make requests to protected resources.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔑 Important CORS Headers Explained
&lt;/h2&gt;

&lt;p&gt;CORS uses several HTTP headers to control access. Here are the most important ones:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Access-Control-Allow-Origin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the most fundamental CORS header. It specifies which origins are allowed to access the resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: https://myfrontend.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use a wildcard to allow any origin (not recommended for APIs handling sensitive data):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Access-Control-Allow-Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Specifies which HTTP methods (GET, POST, etc.) are allowed when accessing the resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Methods: GET, POST, PUT, DELETE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Access-Control-Allow-Headers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Indicates which HTTP headers can be used during the actual request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Headers: Content-Type, Authorization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Access-Control-Allow-Credentials&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Indicates whether the browser should include credentials (like cookies or HTTP authentication) with the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Credentials: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Access-Control-Max-Age&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Specifies how long (in seconds) the results of a preflight request can be cached:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Max-Age: 3600
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ CORS in Code (Server Examples)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;📘 Using Express.js (Manual Headers)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Origin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example-frontend.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Methods&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GET, POST, PUT, DELETE&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Headers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type, Authorization&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/data&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;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This is CORS-enabled!&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;&lt;strong&gt;✅ Better Way: Use cors Middleware&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install cors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example-frontend.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&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="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PUT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;allowedHeaders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&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;
  
  
  ⚠️ Common CORS Errors and How to Debug
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. "Access to fetch at 'X' from origin 'Y' has been blocked by CORS policy"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the most common CORS error and indicates that the server at URL 'X' doesn't include the proper CORS headers to allow access from origin 'Y'.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Configure the server to send the correct &lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; header.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. "Request header field X is not allowed by Access-Control-Allow-Headers"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This error occurs when your request includes headers that aren't explicitly allowed by the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Add the required headers to the &lt;code&gt;Access-Control-Allow-Headers&lt;/code&gt; response header on the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. "Method X is not allowed by Access-Control-Allow-Methods"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The HTTP method you're trying to use isn't allowed by the server's CORS policy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Add the method to the &lt;code&gt;Access-Control-Allow-Methods&lt;/code&gt; response header on the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. "The value of the 'Access-Control-Allow-Origin' header must not be the wildcard '*' when the request's credentials mode is 'include'"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This error occurs when you're trying to send credentials (cookies, etc.) to a server that has &lt;code&gt;Access-Control-Allow-Origin: *&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;: Specify the exact origin instead of using a wildcard, and set &lt;code&gt;Access-Control-Allow-Credentials: true&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Debugging CORS Issues with Browser Dev Tools
&lt;/h2&gt;

&lt;p&gt;Most modern browsers include developer tools that can help you diagnose CORS issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Open Developer Tools&lt;/strong&gt;: Press F12 or right-click and select "Inspect"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Go to Network Tab&lt;/strong&gt;: This shows all network requests&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look for Failed Requests&lt;/strong&gt;: CORS errors will appear in red&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Examine Preflight Requests&lt;/strong&gt;: Look for &lt;code&gt;OPTIONS&lt;/code&gt; requests to see if they're returning the correct headers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Console&lt;/strong&gt;: CORS errors also appear in the console with detailed messages&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example CORS Error in Console:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Access to fetch at '&lt;a href="https://api.example.com/data" rel="noopener noreferrer"&gt;https://api.example.com/data&lt;/a&gt;' from origin &amp;gt;'&lt;a href="https://myfrontend.com" rel="noopener noreferrer"&gt;https://myfrontend.com&lt;/a&gt;' has been blocked by CORS policy: No &amp;gt;'Access-Control-Allow-Origin' header is present on the requested &amp;gt;resource.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🔒 Security Considerations
&lt;/h2&gt;

&lt;p&gt;While CORS is a security mechanism, misconfigured CORS can lead to security vulnerabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ &lt;code&gt;Avoid Access-Control-Allow-Origin: *&lt;/code&gt; for private APIs&lt;/li&gt;
&lt;li&gt;🔒 Only allow trusted origins&lt;/li&gt;
&lt;li&gt;⚙️ Be strict about allowed methods and headers&lt;/li&gt;
&lt;li&gt;🍪 Use &lt;code&gt;Access-Control-Allow-Credentials: true&lt;/code&gt; only when necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt;: CORS is a browser-enforced security feature. API endpoints can still be accessed directly using tools like &lt;code&gt;curl&lt;/code&gt; or &lt;code&gt;Postman&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 Real-World Use Cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;APIs and Microservices&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In modern architectures, frontend applications often need to communicate with multiple backend services hosted on different domains. CORS enables these services to securely share resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third-Party Integrations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When integrating with third-party services (payment gateways, analytics, etc.), CORS allows these external services to access resources from your domain when necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Delivery Networks (CDNs)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When your assets are hosted on CDNs with different domains, CORS allows your main website to interact with these resources.&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Conclusion
&lt;/h2&gt;

&lt;p&gt;CORS is like a &lt;strong&gt;permission system for the web&lt;/strong&gt;. It prevents unauthorized websites from messing with your data, while still letting trusted sites communicate securely.&lt;/p&gt;

&lt;p&gt;Just remember the toy box analogy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your &lt;strong&gt;website&lt;/strong&gt; is &lt;strong&gt;your toy box&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Another website’s data is &lt;strong&gt;your friend’s toy box&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;browser&lt;/strong&gt; is &lt;strong&gt;your mom&lt;/strong&gt;, who makes sure you play safely.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;server&lt;/strong&gt; is &lt;strong&gt;your friend’s parent&lt;/strong&gt;, who decides if you're allowed to borrow the toy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CORS headers&lt;/strong&gt; are &lt;strong&gt;the permission slip&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding CORS is &lt;strong&gt;essential for modern web development&lt;/strong&gt;, especially when working with APIs and distributed systems.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>security</category>
      <category>programming</category>
    </item>
    <item>
      <title>Concurrency in Go</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Sun, 11 May 2025 09:55:18 +0000</pubDate>
      <link>https://dev.to/iamismile/concurrency-in-go-4m2n</link>
      <guid>https://dev.to/iamismile/concurrency-in-go-4m2n</guid>
      <description>&lt;h2&gt;
  
  
  ❓ What is Concurrency?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Concurrency&lt;/strong&gt; is the ability of a program to manage multiple tasks at once. These tasks may not run &lt;em&gt;exactly&lt;/em&gt; at the same time, but they are managed in such a way that it feels like they are happening simultaneously.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 Real-Life Analogy
&lt;/h2&gt;

&lt;p&gt;Imagine you’re cooking dinner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You put water on the stove to boil. While you wait for it to heat up, you chop vegetables. Once it’s boiling, you add pasta. While the pasta cooks, you start preparing the sauce.&lt;/li&gt;
&lt;li&gt;You’re not doing everything at once, but you’ve planned it so that while one task is happening in the background (like water boiling), you’re using that time to work on something else (like chopping vegetables). This way, you’re making steady progress on multiple things without wasting time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s what &lt;strong&gt;concurrency&lt;/strong&gt; means in programming: arranging tasks so they can make progress without blocking each other. Even if only one thing runs at a time, they move forward efficiently by taking turns when it makes sense.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧑‍💻 Concurrency in Go
&lt;/h2&gt;

&lt;p&gt;In Go, concurrency means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your program runs multiple tasks (functions or processes).&lt;/li&gt;
&lt;li&gt;Each concurrent task runs in its own &lt;strong&gt;Goroutine&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Go has a built-in &lt;strong&gt;scheduler&lt;/strong&gt; that efficiently manages these Goroutines across system threads and CPU cores.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧵 What is a Goroutine?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Goroutine&lt;/strong&gt; is a lightweight, independently executing function, managed by the Go runtime.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;You create one using the &lt;code&gt;go&lt;/code&gt; keyword.&lt;/li&gt;
&lt;li&gt;It’s much lighter than an OS thread (~2 KB of stack to start).&lt;/li&gt;
&lt;li&gt;Goroutines can scale massively, you can run thousands without major performance hits.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s how you launch a goroutine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It starts running &lt;code&gt;someFunction()&lt;/code&gt; in the background, quickly and efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Example: Goroutine in Action
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finished background task"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Run task concurrently&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Main function done"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main function done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;😲 Wait, where’s the output from &lt;code&gt;backgroundTask()&lt;/code&gt;?&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What Happened?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;main()&lt;/code&gt; runs in the &lt;strong&gt;main goroutine&lt;/strong&gt;, the default thread of execution in a Go program.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;go backgroundTask()&lt;/code&gt; is called, Go starts a &lt;strong&gt;new goroutine&lt;/strong&gt; for &lt;code&gt;backgroundTask()&lt;/code&gt;, but it doesn't wait for it to finish.&lt;/li&gt;
&lt;li&gt;The program immediately continues to the next line: &lt;code&gt;fmt.Println("Main function done")&lt;/code&gt;, and prints it.&lt;/li&gt;
&lt;li&gt;Since there's nothing left after that, &lt;strong&gt;main ends&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Once &lt;code&gt;main()&lt;/code&gt; finishes, the entire program &lt;strong&gt;exits&lt;/strong&gt;, and Go kills all running goroutines, even if they’re still doing something.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the &lt;code&gt;backgroundTask()&lt;/code&gt; goroutine gets cut off before it can finish and print its message.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Fixing It: Give It Time
&lt;/h2&gt;

&lt;p&gt;Add a delay in &lt;code&gt;main()&lt;/code&gt; to let the background goroutine finish:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Main function done"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main function done
Finished background task
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔️ Now you see both outputs because we gave enough time for the background task to complete.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 But… What If We Don’t Know How Long the Task Takes?
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;time.Sleep()&lt;/code&gt; is a &lt;strong&gt;bad practice&lt;/strong&gt; in real applications because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unknown task duration&lt;/strong&gt;: We can’t always predict how long a task will take. Tasks like API calls may vary in duration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wasted resources&lt;/strong&gt;: If you sleep for more time than necessary, you waste resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fragile code&lt;/strong&gt;: Hardcoding sleep durations makes the program prone to bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔑 Instead, Go gives us a better tool: &lt;strong&gt;&lt;code&gt;sync.WaitGroup&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 What is &lt;code&gt;sync.WaitGroup&lt;/code&gt;?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;WaitGroup&lt;/code&gt; lets you wait for a group of goroutines to finish; &lt;strong&gt;no guessing, no sleeping&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  🎯 Think of it like:
&lt;/h4&gt;

&lt;p&gt;A field trip leader keeping count of students:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧑‍🎓 Each student going out = &lt;code&gt;Add(1)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;✅ Each student returning = &lt;code&gt;Done()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🧍 The leader waits until everyone returns = &lt;code&gt;Wait()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ Using &lt;code&gt;WaitGroup&lt;/code&gt; (Step-by-Step)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"net/http"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// 4. Tell WaitGroup this task is done&lt;/span&gt;

    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"https://jsonplaceholder.typicode.com/posts"&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error fetching posts: %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Background Task, Response Status:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt; &lt;span class="c"&gt;// 1. Create a WaitGroup&lt;/span&gt;

    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 2. We’re launching 1 goroutine&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 3. Start the goroutine&lt;/span&gt;

    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// 5. Wait for all tasks to finish&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Main function done"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧪 Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Background Task, Response Status: 200 OK
Main function done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔍 Explanation&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;wg.Add(1)&lt;/code&gt; tells Go: “One goroutine is coming.”&lt;/li&gt;
&lt;li&gt;Inside the goroutine, &lt;code&gt;defer wg.Done()&lt;/code&gt; tells Go: “I’m finished.”&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wg.Wait()&lt;/code&gt; blocks the main goroutine until the task finishes.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🚀 Running Multiple Goroutines with &lt;code&gt;WaitGroup&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You can use &lt;code&gt;WaitGroup&lt;/code&gt; to manage multiple goroutines at once. Here's how you can launch multiple background tasks concurrently:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"net/http"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"https://jsonplaceholder.typicode.com/posts"&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Task %d failed: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Task %d, Response Status: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;
    &lt;span class="n"&gt;totalTasks&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;totalTasks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;backgroundTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"All background tasks completed"&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;
  
  
  🧵 Race Conditions and Synchronization
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;race condition&lt;/strong&gt; happens when &lt;strong&gt;two or more goroutines try to use or change the same variable at the same time&lt;/strong&gt;, and the result depends on who gets there first. This can lead to wrong or unexpected results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❌ Example: Race Condition Without Synchronization&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;                &lt;span class="c"&gt;// Shared variable&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;       &lt;span class="c"&gt;// Used to wait for all goroutines to finish&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;               &lt;span class="c"&gt;// Increase WaitGroup counter&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;    &lt;span class="c"&gt;// Decrease WaitGroup counter when done&lt;/span&gt;
            &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;          &lt;span class="c"&gt;// 🔥 Race condition happens here!&lt;/span&gt;
        &lt;span class="p"&gt;}()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                   &lt;span class="c"&gt;// Wait for all goroutines to finish&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Final counter:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 😬 Unpredictable result!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧠 What’s Happening?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That line &lt;code&gt;counter++&lt;/code&gt; looks simple, but it's not safe when many goroutines run it at the same time.&lt;/p&gt;

&lt;p&gt;Here's what really happens inside &lt;code&gt;counter++&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the current value of &lt;code&gt;counter&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add 1 to it&lt;/li&gt;
&lt;li&gt;Save the new value back&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If two goroutines do this at the same time, they might both read the same old value before either writes the new one. So, one increment gets lost.&lt;/p&gt;

&lt;p&gt;That’s why you’ll often see a final count that’s less than 1000. This is called a race condition.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✅ How to Fix It: Use a &lt;code&gt;Mutex&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;To safely share data between goroutines, we use a &lt;strong&gt;mutex&lt;/strong&gt; (short for mutual exclusion). It ensures that only one goroutine can access the critical section (the shared resource) at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mu&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Mutex&lt;/span&gt;            &lt;span class="c"&gt;// 👈 Mutex to protect the counter&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;            &lt;span class="c"&gt;// 👈 Lock before accessing counter&lt;/span&gt;
            &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
            &lt;span class="n"&gt;mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Unlock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;          &lt;span class="c"&gt;// 👈 Unlock after done&lt;/span&gt;
        &lt;span class="p"&gt;}()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Final counter:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// ✅ Always 1000&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔐 What &lt;code&gt;mu.Lock()&lt;/code&gt; and &lt;code&gt;mu.Unlock()&lt;/code&gt; Do:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine a &lt;strong&gt;single key to a room&lt;/strong&gt; where the shared variable (like &lt;code&gt;counter&lt;/code&gt;) lives.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧑‍🔧 &lt;code&gt;mu.Lock()&lt;/code&gt; means:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;"I need the key to go into the room and do something important. No one else can come in while I’m inside."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;🧑‍💼 &lt;code&gt;mu.Unlock()&lt;/code&gt; means:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;"I’m done! Here’s the key, someone else can go in now."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So when you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="n"&gt;mu&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Unlock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're saying:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lock the door so no one else can touch &lt;code&gt;counter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Safely update &lt;code&gt;counter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Unlock the door so others can take their turn.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;✅ This makes sure &lt;strong&gt;only one goroutine at a time&lt;/strong&gt; is changing &lt;code&gt;counter&lt;/code&gt;, which keeps things safe and correct.&lt;/p&gt;

&lt;p&gt;🔁 If another goroutine tries to &lt;code&gt;mu.Lock()&lt;/code&gt; while it's already locked, it will &lt;em&gt;wait&lt;/em&gt; until it's unlocked.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Pro tip&lt;/strong&gt;: Use &lt;code&gt;defer mu.Unlock()&lt;/code&gt; right after &lt;code&gt;mu.Lock()&lt;/code&gt; to make sure the lock is always released, even if something goes wrong.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Go's Race Detector
&lt;/h2&gt;

&lt;p&gt;Go includes a built-in race detector. Just add &lt;code&gt;-race&lt;/code&gt; flag when running your program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run &lt;span class="nt"&gt;-race&lt;/span&gt; yourprogram.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will tell you if and where race conditions occur in your code!&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 Recap: What We Learned So Far
&lt;/h2&gt;

&lt;p&gt;We learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goroutines&lt;/strong&gt; run functions in the background.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WaitGroups&lt;/strong&gt; wait until all goroutines are done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mutexes&lt;/strong&gt; prevent race conditions when multiple goroutines access shared data.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🤔 But what if we want goroutines to send back some result or communicate with each other?
&lt;/h3&gt;

&lt;p&gt;That's where &lt;strong&gt;channels&lt;/strong&gt; come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  📬 What is a Channel?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A channel is a built-in Go feature that allows goroutines to talk to each other.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of a channel like a message pipe. One goroutine puts data in, and another takes it out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Creating a Channel&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// creates a channel of type int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📤 Sending Data to a Channel&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="m"&gt;42&lt;/span&gt; &lt;span class="c"&gt;// send 42 to channel&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📥 Receiving Data from a Channel&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="c"&gt;// receive value from channel&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// prints: 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧪 Basic Example
&lt;/h2&gt;

&lt;p&gt;Let’s write a small program with a goroutine that sends a message back to the main function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Hello from goroutine!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// 1. Create a channel of type string&lt;/span&gt;
    &lt;span class="n"&gt;messageChannel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// 2. Start a goroutine and pass the channel to it&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageChannel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// 3. Receive the message from the channel&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;messageChannel&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Received: Hello from goroutine!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if the goroutine takes time (e.g., sleeps), the main function &lt;strong&gt;waits&lt;/strong&gt; until the message is received.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔍 Code Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;make(chan string)&lt;/code&gt;    We create a channel that can carry strings.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;go greet(messageChannel)&lt;/code&gt; We start a goroutine and give it the channel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ch &amp;lt;- "Hello..."&lt;/code&gt; Inside the goroutine, we send a message into the channel.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;-messageChannel&lt;/code&gt; In the main function, we wait and receive the message.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 Blocking Behavior of Channels
&lt;/h2&gt;

&lt;p&gt;Channels in Go are &lt;strong&gt;&lt;em&gt;synchronous&lt;/em&gt;&lt;/strong&gt; by default. That means when you send or receive a value, your code &lt;strong&gt;waits&lt;/strong&gt; (or blocks) until the other side is ready.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Blocks Until&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ch &amp;lt;- value&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Another goroutine is ready to receive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;value := &amp;lt;-ch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Another goroutine sends a value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Because of this, you &lt;strong&gt;can’t send and receive&lt;/strong&gt; on an &lt;strong&gt;unbuffered&lt;/strong&gt; channel in the same &lt;strong&gt;goroutine&lt;/strong&gt;, the send will &lt;strong&gt;pause&lt;/strong&gt; and never reach the receive, since both need each other to proceed. This is why we usually use goroutines with channels.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔥 Here is an example of this
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// create a string channel&lt;/span&gt;

    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Hello from goroutine!"&lt;/span&gt; &lt;span class="c"&gt;// send message to channel&lt;/span&gt;

    &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;      &lt;span class="c"&gt;// receive message from channel&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Output: Hello from goroutine!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan send]:
main.main()
        /home/iamismile/Desktop/development/golang/helloworld/main.go:10 +0x36
exit status 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  💡 Why This Happens:
&lt;/h2&gt;

&lt;p&gt;You created an unbuffered channel, which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The send operation &lt;code&gt;ch &amp;lt;- "..."&lt;/code&gt; will block until someone is ready to receive the value.&lt;/li&gt;
&lt;li&gt;But in your code, the main goroutine tries to send before any goroutine is receiving.&lt;/li&gt;
&lt;li&gt;Since no other goroutine is receiving yet, the main goroutine just waits forever, which causes a deadlock.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🤔 &lt;strong&gt;You might be wondering…&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I've used the term &lt;strong&gt;unbuffered channel&lt;/strong&gt;. So far, all the channels we’ve used were &lt;strong&gt;unbuffered&lt;/strong&gt;, which means the sender and receiver had to be ready &lt;strong&gt;at the same time&lt;/strong&gt; for communication to happen.&lt;/p&gt;

&lt;p&gt;But Go also gives us another type of channel called a &lt;strong&gt;buffered channel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s break down both types in a simple way:&lt;/p&gt;




&lt;h2&gt;
  
  
  🔹 Unbuffered Channels — "Direct Delivery"
&lt;/h2&gt;

&lt;p&gt;Think of an unbuffered channel like a &lt;strong&gt;handshake&lt;/strong&gt;:&lt;br&gt;
The sender holds out a value, but can’t let go until someone is there to take it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// unbuffered&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ch &amp;lt;- 10&lt;/code&gt; → blocks until another goroutine does &lt;code&gt;&amp;lt;-ch&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;-ch&lt;/code&gt; → blocks until another goroutine does &lt;code&gt;ch &amp;lt;- value&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt; &lt;span class="c"&gt;// waits until someone receives&lt;/span&gt;
&lt;span class="p"&gt;}()&lt;/span&gt;

&lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "Hello"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧾 When to use&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want &lt;strong&gt;strict synchronization&lt;/strong&gt; between goroutines.&lt;/li&gt;
&lt;li&gt;You want the &lt;strong&gt;sender to wait&lt;/strong&gt; for the receiver.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔷 Buffered Channels — "Mailboxes"
&lt;/h2&gt;

&lt;p&gt;Buffered channels act like a &lt;strong&gt;mailbox&lt;/strong&gt;:&lt;br&gt;
The sender can drop messages into it and walk away, unless the mailbox is full.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// buffer size = 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;📦 How it behaves&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ch &amp;lt;-&lt;/code&gt; value &lt;strong&gt;blocks only&lt;/strong&gt; if the buffer is &lt;strong&gt;full&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;-ch&lt;/code&gt; &lt;strong&gt;blocks only&lt;/strong&gt; if the buffer is &lt;strong&gt;empty&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"one"&lt;/span&gt;  &lt;span class="c"&gt;// ✅ doesn't block&lt;/span&gt;
&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"two"&lt;/span&gt;  &lt;span class="c"&gt;// ✅ doesn't block&lt;/span&gt;
&lt;span class="c"&gt;// ch &amp;lt;- "three" // ❌ blocks — buffer is full&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "one"&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// "two"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧾 When to use&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to &lt;strong&gt;separate&lt;/strong&gt; the timing between sender and receiver&lt;/li&gt;
&lt;li&gt;You need to &lt;strong&gt;store a few values temporarily&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Producer works in bursts (faster than consumer)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔐 Closing Channels in Go
&lt;/h2&gt;

&lt;p&gt;Now let’s focus on &lt;strong&gt;closing channels&lt;/strong&gt;, a super important part of managing communication between goroutines. It’s not just about stopping data, it's about doing it the right way so your program stays safe, efficient, and bug-free.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Why Closing a Channel Matters
&lt;/h2&gt;

&lt;p&gt;Imagine you’re running a &lt;strong&gt;conveyor belt in a factory&lt;/strong&gt;. Workers (goroutines) put boxes (data) on the belt, and quality checkers (other goroutines) take those boxes off and inspect them.&lt;/p&gt;

&lt;p&gt;But here’s the thing:&lt;br&gt;
If the workers finish their job and leave &lt;strong&gt;without telling anyone&lt;/strong&gt;, the checkers will keep waiting, thinking more boxes will come. Forever. 😬&lt;/p&gt;

&lt;p&gt;In Go, &lt;strong&gt;closing a channel&lt;/strong&gt; is how workers say, "Hey, I’m done sending data!"&lt;/p&gt;

&lt;p&gt;That way, receivers (the checkers) know it's safe to stop waiting.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤔 What Happens When a Channel Is Closed?
&lt;/h2&gt;

&lt;p&gt;Here’s what you need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;✅ Receiving from a closed channel&lt;/strong&gt; still works! You’ll get:

&lt;ul&gt;
&lt;li&gt;All remaining values in the channel.&lt;/li&gt;
&lt;li&gt;Then &lt;strong&gt;zero values&lt;/strong&gt; (0, "", nil, etc.) after it’s empty.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Sending to a closed channel&lt;/strong&gt; causes a &lt;strong&gt;panic&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also check whether a channel is closed using the &lt;code&gt;ok&lt;/code&gt; idiom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Channel is closed!"&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;
  
  
  ⏳ When Should You Close a Channel?
&lt;/h2&gt;

&lt;p&gt;Here’s the golden rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🟢 Only the sender should close the channel.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And only when all data has been sent.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Do close the channel when sending is done.&lt;/li&gt;
&lt;li&gt;❌ Don't close from multiple places.&lt;/li&gt;
&lt;li&gt;❌ Don't close a channel if you're only receiving from it.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of closing a channel like turning off a faucet; only the person using it should do it.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ✅ How to Close a Channel
&lt;/h2&gt;

&lt;p&gt;You use the built-in &lt;code&gt;close()&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nb"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧪 Example: Properly Closing a Channel
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Hello from goroutine!"&lt;/span&gt;
    &lt;span class="nb"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Close after sending&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;messageChannel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageChannel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;messageChannel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"All messages received!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Received: Hello from goroutine!
All messages received!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;for range&lt;/code&gt; loop automatically stops when the channel is closed.&lt;br&gt;
Nice and clean!&lt;/p&gt;


&lt;h2&gt;
  
  
  ❗ What If We Don’t Close the Channel?
&lt;/h2&gt;

&lt;p&gt;Let’s say you forget to close the channel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Hello from goroutine!"&lt;/span&gt;
    &lt;span class="c"&gt;// ⚠️ No close&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;messageChannel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageChannel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;messageChannel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;// ⚠️ This will block forever&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;😱 This will cause a deadlock!&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;for range&lt;/code&gt; loop keeps waiting for new messages that will never come, because the sender is done but didn’t signal it. Your program will just hang.&lt;/p&gt;


&lt;h2&gt;
  
  
  📬 Analogy: Letters in the Mailbox
&lt;/h2&gt;

&lt;p&gt;Think of a channel like a &lt;strong&gt;mailbox&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📨 Senders put letters inside.&lt;/li&gt;
&lt;li&gt;📭 Receivers check and collect them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But if no one ever puts up a “no more letters” sign, the mailman keeps checking the box... forever. 🕳️&lt;/p&gt;

&lt;p&gt;Closing the channel = putting up that “no more mail” sign.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 Summary of Best Practices
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;✅ Do&lt;/th&gt;
&lt;th&gt;❌ Don’t&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Close the channel &lt;strong&gt;only from sender&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;❌ Don’t close the channel from receiver&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Close &lt;strong&gt;only once&lt;/strong&gt;, in &lt;strong&gt;one place&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;❌ Don’t close from multiple goroutines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use &lt;code&gt;for range ch&lt;/code&gt; to receive safely&lt;/td&gt;
&lt;td&gt;❌ Don’t send on a closed channel; panic!&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  🧵 What If Multiple Goroutines Are Sending?
&lt;/h2&gt;

&lt;p&gt;Here’s a &lt;strong&gt;common scenario&lt;/strong&gt;: You have &lt;strong&gt;multiple goroutines&lt;/strong&gt; sending data into the same channel.&lt;br&gt;
The problem?&lt;br&gt;
If more than one of them tries to close the channel — &lt;strong&gt;❌ Panic alert!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔑 Solution&lt;/strong&gt;:&lt;br&gt;
Use a &lt;code&gt;sync.WaitGroup&lt;/code&gt; to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Track when &lt;strong&gt;all&lt;/strong&gt; senders are done.&lt;/li&gt;
&lt;li&gt;Let a &lt;strong&gt;single, dedicated goroutine&lt;/strong&gt; close the channel after that.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧪 Example: Safe Channel Closing with Multiple Senders
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"worker %d done"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;numWorkers&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numWorkers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Start multiple sender goroutines&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;numWorkers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// 🔒 Dedicated goroutine to close the channel&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;     &lt;span class="c"&gt;// Wait until all workers are done&lt;/span&gt;
        &lt;span class="nb"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c"&gt;// ✅ Only one closer&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="c"&gt;// Receive from channel until it's closed&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Received: worker 1 done
Received: worker 2 done
Received: worker 3 done
Received: worker 4 done
Received: worker 5 done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 Why This Pattern Works:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Goroutines (Workers)&lt;/strong&gt;&lt;br&gt;
Each worker runs in its own goroutine, sends a message into &lt;code&gt;ch&lt;/code&gt;, and then calls &lt;code&gt;wg.Done()&lt;/code&gt; to signal it’s finished.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. WaitGroup&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;WaitGroup&lt;/code&gt; keeps track of all running workers.&lt;br&gt;
We start by calling &lt;code&gt;wg.Add(5)&lt;/code&gt; to tell it we're waiting for 5 workers.&lt;br&gt;
Each worker does &lt;code&gt;wg.Done()&lt;/code&gt; when it's finished.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Closing the Channel&lt;/strong&gt;&lt;br&gt;
We spawn a &lt;strong&gt;separate goroutine&lt;/strong&gt; whose only job is to wait until all workers are done (&lt;code&gt;wg.Wait()&lt;/code&gt;), and then safely close the channel.&lt;br&gt;
This ensures &lt;strong&gt;only one goroutine closes the channel&lt;/strong&gt;, and it does so after all sends are complete.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Receiving Messages&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;for msg := range ch&lt;/code&gt; loop reads messages as long as the channel is open.&lt;br&gt;
Once it's closed and empty, the loop ends, cleanly and safely.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 A Quick Note: What’s &lt;code&gt;chan&amp;lt;- string&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;You might have noticed this weird-looking function signature in our example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What’s that &lt;code&gt;chan&amp;lt;- string&lt;/code&gt; thing? 🤔&lt;/p&gt;

&lt;p&gt;This is a &lt;strong&gt;send-only channel&lt;/strong&gt;, meaning the worker function can only send data into the channel, not receive from it.&lt;/p&gt;

&lt;p&gt;It's a good practice because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It makes your code safer and easier to understand.&lt;/li&gt;
&lt;li&gt;It prevents accidental reads from the channel inside the sender.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a quick comparison:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&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;chan string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Read and write (send + receive)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;chan&amp;lt;- string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Send-only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;-chan string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Receive-only&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This kind of type narrowing helps Go enforce better separation of concerns between senders and receivers. 🛡️&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 Enter &lt;code&gt;select&lt;/code&gt;: Choosing Between Channels
&lt;/h2&gt;

&lt;p&gt;Sometimes, you're listening to &lt;strong&gt;multiple&lt;/strong&gt; channels and want to act as soon as &lt;strong&gt;any one&lt;/strong&gt; of them sends data.&lt;br&gt;
That’s exactly what &lt;code&gt;select&lt;/code&gt; is for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Motivation: Pick the First to Reply&lt;/strong&gt;&lt;br&gt;
Imagine you’re waiting for &lt;strong&gt;two friends&lt;/strong&gt; to text you.&lt;br&gt;
Whoever replies first, you’ll go hang out with them.&lt;/p&gt;

&lt;p&gt;That’s what &lt;code&gt;select&lt;/code&gt; does in Go. It waits for &lt;strong&gt;any one of multiple channels&lt;/strong&gt; to send data, and responds immediately.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧪 Example: First Response Wins
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"I'm fast!"&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"I'm slow!"&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Got: I'm fast!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;💡 What Happens?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first goroutine sleeps for &lt;strong&gt;1 second&lt;/strong&gt; and sends &lt;code&gt;"I'm fast!"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The second goroutine sleeps for &lt;strong&gt;2 seconds&lt;/strong&gt; and sends "I'm slow!"&lt;/li&gt;
&lt;li&gt;🔍 &lt;code&gt;select&lt;/code&gt; waits until any one of the channels is ready.&lt;/li&gt;
&lt;li&gt;Because &lt;code&gt;fast&lt;/code&gt; sends first, that case runs, and we skip the slower one!&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔁 What if Nothing Is Ready Yet?
&lt;/h2&gt;

&lt;p&gt;You can use a &lt;code&gt;default&lt;/code&gt; case inside &lt;code&gt;select&lt;/code&gt; to avoid blocking. Useful when you want to do something else if no channel is ready right now.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Example: &lt;code&gt;select&lt;/code&gt; with &lt;code&gt;default&lt;/code&gt; (Non-blocking)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"I'm fast!"&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"I'm slow!"&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="c"&gt;// Try to receive before any goroutine sends&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No messages yet. Doing something else."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Wait for messages to arrive&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Try again after waiting&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;fast&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Later got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Later got:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Still nothing..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No messages yet. Doing something else.
Later got: I'm fast!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 What Happens in This Program?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The first &lt;code&gt;select&lt;/code&gt; runs &lt;strong&gt;immediately&lt;/strong&gt;, but no message has arrived, so &lt;code&gt;default&lt;/code&gt; is chosen.&lt;/li&gt;
&lt;li&gt;Later, all channels are ready. When more than one case is ready, Go picks one &lt;strong&gt;at random&lt;/strong&gt;, so which one runs may change each time you run the program.:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Later got: I'm fast!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Later got: I'm slow!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;default&lt;/code&gt; when you don’t want to wait around, perfect for non-blocking checks or responsive UIs.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚦 Timeouts with select
&lt;/h2&gt;

&lt;p&gt;Another common pattern is using &lt;code&gt;select&lt;/code&gt; with a timeout channel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Create a channel to receive a string&lt;/span&gt;

    &lt;span class="c"&gt;// Start a goroutine that waits for 2 seconds and then sends a message&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Simulate a delay&lt;/span&gt;
        &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;"Finally got data!"&lt;/span&gt;   &lt;span class="c"&gt;// Send message after delay&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="c"&gt;// Use select to either receive from the channel or timeout&lt;/span&gt;
    &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="c"&gt;// If data is received from the channel before timeout&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Received:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;After&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="c"&gt;// If no data arrives in 1 second, this case runs&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Timeout! Moving on..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Timeout! Moving on...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧠 What's Happening?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The goroutine sleeps for 2 seconds before sending data.&lt;/li&gt;
&lt;li&gt;But &lt;code&gt;time.After(1 * time.Second)&lt;/code&gt; creates a channel that sends a signal after 1 second.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;select&lt;/code&gt; waits for whichever comes first.&lt;/li&gt;
&lt;li&gt;Since the timeout comes before the message, the program prints: &lt;code&gt;"Timeout! Moving on..."&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🧰 This pattern is super useful for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timing out slow network calls&lt;/li&gt;
&lt;li&gt;Canceling tasks that take too long&lt;/li&gt;
&lt;li&gt;Preventing your app from getting stuck waiting&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏁 Advanced Pattern: Fan-Out, Fan-In
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Fan-Out&lt;/strong&gt;, &lt;strong&gt;Fan-In&lt;/strong&gt; pattern is a powerful concurrency pattern in Go, designed to help distribute work across multiple workers and collect their results efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 What is Fan-Out, Fan-In?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;👨‍🍳 Fan-Out&lt;/strong&gt;: Distributing tasks across multiple workers (like assigning jobs to different team members).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🧾 Fan-In&lt;/strong&gt;: Gathering the results from all workers into one place (like collecting the completed work at the end of the day).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🍕 Think of it like a pizza restaurant:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fan-Out&lt;/strong&gt;: Customer orders are sent to multiple chefs, who each make different pizzas simultaneously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fan-In&lt;/strong&gt;: All completed pizzas are gathered at the same pickup counter for delivery.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's the Fan-Out, Fan-In pattern! It's a way to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Break a big task into smaller parts&lt;/li&gt;
&lt;li&gt;Work on those parts at the same time&lt;/li&gt;
&lt;li&gt;Combine all the results at the end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;✅ A Clearer Example (with Code)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"sync"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Step 1: Create channels for jobs and results&lt;/span&gt;
    &lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c"&gt;// Channel to send work&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c"&gt;// Channel to collect results&lt;/span&gt;

    &lt;span class="c"&gt;// Step 2: Start multiple workers (Fan-Out)&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;
    &lt;span class="n"&gt;numberOfWorkers&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;

    &lt;span class="c"&gt;// Launch 3 workers&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Starting workers..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numberOfWorkers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;workerId&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;workerId&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;numberOfWorkers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;workerId&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;// Start each worker in its own goroutine&lt;/span&gt;
        &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;workerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Step 3: Send jobs to the workers&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sending jobs..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;jobsToProcess&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="c"&gt;// We'll process 6 jobs&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;jobsToProcess&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Close jobs channel to signal no more jobs&lt;/span&gt;

    &lt;span class="c"&gt;// Step 4: Wait for all workers to finish and close results channel&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Wait&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Wait for all workers to finish&lt;/span&gt;
        &lt;span class="nb"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Signal that all results are collected&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;

    &lt;span class="c"&gt;// Step 5: Collect and print all results (Fan-In)&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Collecting results..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;totalProcessed&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;totalProcessed&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Got result: %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;All done! Processed %d jobs with %d workers&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="n"&gt;totalProcessed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numberOfWorkers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// worker function: processes jobs and sends back results&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt;&lt;span class="k"&gt;chan&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="k"&gt;chan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WaitGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;wg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Done&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c"&gt;// Mark this worker as done when the function exits&lt;/span&gt;

    &lt;span class="c"&gt;// Process all jobs assigned to this worker&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Worker %d started job %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c"&gt;// Simulate actual work with different durations&lt;/span&gt;
        &lt;span class="n"&gt;workTime&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;300&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Millisecond&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;workTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;500&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Millisecond&lt;/span&gt; &lt;span class="c"&gt;// Even numbered jobs take longer&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;workTime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c"&gt;// Send the result (job × 10) back through results channel&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
        &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Worker %d finished job %d → result: %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Worker %d completed all assigned jobs&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&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;
  
  
  🔍 How the Fan-Out, Fan-In Example Works Step-by-Step)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.🛠 Setting Up the Channels&lt;/strong&gt;&lt;br&gt;
We create two channels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;jobs&lt;/code&gt; channel: To send work to workers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;results&lt;/code&gt; channel: To collect completed work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.🧯 Fan-Out Process&lt;/strong&gt;&lt;br&gt;
We create 3 worker goroutines that run simultaneously:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each worker runs independently in the background&lt;/li&gt;
&lt;li&gt;All workers watch the same &lt;code&gt;jobs&lt;/code&gt; channel for incoming work&lt;/li&gt;
&lt;li&gt;This distributes the workload across multiple processors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.📦 Sending Jobs&lt;/strong&gt;&lt;br&gt;
We push &lt;strong&gt;6 jobs&lt;/strong&gt; into the &lt;code&gt;jobs&lt;/code&gt; channel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each worker picks up jobs as they become available&lt;/li&gt;
&lt;li&gt;Workers might process different numbers of jobs depending on their speed&lt;/li&gt;
&lt;li&gt;We close the &lt;code&gt;jobs&lt;/code&gt; channel to signal that &lt;strong&gt;no more work is coming&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4.📥 Fan-In Process&lt;/strong&gt;&lt;br&gt;
We collect all results through the single &lt;code&gt;results&lt;/code&gt; channel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As each worker finishes a job, it sends the result to the &lt;code&gt;results&lt;/code&gt; channel&lt;/li&gt;
&lt;li&gt;The main program reads all results from the &lt;code&gt;results&lt;/code&gt; channel&lt;/li&gt;
&lt;li&gt;We only close the &lt;code&gt;results&lt;/code&gt; channel after &lt;strong&gt;all workers are done&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5.🔒 Coordination with WaitGroup&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;sync.WaitGroup&lt;/code&gt; ensures that we:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Know when all workers are done.&lt;/li&gt;
&lt;li&gt;Only close the &lt;code&gt;results&lt;/code&gt; channel once all processing is finished.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🛠 Real-World Applications
&lt;/h3&gt;

&lt;p&gt;This pattern is useful when you need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Process many items in parallel (e.g., analyzing multiple files).&lt;/li&gt;
&lt;li&gt;Make multiple API calls simultaneously&lt;/li&gt;
&lt;li&gt;Break a large task into smaller independent pieces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like &lt;strong&gt;multiple cashiers at a store (fan-out)&lt;/strong&gt; all putting money into the &lt;strong&gt;same safe at the end of their shift (fan-in)&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Key Benefits of This Pattern
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Speed&lt;/strong&gt;: Work happens in parallel, making better use of multiple CPU cores&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: You can easily adjust the number of workers based on your needs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Control&lt;/strong&gt;: Channels act as buffers to prevent overwhelming the system&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔍 What's Happening Under the Hood
&lt;/h2&gt;

&lt;p&gt;When you run this code, you'll see workers picking up jobs at different times and finishing at different speeds. Some might do more work than others, but together they finish all the jobs much faster than doing them one by one!&lt;/p&gt;

&lt;p&gt;Think of it like multiple checkout lanes at a grocery store versus having just one lane - everything gets done much faster than using just one!&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Conclusion
&lt;/h2&gt;

&lt;p&gt;Go makes it easy to write programs that can do many things at the same time, which is called concurrency. It helps your programs run faster and stay responsive.&lt;/p&gt;

&lt;p&gt;Here are the main things to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goroutines&lt;/strong&gt; are like super-lightweight threads; they let your code run in the background without much cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Channels&lt;/strong&gt; are the safe way for goroutines to talk to each other and share data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WaitGroups&lt;/strong&gt; help you wait until a group of goroutines finishes their work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mutexes&lt;/strong&gt; are tools that make sure only one goroutine can use a shared resource at a time; this prevents bugs called race conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Select&lt;/strong&gt; lets you listen to multiple channels and respond to whichever one is ready first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mastering these tools step by step will help you build faster, more efficient Go programs.&lt;/p&gt;

&lt;p&gt;🚀 Happy concurrent programming!&lt;/p&gt;




</description>
      <category>go</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>Its Dark: A Dark VSCode Theme</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Sat, 01 Jan 2022 15:20:15 +0000</pubDate>
      <link>https://dev.to/iamismile/its-dark-a-dark-vscode-theme-29an</link>
      <guid>https://dev.to/iamismile/its-dark-a-dark-vscode-theme-29an</guid>
      <description>&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=iamismiledev.its-dark" rel="noopener noreferrer"&gt;&lt;img src="https://media.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%2F3ei1905r9nm5dityos0t.png" alt="Its Dark Theme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the day I have started to use VSCode several themes are used by me. Among all of those most used ones are Just Black &amp;amp; Snazzy Operator. &lt;a href="https://marketplace.visualstudio.com/items?itemName=iamismiledev.its-dark" rel="noopener noreferrer"&gt;Its Dark&lt;/a&gt; is based on these themes with some changes. Some screenshots are given below to check how its look like. For best view and feel install and start to use it.&lt;/p&gt;

&lt;p&gt;👩‍💻 JavaScript&lt;br&gt;
&lt;a href="https://media.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%2F2lnuzulekgb2o036fs7a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F2lnuzulekgb2o036fs7a.png" alt="Its Dark (JavaScript)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👩‍💻 TypeScript&lt;br&gt;
&lt;a href="https://media.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%2Fz6euri6d4z9p0pk47lh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fz6euri6d4z9p0pk47lh3.png" alt="Its Dark (TypeScript)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👩‍💻 HTML&lt;br&gt;
&lt;a href="https://media.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%2Fn2nzvqzlmw5wjuqkojgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fn2nzvqzlmw5wjuqkojgh.png" alt="Its Dark (HTML)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👩‍💻 CSS&lt;br&gt;
&lt;a href="https://media.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%2Fb4vv9tbuools2cw4mocj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fb4vv9tbuools2cw4mocj.png" alt="Its Dark (CSS)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👋 Hope you're gonna enjoy this theme.🙂&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>themes</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Web Development Resources</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Fri, 06 Nov 2020 09:49:55 +0000</pubDate>
      <link>https://dev.to/iamismile/web-development-resources-96</link>
      <guid>https://dev.to/iamismile/web-development-resources-96</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyircgjcc7wekbi8j9z08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyircgjcc7wekbi8j9z08.png" alt="Web Development Resources Logo"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;This is a complete web development resource you need to build your next project. More than 150+ resources for your web development.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;This is a shortlist of my Github &lt;a href="https://github.com/iamismile/web-dev-resources" rel="noopener noreferrer"&gt;Web Dev Resources&lt;/a&gt; repo. To get all the resources, visit my &lt;a href="https://github.com/iamismile/web-dev-resources" rel="noopener noreferrer"&gt;repo&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🌟 &lt;strong&gt;Resources&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  💻 DEVELOPER ROADMAPS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://roadmap.sh/frontend" rel="noopener noreferrer"&gt;Frontend&lt;/a&gt; - Frontend Development Roadmap.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://roadmap.sh/backend" rel="noopener noreferrer"&gt;Backend&lt;/a&gt; - Backend Development Roadmap.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://roadmap.sh/react" rel="noopener noreferrer"&gt;React&lt;/a&gt; - React Development Roadmap.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📚 DOCUMENTATIONS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/" rel="noopener noreferrer"&gt;MDN Web Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devdocs.io" rel="noopener noreferrer"&gt;DevDocs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🎭 DESIGN TOOLS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.figma.com" rel="noopener noreferrer"&gt;Figma&lt;/a&gt; - Figma helps teams create, test, and ship better designs from start to finish.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.adobe.com/products/xd.html" rel="noopener noreferrer"&gt;Adobe XD&lt;/a&gt; - Share your story with designs that look and feel like the real thing. Wireframe, animate, prototype, collaborate, and more — it’s all right here, all in one place.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🌐 HOW THE WEB WORKS?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=x3c1ih2NJEg" rel="noopener noreferrer"&gt;How the Internet Works Video&lt;/a&gt; - How does the Internet Works?&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/playlist?list=PLzdnOPI1iJNfMRZm5DDxco3UdsFegvuB7" rel="noopener noreferrer"&gt;How the Internet Works Brief Videos&lt;/a&gt; - A brief explanations on, how does the Internet works?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🖼 HTML AND CSS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/learn" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt; - Free course to learn Web Development.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;HTML Elements&lt;/a&gt; - HTML elements reference by MDN.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://css-tricks.com/snippets/html/glyphs/" rel="noopener noreferrer"&gt;HTML Entity&lt;/a&gt; - HTML Entity Reference by CSS-Tricks.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference" rel="noopener noreferrer"&gt;CSS3 Properties&lt;/a&gt; - CSS reference by MDN.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cssreference.io" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt; - A free visual guide to CSS.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://flexboxfroggy.com" rel="noopener noreferrer"&gt;Flexbox Froggy&lt;/a&gt; - A game that helps you to learn CSS Flex.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/" rel="noopener noreferrer"&gt;CSS-TRICKS Flexbox&lt;/a&gt; - A Complete Guide to Flexbox.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cssgridgarden.com" rel="noopener noreferrer"&gt;Grid Garden&lt;/a&gt; - A game for learning CSS Grid.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learncssgrid.com" rel="noopener noreferrer"&gt;Learn CSS Grid&lt;/a&gt; - A comprehensive guide to help you understand and learn CSS Grid Layout, by Jonathan Suh.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://caniuse.com" rel="noopener noreferrer"&gt;Can I Use&lt;/a&gt; - Up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://emilkowalski.github.io/css-effects-snippets/" rel="noopener noreferrer"&gt;CSS Effects&lt;/a&gt; - CSS Animations.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://keyframes.app" rel="noopener noreferrer"&gt;Keyframes&lt;/a&gt; - Create basic or complex CSS &lt;a class="mentioned-user" href="https://dev.to/keyframe"&gt;@keyframe&lt;/a&gt; animations with a visual timeline editor.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://animista.net" rel="noopener noreferrer"&gt;Animista&lt;/a&gt; - Play with a collection of ready to use CSS animations.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://9elements.com/bem-cheat-sheet" rel="noopener noreferrer"&gt;BEM&lt;/a&gt; - BEM naming cheat sheet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🖋 FONTS AND TYPOGRAPHY
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://fonts.google.com" rel="noopener noreferrer"&gt;Google Fonts&lt;/a&gt; - The #1 resource for free and easy-to-use webfonts&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fontsarena.com" rel="noopener noreferrer"&gt;Fonts Arena&lt;/a&gt; - Free fonts, free alternatives to premium fonts, done-for-you-research articles&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fontpair.co" rel="noopener noreferrer"&gt;FontPair&lt;/a&gt; - Font Pair helps designers pair Google Fonts together. Beautiful Google Font combinations and pairs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🌈 COLORS AND TOOLS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://coolors.co" rel="noopener noreferrer"&gt;Coolors&lt;/a&gt; - Generate or browse beautiful color combinations for your designs&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.0to255.com" rel="noopener noreferrer"&gt;0to255&lt;/a&gt; - A color tool that makes it easy to lighten and darken colors&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.colorsandfonts.com" rel="noopener noreferrer"&gt;Colors and Fonts&lt;/a&gt; - Find colors and typography combinations ready to copy-paste in one click&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mycolor.space" rel="noopener noreferrer"&gt;ColorSpace&lt;/a&gt; - Generate nice Color Palettes&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cssgradient.io" rel="noopener noreferrer"&gt;CSS Gradient&lt;/a&gt; - Free css gradient generator tool&lt;/li&gt;
&lt;li&gt;
&lt;a href="//uigradients.com"&gt;uiGradients&lt;/a&gt; - A handpicked collection of beautiful color gradients for designers and developers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📷 IMAGE RESOURCES
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://unsplash.com" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt; - Free images and photos.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.pexels.com" rel="noopener noreferrer"&gt;Pexels&lt;/a&gt; - Free stock photos.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pixabay.com" rel="noopener noreferrer"&gt;Pixabay&lt;/a&gt; - Free image or video.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://lottiefiles.com" rel="noopener noreferrer"&gt;LottieFiles&lt;/a&gt; - LottieFiles is a collection of animations designed for Lottie - gone are the days of bugging your developer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.remove.bg" rel="noopener noreferrer"&gt;removebg&lt;/a&gt; - Remove Image Background.&lt;/li&gt;
&lt;li&gt;
&lt;a href="//removephotodata.com/"&gt;Remove Photo Data&lt;/a&gt; - Remove personal data from photos before sharing them on the internet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🎨 ILLUSTRATIONS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://undraw.co/illustrations" rel="noopener noreferrer"&gt;unDraw&lt;/a&gt; - Browse to find the illustrations that fit your needs and click to download.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.manypixels.co/gallery/" rel="noopener noreferrer"&gt;manypixels&lt;/a&gt; - Free illustrations to power up your projects. Use them in a commercial or non-commercial way for your landing pages, blog posts, email newsletters, social media graphics, and more.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freepik.com" rel="noopener noreferrer"&gt;freepik&lt;/a&gt; - Free graphic resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  💧 ICONS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://ionicons.com" rel="noopener noreferrer"&gt;Ionicons&lt;/a&gt; - Open-Sourced and MIT licensed icon pack&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fontawesome.com" rel="noopener noreferrer"&gt;Font Awesome&lt;/a&gt; - Vector icons and social logos&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://material.io/resources/icons/?style=baseline" rel="noopener noreferrer"&gt;Material Icons&lt;/a&gt; - Material icons are delightful, beautifully crafted symbols for common actions and items. Download on desktop to use them in your digital products for Android, iOS, and web.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://icons8.com/icons" rel="noopener noreferrer"&gt;icons8&lt;/a&gt; - Download free icons in PNG and SVG.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.flaticon.com" rel="noopener noreferrer"&gt;flaticon&lt;/a&gt; - Free vector icons in SVG, PSD, PNG, EPS format or as ICON FONT&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚙ GENERATORS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://loremipsum.io" rel="noopener noreferrer"&gt;Lorem Ipsum&lt;/a&gt; - Lorem Ipsum generator&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://realfavicongenerator.net" rel="noopener noreferrer"&gt;RealFaviconGenerator&lt;/a&gt; - Favicon generator&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://formito.com/tools/favicon" rel="noopener noreferrer"&gt;Favicon Maker&lt;/a&gt; - Free Favicon maker&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://metatags.io" rel="noopener noreferrer"&gt;Meta Tags&lt;/a&gt; - Meta Tags generator, preview how your webpage will look on Google, Facebook, Twitter, and more!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://bennettfeely.com/clippy/" rel="noopener noreferrer"&gt;Clippy&lt;/a&gt; - CSS clip-path maker.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  👓 ACCESSIBILITY
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://uxdesign.cc/designing-for-accessibility-is-not-that-hard-c04cc4779d94" rel="noopener noreferrer"&gt;Accessibility Blog - Medium&lt;/a&gt; - Seven easy-to-implement guidelines to design a more accessible web.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/erhannah/13-ways-to-level-up-your-site-s-accessibility-22c6"&gt;Accessibility Blog - Dev&lt;/a&gt; - 13 ways to level up your site's accessibility.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://moritzgiessmann.de/accessibility-cheatsheet" rel="noopener noreferrer"&gt;Accessibility Cheatsheet&lt;/a&gt; - Practical approaches to Universal Design for making your website/web app accessible to everyone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📉 SITE ANALYZERS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="//web.dev/measure"&gt;web.dev&lt;/a&gt; - See how well your website performs. Then, get tips to improve your user experience.&lt;/li&gt;
&lt;li&gt;
&lt;a href="//lighthouse-metrics.com"&gt;Lighthouse Metrics&lt;/a&gt; - Lighthouse Metrics provides easy insights into your site's performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📄 TERMINALS FOR WINDOWS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab" rel="noopener noreferrer"&gt;Windows Terminal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/felixse/FluentTerminal" rel="noopener noreferrer"&gt;FluentTerminal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hyper.is" rel="noopener noreferrer"&gt;Hyper&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cmder.net//" rel="noopener noreferrer"&gt;Cmder&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📝 ONLINE IDE, EDITOR
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://repl.it/" rel="noopener noreferrer"&gt;Repl.it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io" rel="noopener noreferrer"&gt;CodeSandbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codepen.io" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jsbin.com/" rel="noopener noreferrer"&gt;JS Bin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ide.goorm.io" rel="noopener noreferrer"&gt;JSFiddle&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ JAVASCRIPT
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/learn" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt; - Best free resource to learn JavaScript interactively.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codecademy.com/learn/introduction-to-javascript" rel="noopener noreferrer"&gt;Codecademy&lt;/a&gt; - Free course to learn JavaScript interactively.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://javascript.info" rel="noopener noreferrer"&gt;JavaScript.info&lt;/a&gt; - Modern JavaScript Tutorial.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://eloquentjavascript.net" rel="noopener noreferrer"&gt;Eloquent JavaScript&lt;/a&gt; - This is a book about JavaScript, programming, and the wonders of the digital. You can read it online here.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://javascript30.com" rel="noopener noreferrer"&gt;JavaScript30&lt;/a&gt; - 30 days vanilla JS coding challenge. Build 30 things in 30 days with 30 tutorials.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference" rel="noopener noreferrer"&gt;JavaScript Reference By MDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events" rel="noopener noreferrer"&gt;JavaScript Event Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://youmightnotneedjquery.com" rel="noopener noreferrer"&gt;DOM Manipulation Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/" rel="noopener noreferrer"&gt;JavaScript Design Patterns&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ NODEJS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/playlist?list=PL4cUxeGkcC9jsz4LDYc6kv3ymONOKxwBU" rel="noopener noreferrer"&gt;Node.js Tutorial&lt;/a&gt; - Node.js Crash Course Tutorial by Net Ninja.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/goldbergyoni/nodebestpractices" rel="noopener noreferrer"&gt;nodebestpractices&lt;/a&gt; - Huge list of best practices for building node apps. Important for big projects.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://thenodeway.io" rel="noopener noreferrer"&gt;The Node Way&lt;/a&gt; - An entire philosophy of Node.js best practices a0nd guiding principles exists for writing maintainable modules, scalable applications, and code that is actually pleasant to read.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/news/express-js-security-tips/" rel="noopener noreferrer"&gt;Express.js Security Tips&lt;/a&gt; - How You Can Save and Secure Your App.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ PYTHON
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.codecademy.com/learn/learn-python" rel="noopener noreferrer"&gt;Codecademy&lt;/a&gt; - Free course to learn Python interactively.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.programiz.com/python-programming" rel="noopener noreferrer"&gt;Programiz&lt;/a&gt; - Learn Python Programming.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/vinta/awesome-python" rel="noopener noreferrer"&gt;Awesome Python&lt;/a&gt; - A curated list of awesome Python frameworks, libraries, software, and resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ REACT
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org" rel="noopener noreferrer"&gt;React&lt;/a&gt; - Official site documentations, tutorial.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codecademy.com/learn/react-101" rel="noopener noreferrer"&gt;Codecademy&lt;/a&gt; - Free React course of Codecademy.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/learn" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt; - Free web development resourse, where you can also learn react.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=iZhV0bILFb0" rel="noopener noreferrer"&gt;React Tutorial&lt;/a&gt; - React Tutorial - Fundamentals, Hooks, Context API, React Router, Custom Hooks by Coding Addict.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=l0JbuMVXaTs" rel="noopener noreferrer"&gt;React Beach Resort&lt;/a&gt; - React Beach Resort project by Coding Addict.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🎮 APIs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://jsonplaceholder.typicode.com" rel="noopener noreferrer"&gt;JSONPlaceholder&lt;/a&gt; - Free to use fake online REST API for testing and prototyping.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://openweathermap.org/guide" rel="noopener noreferrer"&gt;OpenWeather&lt;/a&gt; - Simple and fast and free weather API from OpenWeatherMap you have access to current weather data, hourly, 5- and 16-day forecasts.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://swapi.dev" rel="noopener noreferrer"&gt;SWAPI&lt;/a&gt; - The Star Wars API.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://quotes.rest" rel="noopener noreferrer"&gt;Quotes REST API&lt;/a&gt; - They Said So has more than 1 million+ quotes in the database, the largest such database in the world. And Quotes API gives an easy way to access the data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🛠 DEVELOPER TOOLS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.postman.com" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; - Postman makes API development easy. Simplify each step of building an API and streamline collaboration so you can create better APIs—faster.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://insomnia.rest" rel="noopener noreferrer"&gt;Insomnia&lt;/a&gt; - Leading Open Source API Client, and Collaborative API Design Platform for GraphQL, and REST.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📖 ONLINE LEARNING RESOURCES
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com" rel="noopener noreferrer"&gt;freeCodeCamp&lt;/a&gt; - Learn to code at home. Build projects. Earn certifications.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com" rel="noopener noreferrer"&gt;w3schools&lt;/a&gt; - The world's largest Web Developer site. Tutorials references, examples, exercises, certificates.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codecademy.com/" rel="noopener noreferrer"&gt;Codecademy&lt;/a&gt; - Learn the technical skills you need for the job you want. As leaders in online education and learning to code.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.programiz.com" rel="noopener noreferrer"&gt;Programiz&lt;/a&gt; - Learn to code in Python, C/C++, Java, and other popular programming languages with our easy to follow tutorials, examples, online compiler, and references.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://javascript.info" rel="noopener noreferrer"&gt;JavaScript Info&lt;/a&gt; - The Modern JavaScript Tutorial.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/iamismile/command-line-tutorial-58km"&gt;Command Line Tutorial&lt;/a&gt; - Basic UNIX commands tutorial.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://try.github.io" rel="noopener noreferrer"&gt;Try Git&lt;/a&gt; - An interactive series of challenges to learn about and experiment with Git.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📦 OTHERS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://httpstatuses.com" rel="noopener noreferrer"&gt;HTTP Status Codes&lt;/a&gt; - HTTP Status Code directory, with definitions, details and helpful code references.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tiny-helpers.dev" rel="noopener noreferrer"&gt;Tiny Helpers&lt;/a&gt; - A collection of free single-purpose online tools for web developers.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://free-for.dev#/" rel="noopener noreferrer"&gt;Free for Developers&lt;/a&gt; - This is a list of software and other offerings that have free tiers for developers.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;This is a shortlist of my Github &lt;a href="https://github.com/iamismile/web-dev-resources" rel="noopener noreferrer"&gt;Web Dev Resources&lt;/a&gt; repo. To get all the resources, visit my &lt;a href="https://github.com/iamismile/web-dev-resources" rel="noopener noreferrer"&gt;repo&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Command Line (Tutorial)</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Sun, 15 Mar 2020 05:52:32 +0000</pubDate>
      <link>https://dev.to/iamismile/command-line-tutorial-58km</link>
      <guid>https://dev.to/iamismile/command-line-tutorial-58km</guid>
      <description>&lt;h2&gt;
  
  
  💻 Command Line:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;The command line is a tool or interfaces for interacting with a computer using only text rather than the mouse.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Command-Line is an essential tool for software development. We can execute a wide variety of programs on our computer through this. In this tutorial, we are going to learn the necessary UNIX commands for development.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;UNIX&lt;/strong&gt; command is a type of command that is used in LINUX and macOS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;To run some basic UNIX command in windows you need to download Git Command Line Interface from  &lt;a href="https://git-scm.com/"&gt;Git SCM&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🔰 Getting Started:
&lt;/h2&gt;

&lt;p&gt;✨ Let's start to learn (can use it as a reference guide)🏃‍♂️🏃‍♂️🏃‍♂️...&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Check the Current Directory ➡ &lt;code&gt;pwd&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;On the command line, it's important to know the directory we are currently working on. For that, we can use &lt;code&gt;pwd&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hyXhZKsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zc8x64v83cupsyn77bw5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hyXhZKsu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zc8x64v83cupsyn77bw5.gif" alt="Checking the Current Directory" width="600" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It shows that I'm working on my &lt;strong&gt;Desktop&lt;/strong&gt; directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Display List of Files ➡ &lt;code&gt;ls&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;To see the list of files and directories in the current directory use &lt;code&gt;ls&lt;/code&gt; command in your CLI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dIbM-KXP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/mb3bqmhd0wblcskhito4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dIbM-KXP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/mb3bqmhd0wblcskhito4.gif" alt="Displaying List of Files" width="600" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shows all of my files and directories of my &lt;strong&gt;Desktop&lt;/strong&gt; directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To show the contents of a directory pass the directory name to the &lt;code&gt;ls&lt;/code&gt; command i.e. &lt;code&gt;ls directory_name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Some useful &lt;code&gt;ls&lt;/code&gt; command options:-&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&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;ls -a&lt;/td&gt;
&lt;td&gt;list all files including hidden file starting with '.'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ls -l&lt;/td&gt;
&lt;td&gt;list with the long format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ls -la&lt;/td&gt;
&lt;td&gt;list long format including hidden files&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  ✔ Create a Directory ➡ &lt;code&gt;mkdir&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;We can create a new folder using the &lt;code&gt;mkdir&lt;/code&gt; command. To use it type &lt;code&gt;mkdir folder_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fJoUiCPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/axpfdcqa2xx2vf270w6l.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fJoUiCPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/axpfdcqa2xx2vf270w6l.gif" alt="Creating a Directory" width="600" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;ls&lt;/code&gt; command to see the directory is created or not.&lt;/p&gt;

&lt;p&gt;I created a &lt;strong&gt;cli-practice&lt;/strong&gt; directory in my working directory i.e. &lt;strong&gt;Desktop&lt;/strong&gt; directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Move Between Directories ➡ &lt;code&gt;cd&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;It's used to change directory or to move other directories. To use it type &lt;code&gt;cd directory_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SmmiZkSo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/hqqz7mdl0z2wyr7axiak.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SmmiZkSo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/hqqz7mdl0z2wyr7axiak.gif" alt="Moving Between Directories" width="600" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Can use &lt;code&gt;pwd&lt;/code&gt; command to confirm your directory name.&lt;/p&gt;

&lt;p&gt;Changed my directory to the &lt;strong&gt;cli-practice&lt;/strong&gt; directory. And the rest of the tutorial I'm gonna work within this directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Parent Directory ➡ &lt;code&gt;..&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;We have seen &lt;code&gt;cd&lt;/code&gt; command to change directory but if we want to move back or want to move to the parent directory we can use a special symbol &lt;code&gt;..&lt;/code&gt; after &lt;code&gt;cd&lt;/code&gt; command, like &lt;code&gt;cd ..&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Create Files ➡ &lt;code&gt;touch&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;We can create an empty file by typing &lt;code&gt;touch file_name&lt;/code&gt;. It's going to create a new file in the current directory (the directory you are currently in) with your provided name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Fnie9xY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/qnlntplxwyiotd4ouxks.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Fnie9xY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/qnlntplxwyiotd4ouxks.gif" alt="Creating Files" width="600" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a &lt;strong&gt;hello.txt&lt;/strong&gt; file in my current working directory. Again you can use &lt;code&gt;ls&lt;/code&gt; command to see the file is created or not.&lt;/p&gt;

&lt;p&gt;Now open your &lt;strong&gt;hello.txt&lt;/strong&gt; file in your text editor and write &lt;strong&gt;&lt;em&gt;Hello Everyone!&lt;/em&gt;&lt;/strong&gt; into your &lt;strong&gt;hello.txt&lt;/strong&gt; file and save it.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Display the Content of a File ➡ &lt;code&gt;cat&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;We can display the content of a file using the &lt;code&gt;cat&lt;/code&gt; command. To use it type &lt;code&gt;cat file_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Ft3CHWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/8k5jyuh8fzr8lltoz2eq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Ft3CHWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/8k5jyuh8fzr8lltoz2eq.gif" alt="Displaying the Content of a File" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shows the content of my &lt;strong&gt;hello.txt&lt;/strong&gt; file.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Move Files &amp;amp; Directories ➡ &lt;code&gt;mv&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;To move a file and directory, we use &lt;code&gt;mv&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;By typing &lt;code&gt;mv file_to_move destination_directory&lt;/code&gt;, you can move a file to the specified directory.&lt;/p&gt;

&lt;p&gt;By entering &lt;code&gt;mv directory_to_move destination_directory&lt;/code&gt;, you can move all the files and directories under that directory.&lt;/p&gt;

&lt;p&gt;Before using this command, we are going to create two more directories and another &lt;strong&gt;txt&lt;/strong&gt; file in our &lt;strong&gt;cli-practice&lt;/strong&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir html css&lt;br&gt;
touch bye.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--04Yz_nm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/84r3xpz86tl2838f7ghj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--04Yz_nm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/84r3xpz86tl2838f7ghj.gif" alt="Creating Directories and File" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, we can use multiple directories &amp;amp; files names one after another to create multiple directories &amp;amp; files in one command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pRNZZu24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/t31sfyg3gisqq1m7yamn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pRNZZu24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/t31sfyg3gisqq1m7yamn.gif" alt="Moving Files &amp;amp; Directories" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moved my &lt;strong&gt;bye.txt&lt;/strong&gt; file into my &lt;strong&gt;css&lt;/strong&gt; directory and then moved my &lt;strong&gt;css&lt;/strong&gt; directory into my &lt;strong&gt;html&lt;/strong&gt; directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Rename Files &amp;amp; Directories ➡ &lt;code&gt;mv&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;mv&lt;/code&gt; command can also be used to rename a file and a directory.&lt;/p&gt;

&lt;p&gt;You can rename a file by typing &lt;code&gt;mv old_file_name new_file_name&lt;/code&gt; &amp;amp; also rename a directory by typing &lt;code&gt;mv old_directory_name new_directory_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sIpd5gIu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/e87msrwtaquirwr9uj7k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sIpd5gIu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/e87msrwtaquirwr9uj7k.gif" alt="Renaming Files &amp;amp; Directories" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Renamed my &lt;strong&gt;hello.txt&lt;/strong&gt; file to the &lt;strong&gt;hi.txt&lt;/strong&gt; file and &lt;strong&gt;html&lt;/strong&gt; directory to the &lt;strong&gt;folder&lt;/strong&gt; directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Copy Files &amp;amp; Directories ➡ &lt;code&gt;cp&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;To do this, we use the &lt;code&gt;cp&lt;/code&gt; command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can copy a file by entering &lt;code&gt;cp file_to_copy new_file_name&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7rdKL_yB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/krufbxwa4aqr3h2woh9s.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7rdKL_yB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/krufbxwa4aqr3h2woh9s.gif" alt="Copying Files" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copied my &lt;strong&gt;hi.txt&lt;/strong&gt; file content into &lt;strong&gt;hello.txt&lt;/strong&gt; file. For confirmation open your &lt;strong&gt;hello.txt&lt;/strong&gt; file in your text editor.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can also copy a directory by adding the &lt;code&gt;-r&lt;/code&gt; option, like &lt;code&gt;cp -r directory_to_copy new_directory_name&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The &lt;code&gt;-r&lt;/code&gt; option for "recursive" means that it will copy all of the files including the files inside of subfolders.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gMWpunl7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ti0mg364x7bzenxg9ngk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gMWpunl7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ti0mg364x7bzenxg9ngk.gif" alt="Copying Directories" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I copied all of the files from the &lt;strong&gt;folder&lt;/strong&gt; to &lt;strong&gt;folder-copy&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Remove Files &amp;amp; Directories ➡ &lt;code&gt;rm&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;To do this, we use the &lt;code&gt;rm&lt;/code&gt; command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To remove a file, you can use the command like &lt;code&gt;rm file_to_remove&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DDTprsYz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/v80xozyz0gqorwf6t1ww.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DDTprsYz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/v80xozyz0gqorwf6t1ww.gif" alt="Removing Files" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I removed my &lt;strong&gt;hi.txt&lt;/strong&gt; file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To remove a directory, use the command like &lt;code&gt;rm -r directory_to_remove&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uzTKiPZ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/79v6p4j0c74a11w24ugp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uzTKiPZ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/79v6p4j0c74a11w24ugp.gif" alt="Removing Directories" width="600" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I removed my &lt;strong&gt;folder-copy&lt;/strong&gt; directory from my &lt;strong&gt;cli-practice&lt;/strong&gt; directory i.e. current working directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Clear Screen ➡ &lt;code&gt;clear&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;Clear command is used to clear the terminal screen.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Home Directory ➡ &lt;code&gt;~&lt;/code&gt;:
&lt;/h4&gt;

&lt;p&gt;The Home directory is represented by &lt;code&gt;~&lt;/code&gt;. The Home directory refers to the base directory for the user. If we want to move to the Home directory we can use &lt;code&gt;cd ~&lt;/code&gt; command. Or we can only use &lt;code&gt;cd&lt;/code&gt; command.&lt;/p&gt;




&lt;h3&gt;
  
  
  🛠 Tools I used for this tutorial:-
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/felixse/FluentTerminal"&gt;Fluent Terminal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com"&gt;Git Bash Shell&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Github repo of this tutorial &lt;a href="https://github.com/iamismile/learn-basic-commands"&gt;Learn Basic Commands&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Thanks for reading and stay tuned.🙂👋&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>unix</category>
      <category>commandline</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My VS Code Setup</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Thu, 20 Feb 2020 04:05:11 +0000</pubDate>
      <link>https://dev.to/iamismile/my-vs-code-setup-4fcd</link>
      <guid>https://dev.to/iamismile/my-vs-code-setup-4fcd</guid>
      <description>&lt;p&gt;There are a lot of Code Editors, some are free and some are paid. Among all of them my favorite Code Editor is &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;. It's free and has amazing features. I'm using it from the beginning of my web development journey.&lt;/p&gt;

&lt;p&gt;Today I'm going to share my favorite Code Editor settings, using for my web development. And I'm going to start with my Code Editor looks. After all look matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎨 Theme:
&lt;/h2&gt;

&lt;p&gt;My most used VS Code theme is &lt;a href="https://marketplace.visualstudio.com/items?itemName=aaronthomas.vscode-snazzy-operator" rel="noopener noreferrer"&gt;Snazzy Operator&lt;/a&gt;, currently I'm using this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1izus76qw2ekqrnrbkx3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1izus76qw2ekqrnrbkx3.jpg" alt="VS Code Theme - Snazzy Operator"&gt;&lt;/a&gt;VS Code Theme - Snazzy Operator&lt;/p&gt;

&lt;p&gt;This theme is based on &lt;a href="https://github.com/sindresorhus/hyper-snazzy" rel="noopener noreferrer"&gt;hyper-snazzy&lt;/a&gt; and optimized for used with the &lt;a href="https://www.typography.com/fonts/operator/overview" rel="noopener noreferrer"&gt;Operator Mono&lt;/a&gt; font. I just love😍 this theme.&lt;/p&gt;

&lt;p&gt;⭐ Some other themes I used before:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=naumovs.theme-oceanicnext" rel="noopener noreferrer"&gt;Oceanic Next&lt;/a&gt; - I used Oceanic Next (dimmed bg).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=robertrossmann.remedy" rel="noopener noreferrer"&gt;Remedy&lt;/a&gt; - I used Remedy Dark (straight).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ✒ Font:
&lt;/h2&gt;

&lt;p&gt;Another important things for my Code Editor looks. The font I'm using for my Code Editor is &lt;a href="https://www.jetbrains.com/lp/mono/?ref=jonas.io" rel="noopener noreferrer"&gt;JetBrains Mono&lt;/a&gt;. It's a free font with ligatures support.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fids4g29fl5rwu4cmudcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fids4g29fl5rwu4cmudcr.png" alt="JetBrains Mono Font"&gt;&lt;/a&gt;Captured from JetBrains Mono Fonts Webpage&lt;/p&gt;

&lt;p&gt;The font ligatures are a new format for fonts that support symbol decorations instead of normal characters like =&amp;gt;, &amp;lt;=.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp7zz8e04jp27atnm187i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp7zz8e04jp27atnm187i.png" alt="Alt Text"&gt;&lt;/a&gt;Captured from Official Site&lt;/p&gt;

&lt;p&gt;Before &lt;a href="https://www.jetbrains.com/lp/mono/?ref=jonas.io" rel="noopener noreferrer"&gt;JetBrains Mono&lt;/a&gt;, I used &lt;strong&gt;Operator Mono&lt;/strong&gt;. It's also a nice font.&lt;/p&gt;

&lt;p&gt;⭐ Some other fonts I used before:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.cufonfonts.com/font/operator-mono" rel="noopener noreferrer"&gt;Operator Mono&lt;/a&gt; - Supports ligatures.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/tonsky/FiraCode" rel="noopener noreferrer"&gt;Fira Code&lt;/a&gt; - Free &amp;amp; supports ligatures.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dank.sh" rel="noopener noreferrer"&gt;Dank Mono&lt;/a&gt; - Paid &amp;amp; supports ligatures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🌟🌟🌟 Do you want to use my settings, I use for my VS Code fonts? In your VS Code press &lt;strong&gt;Ctrl + p&lt;/strong&gt;, type &lt;strong&gt;settings.json&lt;/strong&gt; and open that file. Now replace below properties values with my given values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"workbench.colorTheme"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Snazzy Operator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontFamily"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"'JetBrains Mono', Consolas, 'Courier New', monospace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontLigatures"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.lineHeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.letterSpacing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontWeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"400"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.cursorStyle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"line"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.cursorWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.cursorBlinking"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"solid"&lt;/span&gt;&lt;span class="w"&gt;
&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;h2&gt;
  
  
  📁 Icons:
&lt;/h2&gt;

&lt;p&gt;File Icons enhance our VS Code Editor looks. Mainly it helps us to differentiate between different files &amp;amp; folders by their given icons. For my VS Code I use two file icons :-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme" rel="noopener noreferrer"&gt;Material Icon Theme&lt;/a&gt; - One of the most popular icon theme for VS Code.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme-icons" rel="noopener noreferrer"&gt;Material Theme Icons&lt;/a&gt; - Currently using this. And I'm using Material Theme Icons Light variant.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq3f0fdaigdv3jiz7bm7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq3f0fdaigdv3jiz7bm7v.png" alt="Material Icon Theme"&gt;&lt;/a&gt;Material Icon Theme - File Icons&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠 Extensions I Use:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=SimonSiefke.auto-rename-tag" rel="noopener noreferrer"&gt;Auto Rename Tag&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Automatically rename paired HTML/XML tag, also works in JSX.&lt;/p&gt;

&lt;p&gt;Add entry into &lt;code&gt;auto-rename-tag.activationOnLanguage&lt;/code&gt;, in your &lt;strong&gt;settings.json&lt;/strong&gt; file to set the languages that the extension will be activated. By default, it is &lt;strong&gt;["*"]&lt;/strong&gt; and will be activated for all languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"auto-rename-tag.activationOnLanguage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"xml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"php"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"javascript"&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2u2t0jjpk3w3vln3zzm6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2u2t0jjpk3w3vln3zzm6.gif" alt="Auto Rename Tag"&gt;&lt;/a&gt;Auto Rename Tag (Taken from VS Code Auto Rename Tag extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2" rel="noopener noreferrer"&gt;Bracket Pair Colorizer 2&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This extension allows matching brackets to be identified with colours. The user can define which tokens to match, and which colours to use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxyly1rmpc9nnh5l1ma7z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxyly1rmpc9nnh5l1ma7z.png" alt="Bracket Pair Colorizer 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight" rel="noopener noreferrer"&gt;Color Highlight&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This extension styles css/web colors, found in your document.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frzjxppvfqkfw4m7k5n9g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frzjxppvfqkfw4m7k5n9g.gif" alt="Color Highlight"&gt;&lt;/a&gt;Color Highlight (Taken from google)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=pranaygp.vscode-css-peek" rel="noopener noreferrer"&gt;CSS Peek&lt;/a&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Peek: Load the css file inline and make quick edits right there. (Ctrl+Shift+F12)&lt;/li&gt;
&lt;li&gt;Go To: Jump directly to the css file or open it in a new editor (F12)&lt;/li&gt;
&lt;li&gt;Hover: Show the definition in a hover over the symbol (Ctrl+hover)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcbecdt45sjnjx32svzr9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcbecdt45sjnjx32svzr9.gif" alt="CSS Peek"&gt;&lt;/a&gt;CSS Peek (Taken from VS Code CSS Peek extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv" rel="noopener noreferrer"&gt;DotENV&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Highlight key, value pairs in &lt;strong&gt;&lt;em&gt;.env&lt;/em&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4llz9uysuzmgpiq7k6sy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4llz9uysuzmgpiq7k6sy.png" alt="DotENV"&gt;&lt;/a&gt;DotENV (Taken from VS Code DotENV extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets" rel="noopener noreferrer"&gt;ES7 React/Redux/GraphQL/React-Native snippets&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This extension provides you JavaScript and React/Redux snippets in ES7 with Babel plugin features for VS Code.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;'Linting' tool for VS Code - or Code checking tool.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Lint, or a Linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs." &lt;a href="https://en.wikipedia.org/wiki/Lint_(software)" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag" rel="noopener noreferrer"&gt;Highlight Matching Tag&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Highlight matching opening or closing tags.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fulu0yt94sas4sm1pixke.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fulu0yt94sas4sm1pixke.gif" alt="Highlight Matching Tag"&gt;&lt;/a&gt;Highlight Matching Tag (Taken from VS Code Highlight Matching Tag extension page)&lt;br&gt;
Styles I use for this extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"highlight-matching-tag.styles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"opening"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"left"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"custom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0 0 0 1.5px"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderStyle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"solid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yellow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderRadius"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5px"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"overviewRulerColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"white"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"right"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"custom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0 1.5px 0 0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderStyle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"solid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"yellow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"borderRadius"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5px"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"overviewRulerColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"white"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &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;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=kisstkondoros.vscode-gutter-preview" rel="noopener noreferrer"&gt;Image preview&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Shows image preview in the gutter and on hover.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxy3evgn6v5xzeyjvinmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxy3evgn6v5xzeyjvinmd.png" alt="Image preview"&gt;&lt;/a&gt;Image preview (Taken from VS Code Image preview extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow" rel="noopener noreferrer"&gt;Indent Rainbow&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This extension colorizes the indentation in front of your text alternating four different colors on each step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo7zc72mcqhiwvnfkpj5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo7zc72mcqhiwvnfkpj5l.png" alt="Indent Rainbow"&gt;&lt;/a&gt;Indent Rainbow (Taken from VS Code Indent Rainbow extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live Server&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Launch a local development server with live reload feature for static &amp;amp; dynamic pages.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.&lt;/p&gt;

&lt;p&gt;Set below property value to be &lt;code&gt;true&lt;/code&gt; or add this property into your &lt;strong&gt;settings.json&lt;/strong&gt; file to format code on save.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-pugbeautify" rel="noopener noreferrer"&gt;Pug beautify&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Pug beautify plugin for VS Code. Press &lt;strong&gt;F1&lt;/strong&gt; and run the command named &lt;strong&gt;Beautify pug/jade&lt;/strong&gt; to beautify your pug file.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=humao.rest-client" rel="noopener noreferrer"&gt;REST Client&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;REST Client allows you to send HTTP request and view the response in Visual Studio Code directly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx6ppjpq28yjwjv9yw0lr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fx6ppjpq28yjwjv9yw0lr.gif" alt="REST Client"&gt;&lt;/a&gt;REST Client (Taken from VS Code REST Client extension page)&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync" rel="noopener noreferrer"&gt;Settings Sync&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight" rel="noopener noreferrer"&gt;TODO Highlight&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Highlight TODO, FIXME and other annotations within your code.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔹 &lt;a href="https://marketplace.visualstudio.com/items?itemName=pflannery.vscode-versionlens" rel="noopener noreferrer"&gt;Version Lens&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Shows the latest version for each package in your package.json file.&lt;/p&gt;

&lt;h2&gt;
  
  
  📃 Terminal Setup:
&lt;/h2&gt;

&lt;p&gt;I use Windows Operating System. Since I use Git via the command line, I have &lt;a href="https://git-scm.com" rel="noopener noreferrer"&gt;Git Terminal&lt;/a&gt;. And I use this terminal as my integrated terminal. My terminal settings are given below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"terminal.integrated.shell.windows"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Program Files&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;Git&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;bin&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;bash.exe"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"terminal.integrated.fontFamily"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"FuraMono Nerd Font"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"terminal.integrated.fontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"terminal.integrated.rightClickCopyPaste"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔ Useful VS Code Keyboard Shortcuts:
&lt;/h2&gt;

&lt;p&gt;There are some important keyboard shortcuts, I use in my day to day coding life. These shortcuts enhance my productivity with Visual Studio Code.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Keybinding&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + P&lt;/td&gt;
&lt;td&gt;Go to File, You can move to any file of open solution/folder in Visual Studio code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + `&lt;/td&gt;
&lt;td&gt;Open terminal in VS Code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alt + Down&lt;/td&gt;
&lt;td&gt;Move Line Down&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alt + Up&lt;/td&gt;
&lt;td&gt;Move Line Up&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + D&lt;/td&gt;
&lt;td&gt;Move Last Selection To Next Find Match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + Space&lt;/td&gt;
&lt;td&gt;Trigger Suggest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + F&lt;/td&gt;
&lt;td&gt;Find&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + /&lt;/td&gt;
&lt;td&gt;Toggle Line Comment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + C&lt;/td&gt;
&lt;td&gt;Copy line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + X&lt;/td&gt;
&lt;td&gt;Cut line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + V&lt;/td&gt;
&lt;td&gt;Paste&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + Z&lt;/td&gt;
&lt;td&gt;Undo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + Y&lt;/td&gt;
&lt;td&gt;Redo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shift + Alt + Down&lt;/td&gt;
&lt;td&gt;Copy Line Down&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shift + Alt + Up&lt;/td&gt;
&lt;td&gt;Copy Line Up&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ctrl + Shift + T&lt;/td&gt;
&lt;td&gt;Reopen the latest closed window&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Thanks for reading and stay tuned.🙂👋&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>productivity</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My full stack blog based portfolio site</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Fri, 14 Feb 2020 13:02:28 +0000</pubDate>
      <link>https://dev.to/iamismile/my-full-stack-blog-based-portfolio-site-2gi6</link>
      <guid>https://dev.to/iamismile/my-full-stack-blog-based-portfolio-site-2gi6</guid>
      <description>&lt;p&gt;Hello everyone!👋 I have been working on my portfolio site and it is now live. It's a blog based site where I will write about my web technologies. It's a full stack project, this is my first full stack project. Please give some feedback on it. To see my website visit:- &lt;a href="https://iamismile.herokuapp.com"&gt;https://iamismile.herokuapp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I'm going to talk a little bit about myself and my website here. I'm new in web development. Eight month passed away that I'm learning web development. I have learned modern technologies: React.js, Node.js, Express, MongoDB, Mongoose. So I've decided to build my own project, a big project, where I can learn more, implement my knowledge and face some real world problems. And I decided to build a blog site for myself where I can share my thoughts and which also helps me to find a good job.&lt;/p&gt;

&lt;p&gt;✨ Lets talk about my website &lt;strong&gt;Stack&lt;/strong&gt;, &lt;strong&gt;Design&lt;/strong&gt;, &lt;strong&gt;Features&lt;/strong&gt; and &lt;strong&gt;Security&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔ Stack:
&lt;/h2&gt;

&lt;p&gt;The website build with modern technologies. It is an API and Server-Side rendered website. To check my website API visit: &lt;a href="https://iamismile.herokuapp.com/api/v1/tidbits"&gt;https://iamismile.herokuapp.com/api/v1/tidbits&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Client-Side(i.e. frontend):-&lt;/strong&gt; HTML, CSS, JavaScript.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Server-Side(i.e. backend):-&lt;/strong&gt; Node.js(JavaScript runtime).&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Database:-&lt;/strong&gt; MongoDB(NoSQL).&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Image Management:-&lt;/strong&gt; Cloudinary.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Email Services:-&lt;/strong&gt; SendGrid(For server-side), EmailJS(For client-side).&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Deployment &amp;amp; Hoisting:-&lt;/strong&gt; GitHub, Heroku.&lt;/p&gt;

&lt;p&gt;🔹 &lt;strong&gt;Web Performance:-&lt;/strong&gt; Lighthouse Chrome DevTools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S1KgaKiU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/dyzokcj3s6q1h25m0ta1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S1KgaKiU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/dyzokcj3s6q1h25m0ta1.png" alt="Website Performance" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔ Design:
&lt;/h2&gt;

&lt;p&gt;The website is designed with mobile first design. I try to keep all the pages simple and nice looking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uacG09Ks--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ajpw7i4rxcnf2ogdbxj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uacG09Ks--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ajpw7i4rxcnf2ogdbxj3.png" alt="Alt Text" width="472" height="529"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YNkICblx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/f1mnnhi3ibz2owop6o1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YNkICblx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/f1mnnhi3ibz2owop6o1p.png" alt="Alt Text" width="472" height="555"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yauZe2LL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/em879frwaglhqhjjbguy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yauZe2LL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/em879frwaglhqhjjbguy.png" alt="Alt Text" width="472" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔ Features:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;RESTful API design with advance features: filtering, sorting, pagination.&lt;/li&gt;
&lt;li&gt;Used MVC architecture.&lt;/li&gt;
&lt;li&gt;Complete modern authentication: login, password reset.&lt;/li&gt;
&lt;li&gt;Uploading files and Image processing.&lt;/li&gt;
&lt;li&gt;Send email with SendGrid and EmailJS.&lt;/li&gt;
&lt;li&gt;Advance error handling.&lt;/li&gt;
&lt;li&gt;Used Markdown to write blogs.&lt;/li&gt;
&lt;li&gt;Code Style Practices: Used ESLint.&lt;/li&gt;
&lt;li&gt;Testing: For testing I used &lt;strong&gt;&lt;em&gt;Postman&lt;/em&gt;&lt;/strong&gt;(manual testing).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ✔ Security:
&lt;/h2&gt;

&lt;p&gt;Security is an important thing for a website. So some security best practices for my website are given below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compromised database: Strong encrypt password &amp;amp; password reset token.&lt;/li&gt;
&lt;li&gt;Brute Force Attacks: Implement rate limiting.&lt;/li&gt;
&lt;li&gt;Cross-Site Scripting (XSS) Attacks: Sanitize input data.&lt;/li&gt;
&lt;li&gt;Denial of Service (DOS) Attacks: Implement rate limiting.&lt;/li&gt;
&lt;li&gt;NoSQL query injection.&lt;/li&gt;
&lt;li&gt;Use HTTPS.&lt;/li&gt;
&lt;li&gt;Random password reset token with expiry dates.&lt;/li&gt;
&lt;li&gt;Deny access to a authenticated web pages after password reset. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading and stay tuned. Don't forget to give feedback.🙂&lt;/p&gt;

</description>
      <category>portfolio</category>
      <category>career</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React JSX</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Wed, 25 Sep 2019 12:42:55 +0000</pubDate>
      <link>https://dev.to/iamismile/jsx-3ac</link>
      <guid>https://dev.to/iamismile/jsx-3ac</guid>
      <description>&lt;p&gt;👋Hi, In this blog📖, I write about JSX which is the foremost thing to learn React.&lt;/p&gt;

&lt;p&gt;Lets Start...🏃‍♂️🏃‍♂️🏃‍♂️&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;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code looks a bit confusing. It seems like javascript because it starts with &lt;code&gt;const&lt;/code&gt; and ends with &lt;code&gt;;&lt;/code&gt;. Again it seems like HTML because it also contains &lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We write this code in a JavaScript file. Despite what it looks like actually this code does not contain any HTML. The part looks like HTML &lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;/code&gt;, is called JSX.&lt;/p&gt;

&lt;p&gt;➡ JSX is a syntax extension for javascript. It is written for React. JSX is not a valid javascript. Web browser can't read it. If a javascript file contains JSX, that file needs to be compiled before ran. JSX compiler translates any JSX into a regular javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔JSX Element:
&lt;/h2&gt;

&lt;p&gt;A basic unit of JSX is called the JSX element. An element describes what you want to see on the screen. Example of the JSX element given below.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JSX elements are treated as a javascript expression. That means it can be saved in a variable, passed to a function, stored in an object or an array.&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="c1"&gt;// Saved in a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;JSX&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
&lt;span class="c1"&gt;// Stored in an Object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="na"&gt;subTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;JSX&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JSX elements can have attributes like HTML elements can. A single JSX element can have many attributes.&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;const&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Introduction&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;JSX&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔Nesting:
&lt;/h2&gt;

&lt;p&gt;We can nest JSX elements inside of other JSX elements. If JSX expression takes up more than one line then we must wrap the expression in parentheses. We can also save nested JSX expression in a variable just like non-nested JSX expression.&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="c1"&gt;// Nested JSX&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;// For readability, we can use line break and indentation&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Nested JSX expression saved in a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;✨✨✨Important rule, JSX expression must have only one outermost element. The first opening tag and the final closing tag of a JSX expression must belong to the same JSX element.&lt;/em&gt;&lt;/strong&gt;&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;const&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;outer-most-element&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔className &amp;amp; htmlFor:
&lt;/h2&gt;

&lt;p&gt;The grammar of JSX is mostly same as in HTML. In HTML we use &lt;code&gt;class&lt;/code&gt; attribute but in JSX we can't use &lt;code&gt;class&lt;/code&gt;, we have to use &lt;code&gt;className&lt;/code&gt; instead. This is because JSX gets translated into JavaScript, and in JavaScript &lt;code&gt;class&lt;/code&gt; is a reserved word. For same reason we can't use &lt;code&gt;for&lt;/code&gt; in &lt;code&gt;&amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;&lt;/code&gt; element instead we have to use &lt;code&gt;htmlFor&lt;/code&gt;.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="nx"&gt;htmlFor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;First&lt;/span&gt; &lt;span class="nx"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔Self-Closing Tags:
&lt;/h2&gt;

&lt;p&gt;When we write a self-closing tag in HTML, it is optional to include a forward slash before the final angle-bracket. But in JSX we have to include forward-slash otherwise it will raise an error.&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="c1"&gt;// In HTML&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;// In JSX&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;br&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔JavaScript Expressions in JSX:
&lt;/h2&gt;

&lt;p&gt;We can use any JavaScript expressions in JSX elements by enclosing them within &lt;code&gt;{}&lt;/code&gt; curly braces.&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="c1"&gt;// Variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;profession&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Web Developer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// JavaScript Expressions in JSX&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profession&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can also use JavaScript expressions in JSX elements attribute.&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;const&lt;/span&gt; &lt;span class="nx"&gt;google&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;google&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;Me&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔Event Listeners in JSX:
&lt;/h2&gt;

&lt;p&gt;JSX elements can have event listeners just like HTML elements can. We can create an event listener by giving JSX elements a special attribute.&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="nx"&gt;onButtonClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onButtonClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;Me&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An event listener attributes value should be a function. In HTML, all event listener names are written in lowercase letters but in JSX event listener names are written in camelCase letters. You can see a list of supported event names &lt;a href="https://reactjs.org/docs/events.html#supported-events"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔JSX Conditionals:
&lt;/h2&gt;

&lt;p&gt;We can write JSX based on conditions. Some conditional examples are given below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1️⃣ if else :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;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;18&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;message&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;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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;span class="c1"&gt;// output will be&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;✨✨✨You can not inject an &lt;code&gt;if&lt;/code&gt; statement into JSX.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2️⃣ Ternary Operator :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;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;18&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;You can buy a drink.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;You can not buy a drink&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;



&lt;span class="c1"&gt;// output will be&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;3️⃣ &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; Operator :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;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;18&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt; &lt;/span&gt;&lt;span class="err"&gt;}
&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;lt;&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt; &lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;



&lt;span class="c1"&gt;// output will be&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;You&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="nx"&gt;buy&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔The &lt;code&gt;.map()&lt;/code&gt; array method:
&lt;/h2&gt;

&lt;p&gt;To create a list of JSX elements, &lt;code&gt;.map()&lt;/code&gt; is often used in React.&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;const&lt;/span&gt; &lt;span class="nx"&gt;persons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Lily&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Riyan&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;listItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;persons&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;listItems&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;{listItems}&lt;/code&gt; will evaluate to an array. And we can use an array into a JSX elements i.e.&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;const&lt;/span&gt; &lt;span class="nx"&gt;listItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Lily&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Riyan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;John&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;listItems&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;


&lt;span class="c1"&gt;// output will be&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Lily&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Riyan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;John&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔Keys:
&lt;/h2&gt;

&lt;p&gt;When we make a list in JSX, we need to include &lt;code&gt;key&lt;/code&gt;. &lt;code&gt;key&lt;/code&gt; is a JSX attribute and the value should be something unique, similar to an &lt;code&gt;id&lt;/code&gt; attribute.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Example&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li-2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Example&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li-3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Example&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keys help React to identify which items have changed, added, or removed.&lt;/p&gt;

&lt;p&gt;That's it, Thanks🙂 for reading and stay tuned🙋‍♂️.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to setup Webpack and Babel for React</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Thu, 12 Sep 2019 11:25:32 +0000</pubDate>
      <link>https://dev.to/iamismile/how-to-setup-webpack-and-babel-for-react-59ph</link>
      <guid>https://dev.to/iamismile/how-to-setup-webpack-and-babel-for-react-59ph</guid>
      <description>&lt;p&gt;All of us have used CRA(create-react-app) when we worked with React. It's an awesome tool. It gives us just to focus on React by letting take care of the configuration. Today we are going to learn how to setup Webpack and Babel for our React app.&lt;/p&gt;

&lt;p&gt;First, let's learn about Webpack and Babel.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔Webpack:
&lt;/h2&gt;

&lt;p&gt;Its a module bundler which lets us bundle our project files into a single file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A module is a file that contains definitions - including variables and functions, that we can use once it is imported.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It requires a &lt;strong&gt;webpack.config.js&lt;/strong&gt; file in the root folder. Where we tell our webpack how to work with our application by giving entry point information and also output information.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// relative path&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// absolute path&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// file name&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 "entry" point is where does our application going to kick off and we set it by giving relative path value. And the output property tells webpack where to emit the outputs it creates and how to name those files. We have to give absolute path value in our output path properties.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔Babel:
&lt;/h2&gt;

&lt;p&gt;It's a JavaScript compiler. Babel on its own actually has no functionality. Yeah, its a compiler but it's not going to compile anything by default. We have to add various plugins and presets to add support to particular language features. You can check this out by visiting &lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;Babel&lt;/a&gt; website. In the babel website navigation bar section you will find &lt;strong&gt;Try It Out&lt;/strong&gt;. Click on it and you will get a new window.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw4cio5bsnxf1uxyil0ge.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw4cio5bsnxf1uxyil0ge.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Where in the left side window you can write your code and in the right side window you will get your compiled code. Now let's write some JSX in the left side window.&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;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the right-side window, you will get JavaScript understandable compiled code which is always run behind the scene in our React app. On the left side, you see some &lt;strong&gt;PRESETS&lt;/strong&gt; options where some options are already been ticked. If you now untick &lt;strong&gt;react&lt;/strong&gt; presets option you will see an error caused this &lt;strong&gt;react&lt;/strong&gt; preset is responsible for converting our JSX syntax into JavaScript understandable code.&lt;/p&gt;

&lt;p&gt;In our tutorial we are going to use two presets:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env&lt;/em&gt;&lt;/strong&gt; :- Which helps babel to convert ES6, ES7 and ES8 code to ES5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react&lt;/em&gt;&lt;/strong&gt; :- Which Transforms JSX to JavaScript.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Getting Started:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now we know a little bit about webpack and babel. Let's dive into our React setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create directories with these commands:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;mkdir react-setup-tutorial&lt;br&gt;
cd react-setup-tutorial&lt;br&gt;
mkdir public src&lt;br&gt;
touch public/index.html src/app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;In index.html file add the following code inside it.&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"ie=edge"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;React App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/head&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./bundle.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&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;ul&gt;
&lt;li&gt;
&lt;strong&gt;Initialize the project by running:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Install Webpack &amp;amp; React:&lt;/strong&gt;
&lt;/h2&gt;



&lt;p&gt;&lt;code&gt;npm install webpack webpack-cli --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We installed &lt;strong&gt;webpack-cli&lt;/strong&gt; so that we can use webpack in the command line.&lt;/p&gt;

&lt;p&gt;We already know that webpack needs &lt;strong&gt;webpack.config.js&lt;/strong&gt; to file in the root of the project directory. So let's create &lt;strong&gt;webpack.config.js&lt;/strong&gt; file with the following code inside it.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&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;Next, add the webpack command inside package.json:&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack --mode=development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack --mode=production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two modes in Webpack, &lt;strong&gt;development&lt;/strong&gt; and &lt;strong&gt;production&lt;/strong&gt;. Which we can set by &lt;strong&gt;--mode&lt;/strong&gt; flag. Production mode produces optimize files which are ready for use in production. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Install React:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install react react-dom&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now import react and react-dom inside our &lt;strong&gt;app.js&lt;/strong&gt; file and also add some react code.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello from react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now use below command in your terminal and open your &lt;strong&gt;index.html&lt;/strong&gt; file in your browser.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Your app is working well. But you have a question why didn't we use JSX. This time lets try with some JSX code in our &lt;strong&gt;app.js&lt;/strong&gt; file.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now again run our previous command.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This time you will get an error. That's because we use JSX and JavaScript doesn't support JSX. So If we want to use JSX in our app we need to compile it. And we can do it by babel.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Install &amp;amp; Configure Babel:&lt;/strong&gt;
&lt;/h2&gt;



&lt;p&gt;&lt;code&gt;npm install @babel/core @babel/preset-env @babel/preset-react babel-loader --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We already know about &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env and &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react. Now, what is &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/core and babel-loader?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/core&lt;/em&gt;&lt;/strong&gt; :- It allows us to run babel from tools like webpack. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;babel-loader&lt;/em&gt;&lt;/strong&gt; :- Its a webpack plugin. It allows us to teach webpack how to run babel when webpack sees certain files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's configure babel by creating a &lt;strong&gt;.babelrc&lt;/strong&gt; file inside the root of the project directory with the following contents inside of it.&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@babel/preset-react&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;This file will tell babel which presets to use for transpiling the code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now its time to teach webpack how to compile JSX into JavaScript code. To do that we need to use loader. A loader lets us customize the behavior of webpack when it loads a certain file. It's going to run certain files through babel. For that, we need to set up a loader in &lt;strong&gt;webpack.config.js&lt;/strong&gt; file via the &lt;strong&gt;module&lt;/strong&gt; property on our objects. &lt;strong&gt;module&lt;/strong&gt; property needs an array of rules and a rule let us define how we want to use our loaders. Now we have one rule to take JSX and convert it into JavaScript with Babel.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-loader&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="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;Here we set one rule of the object where &lt;strong&gt;loader&lt;/strong&gt; property tells which loader we want to use and we use &lt;strong&gt;babel-loader&lt;/strong&gt;. &lt;strong&gt;test&lt;/strong&gt; property for what files do we actually want to run this loader on and we want to run it on files that end up with &lt;strong&gt;.js&lt;/strong&gt;. &lt;strong&gt;exclude&lt;/strong&gt; property to exclude a set of files and we use &lt;strong&gt;/node_modules/&lt;/strong&gt; cause we don't want to run babel through those libraries. Now we can use JSX in our React. Let's run our app again.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This time we don't get any error. Open your &lt;strong&gt;index.html&lt;/strong&gt; file in the browser and yeah it's working.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Configure Source Map:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's add some extra configuration settings in our &lt;strong&gt;webpack.config.js&lt;/strong&gt; file.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-loader&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="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;devtool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cheap-module-eval-source-map&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here we setup Source map by using &lt;strong&gt;devtool&lt;/strong&gt; property. It enhances our debugging process. Its use to display our original JavaScript while debugging, which is a lot easier to look at than a minified code.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Install DevServer:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Run this below command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install webpack-dev-server --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Add following code inside &lt;strong&gt;webpack.config.js&lt;/strong&gt; file.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-loader&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="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;devtool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cheap-module-eval-source-map&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// changed line&lt;/span&gt;
  &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;contentBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&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="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Next add &lt;strong&gt;webpack-dev-server&lt;/strong&gt; command inside package.json:&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack --mode=development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack --mode=production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev-server&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webpack-dev-server&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run this command.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run dev-server&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;It's going to start the development server. And It gives us output where we can access it. Now we have integrated both tools into one, the dev server is our server and its also running webpack for us.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbh8ypcrk6zgh31f554at.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbh8ypcrk6zgh31f554at.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Now we can visit the highlighted URL and we will get our app.&lt;/p&gt;
&lt;h2&gt;
  
  
  ✔&lt;strong&gt;Loading the Styles:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's create a new file and folder in the &lt;strong&gt;src&lt;/strong&gt; directory.&lt;/p&gt;

&lt;p&gt;Use the following command to create a file and folder.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir src/styles&lt;br&gt;
touch src/styles/styles.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now add the following styles inside &lt;strong&gt;styles.css&lt;/strong&gt; file.&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="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;blue&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;To load our &lt;strong&gt;style.css&lt;/strong&gt; file we need to set up new rules in &lt;strong&gt;webpack.config.js&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Before that, we need to install some new loaders.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install css-loader style-loader --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;css-loader:&lt;/em&gt;&lt;/strong&gt; Allows webpack to load our CSS assets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;style-loader:&lt;/em&gt;&lt;/strong&gt; Take CSS and adds it to the DOM by injecting a

&lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;

tag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now add new rules in our &lt;strong&gt;webpack.config.js&lt;/strong&gt; file.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="c1"&gt;// New rules to load css&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;css$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&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="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;devtool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cheap-module-eval-source-map&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;contentBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&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="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;import&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;style.css&lt;/strong&gt; inside our app.js file and run dev-server to see the effect.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./styles/styles.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to use SCSS then we need to install &lt;strong&gt;&lt;em&gt;sass-loader&lt;/em&gt;&lt;/strong&gt; that would help webpack to compile sass to css. The &lt;strong&gt;&lt;em&gt;sass-loader&lt;/em&gt;&lt;/strong&gt; is dependent on another package &lt;strong&gt;&lt;em&gt;node-sass&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install sass-loader node-sass --save-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now configure &lt;strong&gt;webpack.config.js&lt;/strong&gt; file again for SASS by chaining &lt;strong&gt;&lt;em&gt;sass-loader&lt;/em&gt;&lt;/strong&gt; with the &lt;strong&gt;&lt;em&gt;css-loader&lt;/em&gt;&lt;/strong&gt; and the &lt;strong&gt;&lt;em&gt;style-loader&lt;/em&gt;&lt;/strong&gt;.&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;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bundle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;babel-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="c1"&gt;// Rules to load scss&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Some change here&lt;/span&gt;
        &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;scss$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;css-loader&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sass-loader&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="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;devtool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cheap-module-eval-source-map&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;contentBase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&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="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now chnage our &lt;strong&gt;style.css&lt;/strong&gt; file extension &lt;strong&gt;.css&lt;/strong&gt; to &lt;strong&gt;.scss&lt;/strong&gt; that is &lt;strong&gt;style.scss&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Also change the css import in app.js to:&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="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./styles/styles.scss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add the following style to see that our wepback is working correctly for SASS.&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="nx"&gt;$brand&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;$brand&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;color&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;Now run dev-server again by using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run dev-server&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;And we configure our webpack for SASS.&lt;/p&gt;

&lt;p&gt;That's it. Now we have configured Webpack and Babel for React that we can use to create our React projects. Thanks for reading and stay tuned.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webpack</category>
      <category>babel</category>
    </item>
    <item>
      <title>What "use strict" means in JavaScript</title>
      <dc:creator>Ismile Hossain</dc:creator>
      <pubDate>Sun, 01 Sep 2019 13:55:43 +0000</pubDate>
      <link>https://dev.to/iamismile/what-use-strict-means-in-javascript-45pp</link>
      <guid>https://dev.to/iamismile/what-use-strict-means-in-javascript-45pp</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;"use strict"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For long time JavaScript evolved without facing compatibility issues. This is because JavaScript added new features without changing old functionality. And it had the benefits of never breaking existing code.&lt;/p&gt;

&lt;p&gt;This case was until 2009 when ECMAScript 5 (ES5) appeared. In that version new features were added and also modified some of the existing ones. But most modifications are off by default to keep the old code working. If we want to work the whole scripts modern way we need to explicitly enable them.&lt;/p&gt;

&lt;p&gt;For that we can use a directive looks like a string &lt;strong&gt;"use strict"&lt;/strong&gt; or &lt;strong&gt;'use strict'.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always use &lt;strong&gt;"use strict"&lt;/strong&gt; at top of our script file and it is recommended.&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="c1"&gt;// At top of the file&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// code&lt;/span&gt;
&lt;span class="c1"&gt;// code&lt;/span&gt;
&lt;span class="c1"&gt;//code&lt;/span&gt;

&lt;span class="c1"&gt;// code will work modern way&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use &lt;strong&gt;"use strict"&lt;/strong&gt; at the beginning of the function body instead of at the top of the script. It will enable &lt;strong&gt;strict&lt;/strong&gt; mode in that function only.&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="c1"&gt;// default mode&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// strict mode&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;

&lt;span class="c1"&gt;// default mode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But again it is recommended to use &lt;strong&gt;"use strict"&lt;/strong&gt; at top of the file.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
