<?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: Naweli Verma</title>
    <description>The latest articles on DEV Community by Naweli Verma (@naweli_verma).</description>
    <link>https://dev.to/naweli_verma</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%2F455368%2F95464f6f-54eb-4be7-9e14-ec70bb5fc8dc.jpg</url>
      <title>DEV Community: Naweli Verma</title>
      <link>https://dev.to/naweli_verma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/naweli_verma"/>
    <language>en</language>
    <item>
      <title>The Backend Setup Every Developer Should Follow</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Tue, 03 Mar 2026 12:27:59 +0000</pubDate>
      <link>https://dev.to/naweli_verma/the-backend-setup-every-developer-should-follow-3d03</link>
      <guid>https://dev.to/naweli_verma/the-backend-setup-every-developer-should-follow-3d03</guid>
      <description>&lt;p&gt;Before you write your backend code, it is very important to have a clean and organized setup — one that helps you scale, debug, and collaborate better.&lt;/p&gt;

&lt;p&gt;There are 6 major layers of it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Routes&lt;/li&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;Middleware&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Repositary&lt;/li&gt;
&lt;li&gt;Database&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Routes – The Entry Points
&lt;/h3&gt;

&lt;p&gt;Routes define which function should run when a specific request hits your server.&lt;/p&gt;

&lt;p&gt;They map HTTP methods and URLs to controllers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.post("/signup", userController.signup);
router.get("/profile", authMiddleware, userController.getProfile);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Routes should be thin and clean.&lt;br&gt;
They don’t contain logic.&lt;br&gt;
They only decide where the request goes.&lt;/p&gt;

&lt;p&gt;Think of Routes as:&lt;br&gt;
The road map of your backend.&lt;/p&gt;
&lt;h3&gt;
  
  
  Controllers – The Request Handlers
&lt;/h3&gt;

&lt;p&gt;Controllers handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading request data (req.body, req.params, req.query)&lt;/li&gt;
&lt;li&gt;Sending response (res.json, res.status)&lt;/li&gt;
&lt;li&gt;Calling the service layer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They should NOT:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Contain business logic&lt;/li&gt;
&lt;li&gt;Talk directly to the database&lt;/li&gt;
&lt;li&gt;Hash passwords&lt;/li&gt;
&lt;li&gt;Calculate business rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of Controllers as:&lt;br&gt;
The receptionist. They receive and respond.&lt;/p&gt;
&lt;h3&gt;
  
  
  Middleware – The Gatekeepers
&lt;/h3&gt;

&lt;p&gt;Middleware runs before the controller.&lt;/p&gt;

&lt;p&gt;It is used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication (JWT verification)&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Input validation&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Error handling
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;router.get("/profile", authMiddleware, userController.getProfile);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The request must pass through middleware before reaching the controller.&lt;/p&gt;

&lt;p&gt;Think of Middleware as:&lt;br&gt;
The security check at the airport.&lt;/p&gt;
&lt;h3&gt;
  
  
  Services – The Brain of the Application
&lt;/h3&gt;

&lt;p&gt;This is where your real logic lives.&lt;/p&gt;

&lt;p&gt;Services handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Business rules&lt;/li&gt;
&lt;li&gt;Data transformations&lt;/li&gt;
&lt;li&gt;Workflow decisions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Orchestration of multiple repositories.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.signup = async ({ email, password }) =&amp;gt; {
  const existingUser = await userRepository.findByEmail(email);

  if (existingUser) {
    throw new Error("User already exists");
  }

  const hashedPassword = await bcrypt.hash(password, 10);

  return await userRepository.createUser(email, hashedPassword);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of Services as:&lt;br&gt;
The decision-maker.&lt;/p&gt;

&lt;h3&gt;
  
  
  Repository – The Data Access Layer
&lt;/h3&gt;

&lt;p&gt;The repository is responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Communicating with the database&lt;/li&gt;
&lt;li&gt;Executing queries&lt;/li&gt;
&lt;li&gt;Returning raw data&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Decide business rules&lt;/li&gt;
&lt;li&gt;Validate logic&lt;/li&gt;
&lt;li&gt;Handle HTTP
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.findByEmail = async (email) =&amp;gt; {
  return db("users").where({ email }).first();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repository is:&lt;/p&gt;

&lt;p&gt;An abstraction over the database.&lt;br&gt;
If tomorrow you switch from PostgreSQL to MongoDB,&lt;br&gt;
only the repository layer should change.&lt;/p&gt;

&lt;p&gt;Think of Repository as:&lt;br&gt;
The translator between your app and the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Database – The Storage Engine
&lt;/h3&gt;

&lt;p&gt;This is your:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;li&gt;Supabase&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Its job is simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store data&lt;/li&gt;
&lt;li&gt;Retrieve data&lt;/li&gt;
&lt;li&gt;Maintain integrity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It does not care about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP&lt;/li&gt;
&lt;li&gt;Business logic&lt;/li&gt;
&lt;li&gt;Application rules&lt;/li&gt;
&lt;li&gt;It only stores information&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Full Request Flow
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Let’s say a user signs up.&lt;/li&gt;
&lt;li&gt;Request hits Route&lt;/li&gt;
&lt;li&gt;Middleware validates token/input&lt;/li&gt;
&lt;li&gt;Controller receives request&lt;/li&gt;
&lt;li&gt;Controller calls Service&lt;/li&gt;
&lt;li&gt;Service applies business logic&lt;/li&gt;
&lt;li&gt;Service calls Repository&lt;/li&gt;
&lt;li&gt;Repository talks to Database&lt;/li&gt;
&lt;li&gt;Response travels back up the chain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Database → Repository → Service → Controller → Client&lt;/p&gt;

&lt;p&gt;Clean. Predictable. Scalable.&lt;/p&gt;

&lt;h4&gt;
  
  
  🧠 Simple Mental Model
&lt;/h4&gt;

&lt;p&gt;If you're ever confused where something belongs, ask:&lt;/p&gt;

&lt;p&gt;Does it handle HTTP? → Controller&lt;/p&gt;

&lt;p&gt;Does it validate/authenticate/log? → Middleware&lt;/p&gt;

&lt;p&gt;Is it business logic? → Service&lt;/p&gt;

&lt;p&gt;Is it database query? → Repository&lt;/p&gt;

&lt;p&gt;Is it storage? → Database&lt;/p&gt;

&lt;p&gt;Does it map endpoint to controller? → Route&lt;/p&gt;

&lt;p&gt;This structure is inspired by architectural principles popularized in&lt;br&gt;
Clean Architecture by Robert C. Martin — but simplified for practical backend applications.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>ai</category>
      <category>systemdesign</category>
      <category>architecture</category>
    </item>
    <item>
      <title>A Beginner’s Guide to System Design: Thinking Beyond Code</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Mon, 21 Apr 2025 17:58:58 +0000</pubDate>
      <link>https://dev.to/naweli_verma/a-beginners-guide-to-system-design-thinking-beyond-code-4npg</link>
      <guid>https://dev.to/naweli_verma/a-beginners-guide-to-system-design-thinking-beyond-code-4npg</guid>
      <description>&lt;p&gt;Whether you’re scaling a startup idea, prepping for a tech interview, or just building better mental models, system design is where the rubber meets the road. It’s the blueprinting phase where ideas evolve into robust, scalable, and maintainable software architectures.&lt;/p&gt;

&lt;p&gt;Let’s break it down in a way that makes it not just digestible but fun.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚀 What Is System Design, Really?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design is the art (and science) of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements.&lt;/p&gt;

&lt;p&gt;But that’s textbook.&lt;/p&gt;

&lt;p&gt;In practice? It’s like being the city planner of a digital city. You’re not laying bricks (coding), you’re deciding where the roads, bridges, schools, and power grids go — so that everything works together smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧩 Two Sides of the Coin&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. High-Level Design (HLD)
&lt;/h2&gt;

&lt;p&gt;This is the bird’s-eye view. It includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System architecture (e.g., client-server, microservices, monolith)&lt;/li&gt;
&lt;li&gt;Major components and how they communicate&lt;/li&gt;
&lt;li&gt;Technologies used&lt;/li&gt;
&lt;li&gt;Trade-offs and justifications&lt;/li&gt;
&lt;li&gt;Example: For a URL shortener like Bit.ly, you’d sketch out how requests go from client to API to DB to cache and back.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Low-Level Design (LLD)
&lt;/h2&gt;

&lt;p&gt;This zooms into the nuts and bolts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class diagrams&lt;/li&gt;
&lt;li&gt;Database schemas&lt;/li&gt;
&lt;li&gt;API contracts&lt;/li&gt;
&lt;li&gt;Algorithms and data structures&lt;/li&gt;
&lt;li&gt;Think of this as the developer’s guidebook for implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🛠️ Core Building Blocks
&lt;/h2&gt;

&lt;p&gt;Here are the recurring ingredients in any modern system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Load Balancers — Distribute traffic evenly&lt;/li&gt;
&lt;li&gt;Caching — Speed up repeated reads (Redis, Memcached)&lt;/li&gt;
&lt;li&gt;Databases — SQL vs NoSQL, consistency vs availability&lt;/li&gt;
&lt;li&gt;Message Queues — Async communication (Kafka, RabbitMQ)&lt;/li&gt;
&lt;li&gt;CDNs — Move content closer to users&lt;/li&gt;
&lt;li&gt;Replication &amp;amp; Sharding — For scaling DBs&lt;/li&gt;
&lt;li&gt;Understanding when and why to use them is key.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  You’ll constantly face trade-offs:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Consistency vs Availability (hello, CAP theorem!)&lt;/li&gt;
&lt;li&gt;Latency vs Complexity&lt;/li&gt;
&lt;li&gt;Premature optimization vs scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the right answer often depends on the product’s goals, scale, and team maturity.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>softwaredevelopment</category>
      <category>architecture</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Closuer love story</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Tue, 15 Apr 2025 11:57:39 +0000</pubDate>
      <link>https://dev.to/naweli_verma/clouser-love-story-11lf</link>
      <guid>https://dev.to/naweli_verma/clouser-love-story-11lf</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0" class="crayons-story__hidden-navigation-link"&gt;The Closure Conspiracy: Why Your Functions Never Forget&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/naweli_verma" class="crayons-avatar  crayons-avatar--l  "&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%2Fuser%2Fprofile_image%2F455368%2F95464f6f-54eb-4be7-9e14-ec70bb5fc8dc.jpg" alt="naweli_verma profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/naweli_verma" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Naweli Verma
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Naweli Verma
                
              
              &lt;div id="story-author-preview-content-2408820" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/naweli_verma" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&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%2Fuser%2Fprofile_image%2F455368%2F95464f6f-54eb-4be7-9e14-ec70bb5fc8dc.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Naweli Verma&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Apr 15 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0" id="article-link-2408820"&gt;
          The Closure Conspiracy: Why Your Functions Never Forget
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/fullstack"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;fullstack&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>ai</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>The Closure Conspiracy: Why Your Functions Never Forget</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Tue, 15 Apr 2025 11:56:56 +0000</pubDate>
      <link>https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0</link>
      <guid>https://dev.to/naweli_verma/the-closure-conspiracy-why-your-functions-never-forget-30h0</guid>
      <description>&lt;p&gt;A closure is created when a function is defined inside another function, allowing the inner function to access the outer function's variables, even after the outer function has finished executing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
    let count = 0; // This is a variable in the outer function's scope

    // This inner function is a closure
    function inner() {
        count++;  // It has access to the 'count' variable from the outer function
        console.log(count);
    }

    return inner;  // outer() returns the inner function, creating a closure
}

const counter = outer();  // When outer() is called, it returns the inner function (closure)
counter();  // Logs: 1
counter();  // Logs: 2
counter();  // Logs: 3
&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;When outer() is called, it creates the count variable and the inner() function.&lt;/li&gt;
&lt;li&gt;Even after outer() has finished executing, the inner() function still has access to count, because it's closed over that variable.&lt;/li&gt;
&lt;li&gt;Every time counter() is called, the count variable persists across calls.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How Closures Work:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a function is created inside another function, it captures the variables from its outer function's scope. This means that the inner function has access to those variables even after the outer function has finished executing.**&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
    let outerVar = "I'm from outer!";

    function inner() {
        console.log(outerVar);  // inner function has access to outerVar
    }

    inner();
}

outer();  // Logs: "I'm from outer!"

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1.Creating Private Variables&lt;/strong&gt;&lt;br&gt;
Closures are often used to create private variables in JavaScript, something that isn’t directly supported. Here’s an example where a closure is used to encapsulate data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createCounter() {
    let count = 0;  // Private variable

    return {
        increment: function() {
            count++;
            console.log(count);
        },
        decrement: function() {
            count--;
            console.log(count);
        },
        getCount: function() {
            return count;
        }
    };
}

const counter = createCounter();
counter.increment();  // Logs: 1
counter.increment();  // Logs: 2
console.log(counter.getCount());  // Logs: 2
counter.decrement();  // Logs: 1

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

&lt;/div&gt;



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

&lt;p&gt;count is private because it can’t be accessed directly from outside the createCounter function.&lt;/p&gt;

&lt;p&gt;The increment(), decrement(), and getCount() functions are closures that have access to the count variable, even after createCounter() has finished executing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Closure with SetTimeout&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures can also be useful with asynchronous functions, such as setTimeout, because they allow us to "remember" values over time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function timer() {
    for (let i = 0; i &amp;lt; 3; i++) {
        setTimeout(function() {
            console.log(i);  // Will log 0, 1, 2 after 1 second
        }, 1000);
    }
}

timer();

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

&lt;/div&gt;



&lt;p&gt;The code above might not work as expected because i will have the final value (3) when setTimeout is executed. To preserve the value of i for each iteration, you can use closures to create a new scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function timer() {
    for (let i = 0; i &amp;lt; 3; i++) {
        setTimeout(function() {
            console.log(i);  // Logs: 0, 1, 2 after 1 second
        }, 1000 * i);
    }
}

timer();

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

&lt;/div&gt;



&lt;p&gt;By using closures, each setTimeout captures its own version of i, so you get the expected output (0, 1, 2).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3: Using Closures with this&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Closures can also affect the value of this in JavaScript. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
    this.name = "Outer";
    const inner = function() {
        console.log(this.name); // "this" will refer to the global object or undefined in strict mode
    };
    inner();  // 'this' inside inner() is not the same as in outer()
}

const obj = new outer();  // undefined or error in strict mode

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

&lt;/div&gt;



&lt;p&gt;If you want to ensure that this inside inner() refers to the outer function's this, you can use an arrow function (which doesn't have its own this):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
    this.name = "Outer";
    const inner = () =&amp;gt; {
        console.log(this.name);  // Arrow function keeps the outer 'this'
    };
    inner();  // 'this' refers to the outer function's 'this'
}

const obj = new outer();  // Logs: "Outer"

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Takeaways:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Closure allows functions to "remember" the environment in which they were created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Closures are great for data encapsulation and privacy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They also help with maintaining state across multiple function calls, especially in asynchronous code like setTimeout.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>ai</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>My Amazon SDE Interview Experience – May 2024</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Tue, 17 Sep 2024 08:59:19 +0000</pubDate>
      <link>https://dev.to/naweli_verma/my-amazon-sde-interview-experience-may-2024-3nf6</link>
      <guid>https://dev.to/naweli_verma/my-amazon-sde-interview-experience-may-2024-3nf6</guid>
      <description>&lt;h2&gt;
  
  
  My Amazon SDE Interview Experience – May 2024
&lt;/h2&gt;

&lt;p&gt;In May 2024, I had the opportunity to interview for a Software Development Engineer (SDE) role at Amazon. It all started when a recruiter reached out to me via LinkedIn. I was pleasantly surprised, as it’s always exciting.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It All Started
&lt;/h2&gt;

&lt;p&gt;The recruiter was professional and clear, giving me all the necessary details about the process and the role. After exchanging a few messages, I received a test link for the first round of the interview, which was a coding assessment. The assessment was hosted on HackerRank and comprised two coding questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  First Round - The Coding Test
&lt;/h2&gt;

&lt;p&gt;The questions were straightforward but slightly lengthy. Here's a breakdown:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. First Question: Barcode Generation&lt;/strong&gt;&lt;br&gt;
The task was to generate a barcode based on some predefined parameters. While the question wasn't inherently complex, it required attention to detail to ensure all conditions were met. I approached this problem methodically, breaking it down into smaller parts and implementing a solution in JavaScript. The focus was on efficiency and clarity, ensuring that the generated barcode met the expected format and constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Second Question: Array Processing with Deployment Status&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was more of a data manipulation task. The input consisted of objects, each with a deployment ID and a deployment status. My goal was to return an array based on these inputs. While the problem seemed simple, it came with its share of edge cases. For instance, some objects were missing keys, which wasn’t apparent at first glance. However, after submitting my initial solution, I realized that such edge cases needed to be accounted for. I quickly revised my code to handle these scenarios, ensuring that the missing keys wouldn’t lead to errors or incomplete results.&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%2Fuploads%2Farticles%2Fhmkyfpsw0qybonabkraz.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%2Fuploads%2Farticles%2Fhmkyfpsw0qybonabkraz.gif" alt="Cat gif"&gt;&lt;/a&gt;&lt;br&gt;
I solved both questions using JavaScript and was confident that my solutions passed all the test cases, including the hidden ones.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Amazon tends to move candidates forward in the process if they solve all the coding questions with all test cases passing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After that got a call from recruiter saying that he is moving forward with the interview process, and it is going to be an onsite interview. I had 5 days to prepare. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I have been working remotely from past 3 years and never been to office, so I was scared more because of office rather than the interview rounds 🙃😂&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Further Interview Rounds
&lt;/h2&gt;

&lt;p&gt;I went to the amazon office, few candidates were already there. We all went for interviews. I had 3 technical rounds of interview that day.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Troubleshooting Round
&lt;/h3&gt;

&lt;p&gt;The first round was a troubleshooting-focused interview. As soon as I walked into the room, I was greeted by an interviewer who was incredibly supportive. He kept smiling throughout the session, which helped ease my nervousness.&lt;/p&gt;

&lt;p&gt;He handed me a sheet of paper and presented several questions related to system failures, networking, and network layers. The approach he used was particularly interesting. He asked me to think about basic solutions first—essentially encouraging me to solve the problem from the ground up. Once I provided an answer, he changed the scenario slightly, adding more complexity with each step.&lt;/p&gt;

&lt;p&gt;For example, after discussing a network failure, he shifted the conversation to deeper layers of the network and asked what I would do if standard solutions didn’t work. This pushed me to think creatively and consider various failure points in a system, from the most common to more intricate issues.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Interview asked me to wait outside, after that one recruiter came and said that I will be going for second round.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. DSA Round
&lt;/h3&gt;

&lt;p&gt;The next round was a deep dive into data structures and algorithms (DSA). This time, my interviewer was a senior SDE at Amazon. She greeted me with a sheet of paper and presented a fairly large and complex question. As I read through it, I quickly realized that the main objective was to find the shortest path in a graph. This type of problem is common in interviews but can get tricky when edge cases are involved, which she was sure to include.&lt;/p&gt;

&lt;p&gt;I asked a few clarifying questions to fully understand the problem and its various scenarios. Once I felt confident, I began to work on a solution—writing pseudocode directly on the paper. As I explained my approach and logic, she continuously probed deeper, asking why I made certain decisions and how I was handling different parts of the graph. I walked her through my thought process, discussing the trade-offs and optimizations. Fortunately, I was able to solve the question completely and correctly.&lt;/p&gt;

&lt;p&gt;Once she was satisfied with my graph solution, she asked me about the time and space complexity, which I analyzed and explained to her. Feeling a sense of accomplishment, I thought the round was going well.&lt;/p&gt;

&lt;p&gt;However, she soon moved on to another, more challenging question—this time involving dynamic programming (DP). The problem involved a matrix in which different crops needed to be planted in a way that followed certain rules. This was a more complex question, and I took my time to fully understand it. I asked several questions to ensure I covered all the constraints and edge cases.&lt;/p&gt;

&lt;p&gt;I wrote a pseudocode solution, but it wasn’t fully optimized. She gave me some test cases, and while my code ran successfully on about 80% of them, there were still edge cases that failed. I was getting nervous at this point, and she noticed that. Fortunately, she offered a helpful hint, and I tried to optimize my solution further. Despite my best efforts, I couldn't completely nail the solution, likely due to my nerves taking over.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I waited outside again, I was not very happy and confident about with this round, but the recruiter again came said that my next round is System design. I got so happy!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. System Design Round
&lt;/h3&gt;

&lt;p&gt;The final round of the day was the System Design interview, and this was by far the most intense and draining session. The interviewer was part of Amazon’s architecture team, and right from the start, I could tell that this round would be challenging. We began with a discussion about my resume, focusing on my past projects and the design decisions I had made in previous work. He asked several questions about the architecture of the systems I had worked on, probing into the details of my design choices and the trade-offs I made.&lt;/p&gt;

&lt;p&gt;After this initial discussion, he asked me to design a system for an ed-tech platform, with a specific focus on the video streaming feature. The goal was to design a system where teachers could stream live video sessions, and students could attend those sessions online.&lt;/p&gt;

&lt;p&gt;We began with the high-level architecture, discussing the main components such as video servers, databases, and APIs. I explained my approach to handling the large number of users and ensuring a smooth video streaming experience. He continuously asked about scalability, reliability, and latency issues, which are crucial for a platform with live video.&lt;/p&gt;

&lt;p&gt;Once we had covered the high-level design, he shifted the conversation to the low-level details. This is where the discussion became more technical. We explored various approaches for optimizing the system, handling edge cases, and ensuring a seamless experience for users even in worst-case scenarios. I had to think on my feet, offering solutions and alternatives for different problems, including handling spikes in user traffic and ensuring minimal downtime.&lt;/p&gt;

&lt;p&gt;The interviewer kept presenting different scenarios—what if a video server goes down? How would you handle network congestion? How do you ensure low latency for students in different geographical regions? Each scenario required a detailed answer, and I found myself fully immersed in discussing possibilities and design patterns.&lt;/p&gt;

&lt;p&gt;The entire interview lasted about 1.5 hours, and by the end of it, I was exhausted. It was mentally draining but also one of the most insightful interviews I’ve ever had. We explored various architectural challenges, and it felt more like a collaborative problem-solving session than a traditional interview.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So I went to amazon office at 9 AM in the morning and came out at 5 PM in the evening, &lt;strong&gt;I had all my rounds completed and the recruiter said that he is moving forward with the managerial round,&lt;/strong&gt; which is not scheduled yet. &lt;/p&gt;
&lt;/blockquote&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%2Fuploads%2Farticles%2F9rdwgj27f7jrjjgdr67j.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%2Fuploads%2Farticles%2F9rdwgj27f7jrjjgdr67j.gif" alt="Office gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Anyways forgot to tell you one thing, Please understand all the amazon's principle before going for the interview, they will ask at-least 2 question around it in every round. So please prepare that as well
&lt;/h4&gt;

</description>
      <category>interview</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>aws</category>
    </item>
    <item>
      <title>Top 10 JavaScript Interview Questions You Need to Know</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Tue, 10 Sep 2024 10:34:48 +0000</pubDate>
      <link>https://dev.to/naweli_verma/top-10-javascript-interview-questions-you-need-to-know-1ood</link>
      <guid>https://dev.to/naweli_verma/top-10-javascript-interview-questions-you-need-to-know-1ood</guid>
      <description>&lt;p&gt;Introduction:&lt;/p&gt;

&lt;p&gt;JavaScript remains one of the most popular programming languages in web development. Whether you’re a junior developer or a seasoned professional, mastering JavaScript is crucial for acing interviews. In this blog, we’ll cover ten essential JavaScript interview questions that every developer should be prepared to answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. What Are Closures in JavaScript?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Closures are a fundamental concept in JavaScript. They occur when a function retains access to its lexical scope, even when the function is executed outside that scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction() {
  let outerVariable = 'I am from outer scope';

  function innerFunction() {
    console.log(outerVariable); // Accesses outerVariable
  }

  return innerFunction;
}

const closureFunction = outerFunction();
closureFunction(); // Outputs: I am from outer scope

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Closures are key to understanding data encapsulation and function scope in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Explain the Event Loop and How It Works&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Event Loop is a mechanism that allows JavaScript to perform non-blocking operations despite being single-threaded. It works by placing operations in a queue and executing them when the call stack is empty.&lt;/p&gt;

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

&lt;p&gt;Call Stack: Handles function execution.&lt;br&gt;
Callback Queue: Holds callbacks that are ready to be executed.&lt;br&gt;
Event Loop: Moves tasks from the callback queue to the call stack.&lt;br&gt;
Why It Matters: Understanding the event loop is essential for writing efficient and responsive JavaScript code.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;3. What Is the Difference Between == and ===?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;== (Equality Operator): Compares values with type coercion.&lt;br&gt;
=== (Strict Equality Operator): Compares values without type coercion (strict equality).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 == '5');  // true
console.log(5 === '5'); // false

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Using === avoids unexpected bugs caused by type coercion, making code more predictable and reliable.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. What Are Promises and How Do They Work?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Promises are objects representing the eventual completion or failure of an asynchronous operation. They provide a cleaner way to handle asynchronous code compared to callbacks.&lt;/p&gt;

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

&lt;p&gt;then(onFulfilled, onRejected): Handles resolved and rejected states.&lt;br&gt;
catch(onRejected): Handles errors.&lt;br&gt;
finally(onFinally): Executes code regardless of the promise’s outcome.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise = new Promise((resolve, reject) =&amp;gt; {
  setTimeout(() =&amp;gt; resolve('Resolved!'), 1000);
});

promise.then(result =&amp;gt; console.log(result)); // Outputs: Resolved!

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;5. What Is the this Keyword in JavaScript?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The this keyword refers to the object that is executing the current function. Its value depends on the context in which a function is called.&lt;/p&gt;

&lt;p&gt;Common Use Cases:&lt;/p&gt;

&lt;p&gt;Global Context: this refers to the global object.&lt;br&gt;
Object Method: this refers to the object.&lt;br&gt;
Constructor Function: this refers to the instance created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj = {
  name: 'Alice',
  greet: function() {
    console.log(this.name);
  }
};

obj.greet(); // Outputs: Alice

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;6. What Are Arrow Functions and How Do They Differ from Regular Functions?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Arrow Functions provide a more concise syntax and have lexical this binding, meaning they inherit this from the surrounding context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; a + b;

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

&lt;/div&gt;



&lt;p&gt;Difference:&lt;/p&gt;

&lt;p&gt;Regular Function: Has its own this.&lt;br&gt;
Arrow Function: Inherits this from the parent scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters:&lt;/strong&gt; Arrow functions simplify code and prevent common issues with this binding in callbacks. Arrow functions simplify code and prevent common issues with this binding in callbacks.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;7. How Does Prototypal Inheritance Work in JavaScript?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Prototypal Inheritance allows objects to inherit properties and methods from other objects. JavaScript uses prototypes to implement inheritance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const animal = {
  speak() {
    console.log('Animal speaks');
  }
};

const dog = Object.create(animal);
dog.bark = function() {
  console.log('Woof');
};

dog.speak(); // Outputs: Animal speaks
dog.bark();  // Outputs: Woof

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;8. What Is the Difference Between null and undefined?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;null: Represents an intentional absence of value.&lt;/p&gt;

&lt;p&gt;undefined: Represents a variable that has been declared but not initialized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a;
console.log(a); // Outputs: undefined

let b = null;
console.log(b); // Outputs: null

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;9. What Are map, filter, and reduce Methods?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;These are higher-order functions used for array manipulation:&lt;/p&gt;

&lt;p&gt;map: Creates a new array by applying a function to each element.&lt;br&gt;
filter: Creates a new array with elements that pass a test.&lt;br&gt;
reduce: Reduces an array to a single value by applying a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const doubled = numbers.map(n =&amp;gt; n * 2);
const evens = numbers.filter(n =&amp;gt; n % 2 === 0);
const sum = numbers.reduce((total, n) =&amp;gt; total + n, 0);

console.log(doubled); // [2, 4, 6, 8, 10]
console.log(evens);   // [2, 4]
console.log(sum);     // 15

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;10. How Do You Optimize JavaScript Performance?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Performance Optimization Techniques:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minify and Bundle&lt;/strong&gt;: Use tools like Webpack to minify and bundle JavaScript files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Loading&lt;/strong&gt;: Load resources only when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debouncing/Throttling&lt;/strong&gt;: Control the rate of function execution in response to events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid Memory Leaks&lt;/strong&gt;: Ensure proper cleanup of event listeners and intervals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Mastering these ten JavaScript interview questions will prepare you for various scenarios and challenges you might face in technical interviews. Deepening your understanding of these topics will not only help you in interviews but also improve your overall JavaScript skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Power comes in response to a need, not a desire. You have to create that need.&lt;/strong&gt;"&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How does Blockchain work?</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Mon, 08 Jan 2024 13:43:36 +0000</pubDate>
      <link>https://dev.to/naweli_verma/how-does-blockchain-work-12gb</link>
      <guid>https://dev.to/naweli_verma/how-does-blockchain-work-12gb</guid>
      <description>&lt;h2&gt;
  
  
  What exactly is Blockchain?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Blockchain is a type of database&lt;/strong&gt;, which has a chain of data stored in blocks,it has unique characteristics that differentiate it from traditional databases. The key features of a blockchain include decentralization, immutability, and security through cryptographic techniques.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralization&lt;/strong&gt;: In a traditional database, data is usually stored in a central location, and access is controlled by a central authority. In a blockchain, the data is distributed across a network of nodes (computers) that participate in the network. Each node has a copy of the entire database, and there is no central authority controlling the entire system. This decentralized nature makes it resistant to censorship and single points of failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutability&lt;/strong&gt;: Once data is added to the blockchain, it becomes extremely difficult to alter or delete. Each block in the chain contains a reference to the previous block, and changing the information in one block would require changing all subsequent blocks, which is computationally infeasible. This immutability provides a high level of trust in the integrity of the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Blockchain uses cryptographic techniques to secure transactions and control access to the data. Nodes on the network validate and agree on the transactions before they are added to the blockchain. The consensus mechanism (such as proof-of-work or proof-of-stake) ensures that malicious actors cannot easily manipulate the data or compromise the network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zqCKo-NR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bm8htijpfcsz6oadais.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zqCKo-NR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bm8htijpfcsz6oadais.jpg" alt="Blockchain hash and blocks" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The security of a blockchain relies on the cryptographic link between blocks. Each block contains a hash (a unique identifier) based on its data and the hash of the previous block. If someone attempts to change the information in a block, it alters its hash. As a result, the subsequent block's reference becomes invalid, breaking the chain. This interconnectedness makes it computationally infeasible to alter one block without changing every subsequent block—a feature that enhances the immutability and security of the blockchain.&lt;/p&gt;

&lt;p&gt;While blockchain technology provides a high level of security and immutability, it's important to note that no system is completely unhackable. The security of a blockchain network depends on factors such as the consensus mechanism, network size, and the implementation of cryptographic techniques. Additionally, vulnerabilities in the software or smart contracts built on top of the blockchain can still be exploited.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering React Query's useQuery for Data Fetching</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Thu, 19 Oct 2023 18:29:20 +0000</pubDate>
      <link>https://dev.to/naweli_verma/mastering-react-querys-usequery-for-data-fetching-olf</link>
      <guid>https://dev.to/naweli_verma/mastering-react-querys-usequery-for-data-fetching-olf</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the ever-evolving world of web development, managing data fetching in your React applications is a crucial part of building responsive and performant user interfaces. While there are various tools and libraries available for this purpose, one of the most popular choices among developers is React Query. React Query simplifies data fetching, caching, and state management, making it a breeze to work with complex data-related tasks. &lt;/p&gt;

&lt;p&gt;In this blog post, we will delve into the core concept of React Query: the useQuery hook, and explore how to use it effectively in your projects.&lt;/p&gt;

&lt;p&gt;In React, fetching data is a common task. Whether you're making calls to a backend API or simply retrieving data from a local store, data fetching can quickly become complex and difficult to manage.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;useQuery&lt;/strong&gt; comes in. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is React Query?
&lt;/h2&gt;

&lt;p&gt;React Query is a library that simplifies data management in React applications. It offers a comprehensive set of tools for fetching, caching, synchronizing, and updating data from your API endpoints. With React Query, you can streamline your data-fetching logic, handle data updates efficiently, and keep your UI in sync with the server's state.&lt;/p&gt;

&lt;h2&gt;
  
  
  The useQuery Hook
&lt;/h2&gt;

&lt;p&gt;useQuery is a React hook provided by React Query that makes data fetching simple, predictable, and performant.&lt;br&gt;
The useQuery hook is one of the key features of React Query, and it plays a vital role in simplifying the data-fetching process. It abstracts away much of the complex logic associated with fetching data and provides a clean and easy-to-use API for managing asynchronous data.&lt;/p&gt;
&lt;h2&gt;
  
  
  How does useQuery work?
&lt;/h2&gt;

&lt;p&gt;To get started with useQuery, you need to import it from React Query and then invoke it. useQuery takes a query key and a query function as arguments. The query key is a unique identifier for the data you want to fetch, which can be any string or array of values. The query function is an asynchronous function that returns the data.&lt;/p&gt;

&lt;p&gt;When useQuery is called, it will first check if the data for the given query key is already cached. If the data is cached, it will be returned immediately. If the data is not cached, the query function will be called and the data will be fetched.&lt;/p&gt;

&lt;p&gt;Once the data has been fetched, it will be stored in the cache and returned. The next time useQuery is called with the same query key, the cached data will be returned immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from 'react-query';

const getProducts = () =&amp;gt; {
  return fetch('https://api.example.com/products').then(res =&amp;gt; res.json());
};

const Products = () =&amp;gt; {
  const { isLoading, error, data } = useQuery('products', getProducts);

  if (isLoading) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;

  if (error) return &amp;lt;div&amp;gt;Error: {error.message}&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;ul&amp;gt;
      {data.map(product =&amp;gt; (
        &amp;lt;li key={product.id}&amp;gt;{product.name}&amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;In this example, the useQuery hook is used to fetch a list of products from an API. The queryKey is products and the queryFunction is getProducts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling Loading and Errors
&lt;/h2&gt;

&lt;p&gt;Asynchronous data fetching can result in various states, including loading and error states. React Query provides isLoading and error properties to help you manage these states gracefully. You can conditionally render loading spinners or error messages based on these values, as shown in the earlier example.&lt;/p&gt;

&lt;p&gt;In this example, the Products component renders a loading message while the data is being fetched. If there is an error, the component renders an error message. If the data is successfully fetched, the component renders a list of products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caching
&lt;/h2&gt;

&lt;p&gt;One of the most significant advantages of using React Query is its built-in caching mechanism. When you use useQuery to fetch data, React Query automatically stores the fetched data in a cache. Subsequent calls to the same query key will return the cached data instead of making a duplicate API request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const { isLoading, error, data } = useQuery('products', getProducts);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automatic Data Refetching
&lt;/h2&gt;

&lt;p&gt;React Query also handles automatic data refetching for you. You can set up automatic background data refetching at a specified interval, ensuring your UI always displays the most up-to-date data.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
  const { isLoading, error, data } = useQuery('products', getProducts,{ refetchInterval: 5000, // Refetch every 5 seconds&lt;br&gt;
});&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;React Query's useQuery hook is a powerful and flexible tool for handling data fetching in your React applications. It simplifies the process, manages caching, and helps you handle loading and error states effortlessly. If you're looking for a way to improve the way you manage data fetching in your React applications, I encourage you to give useQuery a try. &lt;/p&gt;

&lt;h3&gt;
  
  
  Happy coding!
&lt;/h3&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>api</category>
      <category>javascript</category>
    </item>
    <item>
      <title>OOP vs OOD</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Sat, 13 May 2023 12:59:31 +0000</pubDate>
      <link>https://dev.to/naweli_verma/oop-vs-ood-gnp</link>
      <guid>https://dev.to/naweli_verma/oop-vs-ood-gnp</guid>
      <description>&lt;h2&gt;
  
  
  OOP
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Object Oriented Programming
&lt;/h3&gt;

&lt;p&gt;OOP stands for Object-Oriented Programming, which is a programming paradigm that focuses on organizing code around objects, which are instances of classes. OOP promotes the use of encapsulation, inheritance, and polymorphism to structure and design software.&lt;/p&gt;

&lt;p&gt;It emphasizes the creation of reusable and modular code by breaking down complex systems into smaller, self-contained objects that interact with each other. OOP languages, such as Java, C++, and Python, provide features and constructs to implement OOP principles effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  OOD
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Object Oriented Design
&lt;/h3&gt;

&lt;p&gt;On the other hand, OOD stands for Object-Oriented Design, which is a broader concept that encompasses the process of designing software systems using object-oriented principles. OOD involves the high-level design decisions and architectural considerations taken during the initial phases of software development. &lt;/p&gt;

&lt;p&gt;It includes identifying objects, their relationships, responsibilities, and interactions to create a well-structured and maintainable system. OOD focuses on conceptualizing the system's structure, defining classes, and designing the overall architecture before moving into the implementation phase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's understand it by a simple example.
&lt;/h3&gt;

&lt;p&gt;Suppose we want to create a program to simulate a zoo. We'll start with OOD, which involves designing the system before writing any code. In this stage, we would identify the key objects and their relationships. For a zoo, we might have objects like "Zoo," "Animal," "Lion," and "Tiger." The Zoo object would contain a collection of Animal objects, which can be either Lion or Tiger. We would define the properties and behaviors of each object, such as the Animal's name, age, and sound it makes, and the Zoo's capacity and methods to add or remove animals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;

class Animal {
protected:
    std::string name;
    int age;

public:
    Animal(const std::string&amp;amp; name, int age) : name(name), age(age) {}

    virtual void make_sound() {
        // Placeholder for the specific sound each animal makes
    }
};

class Lion : public Animal {
public:
    Lion(const std::string&amp;amp; name, int age) : Animal(name, age) {}

    void make_sound() override {
        std::cout &amp;lt;&amp;lt; "Roar!" &amp;lt;&amp;lt; std::endl;
    }
};

class Tiger : public Animal {
public:
    Tiger(const std::string&amp;amp; name, int age) : Animal(name, age) {}

    void make_sound() override {
        std::cout &amp;lt;&amp;lt; "Growl!" &amp;lt;&amp;lt; std::endl;
    }
};

class Zoo {
private:
    int capacity;
    std::vector&amp;lt;Animal*&amp;gt; animals;

public:
    Zoo(int capacity) : capacity(capacity) {}

    void add_animal(Animal* animal) {
        if (animals.size() &amp;lt; capacity) {
            animals.push_back(animal);
        } else {
            std::cout &amp;lt;&amp;lt; "Zoo is full!" &amp;lt;&amp;lt; std::endl;
        }
    }

    void remove_animal(Animal* animal) {
        auto it = std::find(animals.begin(), animals.end(), animal);
        if (it != animals.end()) {
            animals.erase(it);
        }
    }

    void display_animals() {
        for (Animal* animal : animals) {
            std::cout &amp;lt;&amp;lt; animal-&amp;gt;name &amp;lt;&amp;lt; " (" &amp;lt;&amp;lt; typeid(*animal).name() &amp;lt;&amp;lt; "), Age: " &amp;lt;&amp;lt; animal-&amp;gt;age &amp;lt;&amp;lt; std::endl;
        }
    }
};

int main() {
    Zoo zoo(3);

    Lion lion("Simba", 5);
    Tiger tiger("Sher Khan", 7);

    zoo.add_animal(&amp;amp;lion);
    zoo.add_animal(&amp;amp;tiger);

    zoo.display_animals();

    lion.make_sound();
    tiger.make_sound();

    return 0;
}

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

&lt;/div&gt;



&lt;p&gt;The Animal class is a base class with the name and age properties and a virtual make_sound function. The Lion and Tiger classes inherit from Animal and override the make_sound function with their specific sound implementations. &lt;/p&gt;

&lt;p&gt;The Zoo class has an add_animal function that accepts a pointer to an Animal object and manages a vector of animal pointers. The rest of the code demonstrates how to create instances of animals, add them to the zoo, and call the appropriate methods.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>systemdesign</category>
      <category>oop</category>
      <category>interview</category>
    </item>
    <item>
      <title>An exposer to JSX</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Sun, 26 Jun 2022 14:52:40 +0000</pubDate>
      <link>https://dev.to/naweli_verma/an-exposer-to-jsx-ldk</link>
      <guid>https://dev.to/naweli_verma/an-exposer-to-jsx-ldk</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Things that look complex are not necessary to be complex&lt;/strong&gt;&lt;/em&gt; 😲&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://twitter.com/naweli_verma"&gt;twitter&lt;/a&gt; ❤️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wait,&lt;/strong&gt; before that, sorry read it first than open your phone otherwise I know you will end up scrolling. We all do that 😆 😝 😄 &lt;/p&gt;

&lt;p&gt;ReactJs uses &lt;strong&gt;JSX&lt;/strong&gt; to generate the UI. Now you must be thinking oh! now what the hell is this. 😩😩&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSX = JavaScript + XML&lt;/strong&gt; 😕&lt;br&gt;
and yeah, you don't need to learn XML for this!😛&lt;/p&gt;

&lt;p&gt;Let me tell you with some points. &lt;/p&gt;
&lt;h2&gt;
  
  
  What is JSX? 🍄
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JSX is nothing but a syntax extension to JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows you to write &lt;strong&gt;HTML + JavaScript&lt;/strong&gt;  together in React Code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is HTML like syntax, that extends EcmaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is simpler and elegant way to write React Code.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var marvelHeroes= (
    &amp;lt;ul id="marvelHeroes"&amp;gt;
      &amp;lt;li&amp;gt;Iron-Man&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;Thor&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;Doctor Strange (My fav)&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;Captain America&amp;lt;/li&amp;gt;
      &amp;lt;li&amp;gt;Spiderman&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The above code is JSX. I am sure, it's not complete alien syntax for you. 😄&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Don't tell me it is completely alien to you.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here, if we try to understand the syntax, it's JavaScript where we are adding some HTML elements like a unordered list tag and list tag 😄&lt;/p&gt;

&lt;p&gt;Now you must be thinking, Why we are usinhg JSX???? 🙆‍♀️&lt;/p&gt;

&lt;p&gt;We are using JSX cause it makes our code &lt;strong&gt;simpler, elegant and more readable.&lt;/strong&gt; 🙆‍♀️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How?&lt;/strong&gt; 🙀🙀&lt;/p&gt;

&lt;p&gt;Let's understand both How and Why.&lt;/p&gt;

&lt;p&gt;React creates it's own DOM. A &lt;strong&gt;virtual DOM&lt;/strong&gt;, which is exact replica of the Real DOM and it holds JavaScript objects. It is faster than real DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM means Document Object Model&lt;/strong&gt;. It holds all those elements and attributes in node. It creates a tree like structure in the background when we add some element to our code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IfaqzWPq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcizlwcfhkuevcho29vt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IfaqzWPq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcizlwcfhkuevcho29vt.png" alt="Virtual Dom" width="880" height="743"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, if we want to add some element to our React project, suppose a list of heroes, for that we we need to add &lt;strong&gt;list tag&lt;/strong&gt; element which will go in your react virtual DOM.&lt;/p&gt;

&lt;p&gt;For adding or creating that element, we need to write instruction for React to create elements in the DOM.&lt;/p&gt;

&lt;p&gt;The syntax for that is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React.createElement(type,{props},children); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where&lt;br&gt;
&lt;strong&gt;type:&lt;/strong&gt; the type of the HTML element &lt;br&gt;
&lt;strong&gt;props:&lt;/strong&gt; properties of the object that components will take&lt;br&gt;
&lt;strong&gt;children:&lt;/strong&gt; any data that will be visible in the UI.&lt;/p&gt;

&lt;p&gt;Now, let's try to create the same heroes list that we've just created using JSX, but this time using the &lt;strong&gt;React.createElement&lt;/strong&gt; syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var marvelHeores= React.createElement(
   "ul",
   { id: "marvelHeores" },
   React.createElement(
      "li",
      null,
      "Iron-Man"
   ),
   React.createElement(
      "li",
      null,
      "Thor"
   ),
   React.createElement(
      "li",
      null,
      "Doctor-Strange"
   ),
   React.createElement(
      "li",
      null,
      "Captain America"
   ),
   React.createElement(
      "li",
      null,
      "Spiderman"
   )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are feeling the struggle. Right? 😆 😹&lt;/p&gt;

&lt;p&gt;The syntax is super lengthy when we use React.createElement(), and it gets more complicated when you want to use some nested elements.&lt;/p&gt;

&lt;p&gt;So, for handling all these burden, we use JSX. ❤️&lt;/p&gt;

&lt;p&gt;JSX is a &lt;strong&gt;SYNATICAL SUGAR&lt;/strong&gt; to cut down the struggle of using React.createElement().&lt;/p&gt;

&lt;p&gt;We are pretty much done here, I just want you to know some points before you write your first JSX. 👼&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you want to add some JavaScript or some decision making code just wrap it in the &lt;strong&gt;curly braces{}&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;onclick&lt;/strong&gt; is &lt;strong&gt;onClick&lt;/strong&gt; and the &lt;strong&gt;class&lt;/strong&gt; is &lt;strong&gt;className&lt;/strong&gt; in JSX.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All HTML elements in JSX starts with &lt;strong&gt;lowercase&lt;/strong&gt; while component names starts with &lt;strong&gt;UpperCase&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Check your App.js&lt;/strong&gt; file in the project that you have just created with me in the previous blog of this series. 🐾🐾&lt;/p&gt;

&lt;p&gt;Happy Building!! &lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://twitter.com/naweli_verma"&gt;twitter&lt;/a&gt; ❤️&lt;/p&gt;

&lt;p&gt;Now we have completed your blog here, click on the twitter link and connect there with me 😁😁&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Class and Function Components</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Fri, 24 Jun 2022 12:53:50 +0000</pubDate>
      <link>https://dev.to/naweli_verma/react-components-5gef</link>
      <guid>https://dev.to/naweli_verma/react-components-5gef</guid>
      <description>&lt;h2&gt;
  
  
  &amp;gt; &lt;strong&gt;Every drop makes an ocean&lt;/strong&gt; 🌟 🌊
&lt;/h2&gt;

&lt;p&gt;You cannot deny the above quote. Right?&lt;/p&gt;

&lt;p&gt;PS: The every blog of this &lt;a href="https://dev.to/naweli_verma/series"&gt;React Series&lt;/a&gt;, is also more like a water drops, to make you a ocean of knowledge. 🌞&lt;/p&gt;

&lt;p&gt;Well we are going to learn about the most important and a very crucial part of ReactJs, which are &lt;strong&gt;Components&lt;/strong&gt;. 🌋&lt;/p&gt;

&lt;p&gt;If you ask me &lt;strong&gt;what are components&lt;/strong&gt; by giving a real world example, I will say a &lt;strong&gt;ReactJs web app is an ocean and the components are the water droplets.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Makes sense? 😄&lt;/p&gt;

&lt;p&gt;A little, right? 😂&lt;/p&gt;

&lt;p&gt;Be with me, I will tell you what exactly the thing is.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here we go now, hold my hand tight, we are going for the ride.&lt;/em&gt; 🏄&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Components 🍄
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Components are the small building blocks of any ReactJs app. Every ReactJs web app is made up of components. Either one, two components or thousands of them. It is up to the developer, how they want.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;You will know it once you try it.&lt;/em&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It describes the part of user-interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is to break down complex UI in small chunks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is reusable and can be nested inside other components. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ObFzajV_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cta4wgi7h5gw1r1otq49.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ObFzajV_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cta4wgi7h5gw1r1otq49.jpg" alt="React Components" width="561" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let me give you an example so you can picturize it right&lt;/strong&gt; 💆&lt;/p&gt;

&lt;p&gt;Suppose you want a beautiful landing page in your website. What are the things that you will need there?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think and think&lt;/strong&gt; 🙇🙇&lt;/p&gt;

&lt;p&gt;You may want a Header, Footer, Sidebar, Content Body. Integrating all this together you will have your Landing Page. True?&lt;/p&gt;

&lt;p&gt;Now this is what component is, small chunks of of your desired page. 🚀&lt;/p&gt;

&lt;p&gt;If you want a Button and you want the same exact button in your website, so you can simply create a Button Component and can reuse wherever you like. &lt;br&gt;
If you want the same button with different text you can change the text through props. (We will cover this in coming series)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now I am pretty sure you know what exactly a Component is, on that victory let's know little more about it&lt;/strong&gt; 🚀🚀🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Types of Components&lt;/strong&gt; 🍄
&lt;/h2&gt;

&lt;p&gt;There are two types of components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Class Components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Function Components&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Before ReactJs version 16.8.0** ⬅️
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Class Components :mushrooms:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sdy6TBcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd5w5w9vaydbiswobtjn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sdy6TBcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd5w5w9vaydbiswobtjn.png" alt="Class Component" width="880" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It takes object of props optionally and return JSX to the UI.&lt;/p&gt;
&lt;h5&gt;
  
  
  (Don't worry if this line doesn't makes sense a little or at all. You will know it soon it coming series.)
&lt;/h5&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class Components are &lt;strong&gt;used&lt;/strong&gt; ( &lt;em&gt;pay attention on "used" word&lt;/em&gt; )to be called as &lt;strong&gt;stateful&lt;/strong&gt; components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Capable for handling complex UIs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintain their own private data or state to give the power of dynamic nature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provide lifecycle hooks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;this&lt;/strong&gt; keyword can be used here.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function Components :mushrooms:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yrl1-u5i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9e5n91e1eagg34f65lv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yrl1-u5i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9e5n91e1eagg34f65lv.png" alt="Function Component" width="880" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Same like class, it takes object of props optionally and return JSX to the UI.&lt;/p&gt;
&lt;h5&gt;
  
  
  (As I told you earlier, don't worry if this line doesn't makes sense a little or at all. You will know it soon it coming series.)
&lt;/h5&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is simple JavaScript function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function Components are &lt;strong&gt;used&lt;/strong&gt; ( &lt;em&gt;pay attention on "used" word&lt;/em&gt; ) to be called as &lt;strong&gt;stateless&lt;/strong&gt; components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No vision for &lt;strong&gt;this&lt;/strong&gt; keyword.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is not capable of handling any data fetching, other side effects, state rendering or anything which is complex.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  As you just got to know that functional components never was in the choice list when handling complex operations. 😒😒
&lt;/h5&gt;

&lt;p&gt;**But Class Components was also not very developer loving, they are complex, specially the "this" keyword. 😒&lt;/p&gt;

&lt;p&gt;So, to solve this problem, the super genius React parents introduced a super weapon to the react developer, and that is &lt;strong&gt;HOOKS&lt;/strong&gt; ❤️❤️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Devs, things are going to be pretty much more in our favor from here&lt;/strong&gt; 💃💃&lt;/p&gt;

&lt;h2&gt;
  
  
  After ReactJs version 16.8.0** ➡️
&lt;/h2&gt;

&lt;p&gt;In this version of React, they introduced a beautiful and a powerful concepts of Hooks to the community. 🐯🐯🐯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy days are back&lt;/strong&gt; 😄😄&lt;/p&gt;

&lt;p&gt;Let me give you a little insights of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hooks :mushrooms:
&lt;/h2&gt;

&lt;p&gt;I will just give you a little idea about it know.&lt;/p&gt;

&lt;p&gt;Hooks gives a developer the power to use all those side effects, complex UI logics in the functional components, without worrying about &lt;strong&gt;this&lt;/strong&gt; keyword and complex syntax like class components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So from now on, Functional Components also are "Stateful" components&lt;/strong&gt; and we will use this in our whole series. 😍 😄 😃&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Hurrayyyyy!!!!! *&lt;/em&gt; 😍😍&lt;/p&gt;

&lt;p&gt;So now you know why Hooks were introduced.&lt;/p&gt;

&lt;p&gt;If you want to know more &lt;a href="https://stackoverflow.blog/2021/10/20/why-hooks-are-the-best-thing-to-happen-to-react/"&gt;why and what about hooks&lt;/a&gt;, this will help. 🔥&lt;/p&gt;

&lt;p&gt;Okay developers, see you in the next one. &lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://twitter.com/naweli_verma"&gt;twitter&lt;/a&gt; 😃&lt;/p&gt;

&lt;p&gt;We will find a way through the dark 🔥&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>First React.Js App and Folder Structure</title>
      <dc:creator>Naweli Verma</dc:creator>
      <pubDate>Thu, 23 Jun 2022 13:01:01 +0000</pubDate>
      <link>https://dev.to/naweli_verma/first-react-app-and-folder-structure-581o</link>
      <guid>https://dev.to/naweli_verma/first-react-app-and-folder-structure-581o</guid>
      <description>&lt;p&gt;&lt;strong&gt;I am excited to shout out loud that, "Yayyy!! I made my first react app"&lt;/strong&gt; 😃😃😃😃😃&lt;/p&gt;

&lt;p&gt;Just explore with me, it will be fun and you will be confident. &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's create our first react app! 🚀
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Prerequisite 🍄
&lt;/h2&gt;

&lt;p&gt;I want you to &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;install node&lt;/a&gt; in your system, it will make your ReactJs life way to easy. Node provides package manager which is &lt;strong&gt;NPM -&amp;gt; Node Package Manager&lt;/strong&gt;. It manages all the dependencies and third party packages.&lt;/p&gt;

&lt;p&gt;I hope you have a compiler. If not, &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;install VS Code&lt;/a&gt;, it's awesome.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now be a developer and open your terminal&lt;/strong&gt; 👩‍💻&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go into your terminal, to create a react app, run the command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app your_app_name
or
yarn create-react-app your_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now navigate inside your folder
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd your_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now inside your folder, run command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
or
yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open your browser and on &lt;strong&gt;localhost:3000&lt;/strong&gt; you can see your &lt;strong&gt;very first react app&lt;/strong&gt;!! 🔥🔥&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hurrayyyyy!!!!&lt;/strong&gt; 😍😍&lt;/p&gt;

&lt;p&gt;Now let's understand the folder structure for a seamless journey. 📂&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;So, in your folder you can see a file &lt;strong&gt;Package.json&lt;/strong&gt;,📄 a very important and useful one. It holds all the meta data of dependencies, version of your packages, scripts of your react app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;According to your project building you can see &lt;strong&gt;package.lock.json&lt;/strong&gt; if you have used npx and &lt;strong&gt;yarn.lock.json&lt;/strong&gt; if you have used yarn to create your react app. We can leave it as it is.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now you have &lt;strong&gt;node_modules&lt;/strong&gt; file where all your dependencies is installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now let's go into the &lt;strong&gt;Public&lt;/strong&gt; folder, where you have few files but our concern is only for &lt;strong&gt;index.html&lt;/strong&gt;. It is the only &lt;strong&gt;HTML&lt;/strong&gt; file in our folder.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;So the thing is that, React is a &lt;strong&gt;Single Page Application -&amp;gt; SPA&lt;/strong&gt;  it means everything will be dynamic in browser but it is the only file that served up to the browser. You can take it a container file for every single component in your react folder, whether it is 3 files of 30,000 files.&lt;/em&gt; 🔥&lt;/p&gt;

&lt;h3&gt;
  
  
  Now pay close attention ❗
&lt;/h3&gt;

&lt;p&gt;In the &lt;strong&gt;index.html&lt;/strong&gt; file we have a div in the body tag where &lt;strong&gt;id="root&lt;/strong&gt;, you can see that in line no.31 in the attached image. Keep it in your mind I will tell you about it. Before that go to src folder,&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%2Fuploads%2Farticles%2Fi07xu9ljeyx5y0vyesi6.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%2Fi07xu9ljeyx5y0vyesi6.png" alt="index.html"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the Src folder, the most going to be used folder. In this you can see &lt;strong&gt;index.js&lt;/strong&gt; file , and in line no.8 the DOM element that is being used is &lt;strong&gt;root&lt;/strong&gt;, which is the same that you just saw in &lt;strong&gt;index.html&lt;/strong&gt; file.&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%2Fuploads%2Farticles%2Fxg7hsk3e1wlly62arjev.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%2Fxg7hsk3e1wlly62arjev.png" alt="index.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So everything that is in the DOM node is being handled by &lt;strong&gt;root&lt;/strong&gt; and here &lt;strong&gt;App.js&lt;/strong&gt; is being served to the root. &lt;/p&gt;

&lt;p&gt;So let's wrap by saying that &lt;strong&gt;root&lt;/strong&gt; element will be served to browser and content in &lt;strong&gt;App.js&lt;/strong&gt; will be the view of that, like whatever you see in the browser. &lt;/p&gt;

&lt;p&gt;Now you can add and edit anything in the App.js file and see the change in the browser.🥂&lt;/p&gt;

&lt;p&gt;&lt;em&gt;There are other files like logo, css file, which I suggest you to explore&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;So on this note, we have created our very first react app and also got to know about the folder structure. You will know more things when you start doing by your own. 😁 😁&lt;/p&gt;

&lt;p&gt;I hope you are running your react app now. 😁😁&lt;/p&gt;

&lt;p&gt;See you in the next one. 👋&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://twitter.com/naweli_verma" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; 😃&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
