<?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: Programming with Shahan</title>
    <description>The latest articles on DEV Community by Programming with Shahan (@codewithshahan).</description>
    <link>https://dev.to/codewithshahan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F643041%2F8dd0a2d8-8e1d-48bb-9c03-ff3a0fcc056c.PNG</url>
      <title>DEV Community: Programming with Shahan</title>
      <link>https://dev.to/codewithshahan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codewithshahan"/>
    <language>en</language>
    <item>
      <title>How to Build an Unblockable AI Agent for Browser Automation with JavaScript, Bright Data, Gemini, and Playwright</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Sun, 05 Jul 2026 06:53:41 +0000</pubDate>
      <link>https://dev.to/codewithshahan/how-to-build-a-production-ready-browser-automation-ai-agent-with-nodejs-bright-data-gemini-and-39ii</link>
      <guid>https://dev.to/codewithshahan/how-to-build-a-production-ready-browser-automation-ai-agent-with-nodejs-bright-data-gemini-and-39ii</guid>
      <description>&lt;p&gt;&lt;strong&gt;In this full guide, you’ll learn:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  📛 Why &lt;a href="https://medium.com/stackademic/how-to-bypass-anti-bot-walls-for-production-ready-apps-9bf799e34488" rel="noopener noreferrer"&gt;most AI browser agents fail&lt;/a&gt; on modern websites.&lt;/li&gt;
&lt;li&gt;  🧱 How browser fingerprinting and anti-bot systems work.&lt;/li&gt;
&lt;li&gt;  ⛑️ How to build an AI browser agent using JavaScript (Node.js) that combines Gemini, &lt;a href="https://playwright.dev/" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, and &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;Bright Data&lt;/a&gt; to browse real websites, extract live data, analyze, reason, and generate reports locally without maintaining fragile anti-bot infrastructure ourselves that breaks 5 days later.&lt;/li&gt;
&lt;li&gt;  🗃️ How to setup Bright Data production-ready &lt;a href="https://get.brightdata.com/free-proxies" rel="noopener noreferrer"&gt;browser sessions&lt;/a&gt; for AI agent automation without user’s assistance manually.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwxzafjq21qlhienr0bwi.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwxzafjq21qlhienr0bwi.gif" alt="Image of ai agent browser automation" width="760" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🪁Introduction
&lt;/h2&gt;

&lt;p&gt;Building unrestricted anonymous browser automation has developed far beyond writing Playwright scripts that click buttons and scrape HTML. Modern websites actively detect automated traffic using &lt;a href="https://www.firefox.com/en-US/features/block-fingerprinting/" rel="noopener noreferrer"&gt;browser fingerprints&lt;/a&gt;, &lt;a href="https://www.ibm.com/docs/en/ibm-mq/10.0.x?topic=tls-digital-signatures-in-ssltls" rel="noopener noreferrer"&gt;TLS signatures&lt;/a&gt;, IP reputation, and behavioral analysis, making reliable automation significantly more challenging than it was just a few years ago.&lt;/p&gt;

&lt;p&gt;Modern AI browser agents don’t usually fail because they’re arbitrary. Their reasoning, prompts, and planning loops are often sophisticated. The execution layer underneath is fragile.&lt;/p&gt;

&lt;p&gt;Most tutorials show how to connect an LLM to a browser, execute a few &lt;a href="https://docs.brightdata.com/integrations/playwright" rel="noopener noreferrer"&gt;Playwright commands&lt;/a&gt;, and declare you’ve built an autonomous agent.&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;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reality, you’ve ONLY automated a browser. Commercial sites don’t gauge how intelligent your agent is. They judge whether they believe your browser is genuine.&lt;/p&gt;

&lt;p&gt;Before a page even finishes loading, they inspect what your browser actually is: the &lt;a href="https://www.cloudflare.com/learning/ssl/what-happens-in-a-tls-handshake/" rel="noopener noreferrer"&gt;TLS handshake&lt;/a&gt;, IP reputation, browser fingerprints, &lt;a href="https://www.todetect.net/article/canvas/webgl-fingerprint/" rel="noopener noreferrer"&gt;canvas and WebGL fingerprints&lt;/a&gt;, cookies, device characteristics, and even the rhythm of your connection. Dozens of signals are examined in the time it takes the page to start loading.&lt;/p&gt;

&lt;p&gt;If those signals don’t look authentic, your agent rarely reaches the real application. Instead, it encounters CAPTCHA challenges, verification pages, &lt;a href="https://wiki.c2.com/?QuickSilentRedirect=" rel="noopener noreferrer"&gt;silent redirects&lt;/a&gt;, incomplete datasets, or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200" rel="noopener noreferrer"&gt;HTTP 200 responses&lt;/a&gt; that quietly return entirely different content.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffe7qw3v4cwuc0zpp1wb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffe7qw3v4cwuc0zpp1wb6.png" alt="Fake 200 response from amazon after sending raw request without browser fingerprint" width="787" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the biggest challenges in modern browser automation:👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpntlpwtzy9ynq4w69d86.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpntlpwtzy9ynq4w69d86.png" alt="raw http request vs. Bright Data Web Unlocker API gateway" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ve always wanted to &lt;a href="https://blog.stackademic.com/how-to-bypass-anti-bot-walls-for-production-ready-apps-9bf799e34488" rel="noopener noreferrer"&gt;build an autonomous software system&lt;/a&gt; that could function on the web as naturally as a human, not another scraper that extracts a few HTML elements or another automation script that breaks the moment a production website changes.&lt;/p&gt;

&lt;p&gt;Like many developers, I started with HTTP requests, graduated to browser automation, and eventually began building AI agents powered by large language models.&lt;/p&gt;

&lt;p&gt;Along the way, I realized something surprising: intelligence without &lt;a href="https://sajidalianjum.substack.com/p/ai-without-internet-how-offline-ai" rel="noopener noreferrer"&gt;reliable web access&lt;/a&gt; is meaningless.&lt;/p&gt;

&lt;p&gt;Fortunately, solving this problem doesn’t require &lt;a href="https://fingerprint.com/blog/browser-fingerprinting-techniques/" rel="noopener noreferrer"&gt;building your own fingerprinting&lt;/a&gt; or &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;anti-detection infrastructure&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Instead, we’ll let &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;Bright Data handle browser identity&lt;/a&gt;, network reputation, and anti-bot bypass while our AI agent focuses on reasoning and execution.&lt;/p&gt;

&lt;p&gt;Because on today’s web, access is an engineering problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  🏗️ What We Are Building
&lt;/h2&gt;

&lt;p&gt;By the end of this article, we’ll build a fully functional browser automation AI agent called &lt;strong&gt;SIKKI Agent&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of it as an unpaid intern who somehow thinks harder at 3 a.m. than I do: it clicks, scrolls, extracts products, grabs ratings, checks prices, and patiently does the repetitive work I’d rather avoid; the &lt;a href="https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic"&gt;most overqualified intern you’ll never have to pay.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The entire project is built with plain JavaScript. No proprietary framework. No billion-dollar AI platform. Just Node.js, Playwright, Bright Data, and Gemini working together.&lt;/p&gt;

&lt;p&gt;Here’s a quick overview of what we’re going to build:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/1AFVtiBkcxQ"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;🍋‍🟩Note:&lt;/strong&gt; The complete source code is available on GitHub at the end of this article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At a high level, the agent follows this workflow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1sozq8zn3naxs61kj47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr1sozq8zn3naxs61kj47.png" alt="our sikki agent’s blueprint" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is the engineering architecture we’ll build throughout the tutorial:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzj5q1albuon0li1txixz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzj5q1albuon0li1txixz.png" alt="architecture of sikki agent" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🪪 Prerequisite
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Basic JavaScript/TypeScript or Python. E&lt;/strong&gt;ven though I used javascript all over this project, you can follow through this article if you know any programming language. But familiarity with asynchronous programming (&lt;code&gt;async/await&lt;/code&gt;) is required, as both scraping and AI calls rely heavily on it.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Fundamental Node.js or Python Environment:&lt;/strong&gt; Ability to install packages via &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;pip&lt;/code&gt; and manage local environment variables (&lt;code&gt;.env&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;API Keys:&lt;/strong&gt; Active accounts and API keys for both &lt;a href="https://aistudio.google.com/" rel="noopener noreferrer"&gt;Google AI Studio (Gemini API)&lt;/a&gt; and Bright Data. &lt;strong&gt;Both are free to use.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Basic DOM Understanding:&lt;/strong&gt; A general awareness of HTML structure, though our SIKKI AI agent will minimize the need for complex CSS selectors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;We will use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Gemini as the reasoning engine&lt;/li&gt;
&lt;li&gt;  Node.js as the runtime&lt;/li&gt;
&lt;li&gt;  Playwright as the browser controller&lt;/li&gt;
&lt;li&gt;  Bright Data Scraping Browser as the cloud browser infrastructure&lt;/li&gt;
&lt;li&gt;  Memory and retry loops for robustness&lt;/li&gt;
&lt;li&gt;  Structured outputs and screenshots for observation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Our Sikki agent will:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Accept natural language goals&lt;/li&gt;
&lt;li&gt;  Plan browser actions dynamically&lt;/li&gt;
&lt;li&gt;  Connect to a remote cloud browser over CDP (Chrome DevTools Protocol)&lt;/li&gt;
&lt;li&gt;  Access real websites&lt;/li&gt;
&lt;li&gt;  Extract structured information&lt;/li&gt;
&lt;li&gt;  Take screenshots&lt;/li&gt;
&lt;li&gt;  Recover from failures&lt;/li&gt;
&lt;li&gt;  Produce clean results by itself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But more importantly&lt;/p&gt;

&lt;p&gt;You will understand &lt;strong&gt;why&lt;/strong&gt; browser AI agents fail. Why local Playwright breaks. Why websites detect automation. Why browser identity matters.&lt;/p&gt;

&lt;p&gt;And how modern AI agents separate rational thinking from execution to run successfully on the real web.&lt;/p&gt;

&lt;p&gt;We are NOT building another toy model. We are building an architecture.&lt;/p&gt;

&lt;p&gt;And like all architectures, we begin with the foundations.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧑‍🍼 Building Sikki Project
&lt;/h2&gt;

&lt;p&gt;In this section, I will show you how to setup Sikki project locally using Gemini, Playwright, and Bright Data and run a quick result in terminal to extract information from CNN website. You can skips this section if you know exactly how to integrate Gemini, Playwright, and Bright Data locally.&lt;/p&gt;

&lt;p&gt;Then in the coming section, I will go deeper building the final Sikki agent engine by showing the blueprint and functional implementations step by step.&lt;/p&gt;

&lt;p&gt;So lets start with a basic test to see whether our API keys and tech stacks are working properly:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: ⛏️Create the Project
&lt;/h3&gt;

&lt;p&gt;Open terminal:&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;mkdir&lt;/span&gt; &lt;span class="nx"&gt;sikki&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;agent&lt;/span&gt;
&lt;span class="nx"&gt;cd&lt;/span&gt; &lt;span class="nx"&gt;sikki&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;agent&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable ES Modules:&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;npm&lt;/span&gt; &lt;span class="nx"&gt;pkg&lt;/span&gt; &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Node.js treats &lt;code&gt;.js&lt;/code&gt; files as legacy CommonJS by default. We enable ES Modules to cleanly use modern &lt;code&gt;import&lt;/code&gt; statements and native &lt;code&gt;await&lt;/code&gt; commands at the root level of our AI agent script&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now install the necessary dependencies:&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;npm &lt;span class="nb"&gt;install &lt;/span&gt;playwright
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @google/genai
npm install dotenv
npm install chalk
npm install ora
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our project’s folder structure should look like this (create these other directories manually):&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;sikki&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;agent&lt;/span&gt;
 &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;
 &lt;span class="nx"&gt;screenshots&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
 &lt;span class="nx"&gt;reports&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
 &lt;span class="kr"&gt;package&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxsc4ujp4ag6bl9l6757o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxsc4ujp4ag6bl9l6757o.png" alt="project’s folder structure" width="328" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: 🗝️ Get Gemini API Key
&lt;/h3&gt;

&lt;p&gt;Go to: &lt;a href="https://aistudio.google.com/" rel="noopener noreferrer"&gt;https://aistudio.google.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create Gemini API Key by creating a new project called “Sikki-Agent”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9qcmfxuklkarqfkd38g8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9qcmfxuklkarqfkd38g8.png" alt="gemini api key generation image" width="800" height="245"&gt;&lt;/a&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F765bdqmhkw6cg2rxjc9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F765bdqmhkw6cg2rxjc9p.png" alt="gemini api key project dashboard" width="567" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside your .env file, paste your Gemini API key:&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;GEMINI_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;your_gemini_api_key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;//i will show you later&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: 😶‍🌫️ Setting up Bright Data Cloud Browser Infrastructure
&lt;/h3&gt;

&lt;p&gt;Sign up for &lt;a href="https://get.brightdata.com/browser-api" rel="noopener noreferrer"&gt;Bright Data Browser API&lt;/a&gt; to log into your control panel dashboard.&lt;/p&gt;

&lt;p&gt;Once you are inside the main console sidebar, do not search for generic proxy settings. Navigate directly to the &lt;strong&gt;Web Access API&lt;/strong&gt; section on the left-hand navigation menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fombet8byrofbgmlbo5po.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fombet8byrofbgmlbo5po.png" alt="bright data web access image" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the Top right corner “Create API” and choose option labeled &lt;strong&gt;Browser API:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr0okt1l33tmvidatiqh7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fr0okt1l33tmvidatiqh7.png" alt="Bright Data creates an API for browser automation image" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then click “continue” and name your API key or leave it default.&lt;/p&gt;

&lt;p&gt;Now click “Add API”; you will find your unique &lt;strong&gt;WebSocket Connection Endpoint&lt;/strong&gt;. Copy that first puppeteer/playwright endpoint starting with “wss://brd-customer-hl…” Paste it in your .env file in your local project.&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;BRIGHT_WS_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;your_endpoint&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will look exactly like this perpetual connection string:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdn1o1bbsmr8yxt8uek8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdn1o1bbsmr8yxt8uek8u.png" alt="Bright data browser api key" width="791" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;We are NOT launching:&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;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead:&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;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meaning: Your browser lives in the cloud.&lt;/p&gt;

&lt;p&gt;To help you understand lets write a simple code block to browse CNN’s title from our local terminal using Playwright and Bright Data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: 🦧 Connect Playwright to Bright Data
&lt;/h3&gt;

&lt;p&gt;Inside your index.js file write that below to access CNN title from terminal:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;playwright&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;BRIGHT_WS_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;your_endpoint&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&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://cnn.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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&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;If you run this on the terminal, you will see a real CNN website title has been shown. We successfully extracted information and displayed the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fer62pjgn4tsyhgym1kk8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fer62pjgn4tsyhgym1kk8.png" alt="extracted cnn information in terminal image" width="800" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you now look at your Bright Data &lt;em&gt;event log&lt;/em&gt; inside &lt;strong&gt;web access&lt;/strong&gt; panel, you will see successful authentication. That means our BrightData and Playwright are working properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ycw7fhqcncqbxx9c9vi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ycw7fhqcncqbxx9c9vi.png" alt="bright data event log panel to check if our api calls are successful" width="799" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;connectOverCDP()&lt;/code&gt; does NOT launch a browser locally.&lt;/p&gt;

&lt;p&gt;Instead, this is what happened:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxjzcetkhtiw6qiiq9kir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxjzcetkhtiw6qiiq9kir.png" alt="image by author" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This separation is one of the most important notions in today’s browser agents:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your AI reasons locally. Your browser executes remotely.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope that makes sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  🐦‍⬛ Going Deeper into SIKKI Agent Before Implementation
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Wait! in this section I will not show you the actual Sikki codebase. I will explain the arthictecture behind SIKKI and how we will implement it in the next setion. You can skip this section if you want.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Up until now, we have built something that resembles a browser automation script. We opened a cloud browser. We visited a website. We extracted information. And we displayed the results.&lt;/p&gt;

&lt;p&gt;That is useful, but it is &lt;strong&gt;not intelligence&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The truth is that many developers stop at this stage and call their projects AI agents. They build a browser script, attach an LLM somewhere in the pipeline, and assume they have built something autonomous.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I don’t think that’s enough.🙅‍♂️&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An autonomous agent is not defined by the presence of an LLM. It is defined by its ability to observe an environment, reason about the information it receives, decide on actions, execute those actions, and continue this cycle until it reaches its objective.&lt;/p&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The browser is not the agent. The model is not the agent. The agent is the system that connects both.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is the architectural philosophy behind SIKKI.&lt;/p&gt;

&lt;h3&gt;
  
  
  🪛 SIKKI is Not A Scraper
&lt;/h3&gt;

&lt;p&gt;I intentionally avoided calling SIKKI a scraper.&lt;/p&gt;

&lt;p&gt;Scrapers collect data. Agents pursue goals.&lt;/p&gt;

&lt;p&gt;Suppose I ask SIKKI:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Find the best gaming laptop under $1000.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A traditional scraper might return the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ProductPriceAcer Nitro V&lt;span class="nv"&gt;$899ASUS&lt;/span&gt; TUF&lt;span class="nv"&gt;$949MSI&lt;/span&gt; Thin&lt;span class="nv"&gt;$979&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful. But not intelligent. An actual agent should ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Which products exceed the budget?&lt;/li&gt;
&lt;li&gt;  Which product has the highest rating?&lt;/li&gt;
&lt;li&gt;  Which seller has the most reviews?&lt;/li&gt;
&lt;li&gt;  Which laptop offers the best price-to-performance ratio?&lt;/li&gt;
&lt;li&gt;  Is the market trending upward or downward?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And finally:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Which one would I personally recommend?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is no longer data extraction. That is reasoning. And that is the moment a browser becomes an intelligent e-commerce agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛣️ The Architecture Behind SIKKI
&lt;/h2&gt;

&lt;p&gt;Internally, SIKKI is composed of &lt;strong&gt;four independent layers.&lt;/strong&gt; Each layer solves a completely different problem:&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;SIKKI&lt;/span&gt;
&lt;span class="nx"&gt;Strategic&lt;/span&gt; &lt;span class="nx"&gt;Intelligence&lt;/span&gt; &lt;span class="nx"&gt;Commerce&lt;/span&gt; &lt;span class="nx"&gt;Kernel&lt;/span&gt;
&lt;span class="err"&gt;┌──────────────────────────────┐&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Browser&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;                &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Playwright&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;Bright&lt;/span&gt; &lt;span class="nx"&gt;Data&lt;/span&gt;     &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;└──────────────────────────────┘&lt;/span&gt;
                &lt;span class="err"&gt;│&lt;/span&gt;
                &lt;span class="err"&gt;▼&lt;/span&gt;
&lt;span class="err"&gt;┌──────────────────────────────┐&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Extraction&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;             &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;                      &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Price&lt;/span&gt;                        &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Rating&lt;/span&gt;                       &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Seller&lt;/span&gt;                       &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Availability&lt;/span&gt;                 &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;└──────────────────────────────┘&lt;/span&gt;
                &lt;span class="err"&gt;│&lt;/span&gt;
                &lt;span class="err"&gt;▼&lt;/span&gt;
&lt;span class="err"&gt;┌──────────────────────────────┐&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;AI&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;                     &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Gemini&lt;/span&gt;                       &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;└──────────────────────────────┘&lt;/span&gt;
                &lt;span class="err"&gt;│&lt;/span&gt;
                &lt;span class="err"&gt;▼&lt;/span&gt;
&lt;span class="err"&gt;┌──────────────────────────────┐&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Analysis&lt;/span&gt; &lt;span class="nx"&gt;Layer&lt;/span&gt;               &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Cheapest&lt;/span&gt; &lt;span class="nx"&gt;Products&lt;/span&gt;            &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Market&lt;/span&gt; &lt;span class="nx"&gt;Average&lt;/span&gt;               &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Competitor&lt;/span&gt; &lt;span class="nx"&gt;Comparison&lt;/span&gt;        &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt; &lt;span class="nx"&gt;Trend&lt;/span&gt; &lt;span class="nx"&gt;Analysis&lt;/span&gt;               &lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;└──────────────────────────────┘&lt;/span&gt;
                &lt;span class="err"&gt;│&lt;/span&gt;
                &lt;span class="err"&gt;▼&lt;/span&gt;
        &lt;span class="nx"&gt;Markdown&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;CSV&lt;/span&gt;
        &lt;span class="nx"&gt;Dashboard&lt;/span&gt; &lt;span class="nx"&gt;Export&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because browser automation problems and reasoning problems are fundamentally different. If Gemini cannot understand your prompt, changing Playwright selectors won’t fix it.&lt;/p&gt;

&lt;p&gt;If Bright Data cannot open a page, increasing Gemini’s context window won’t help. Each layer has a different responsibility. And each layer can evolve independently.&lt;/p&gt;

&lt;h3&gt;
  
  
  🏙️ Building The Extraction Layer
&lt;/h3&gt;

&lt;p&gt;Let’s make SIKKI more useful. Instead of extracting a single CNN headline, let’s teach it how to understand products.&lt;/p&gt;

&lt;p&gt;In the real world, commerce websites display several critical pieces of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Product title&lt;/li&gt;
&lt;li&gt;  Current price&lt;/li&gt;
&lt;li&gt;  Rating&lt;/li&gt;
&lt;li&gt;  Review count&lt;/li&gt;
&lt;li&gt;  Seller information&lt;/li&gt;
&lt;li&gt;  Availability&lt;/li&gt;
&lt;li&gt;  Product link&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A human sees these immediately. Our goal is to teach the browser to see them too.&lt;/p&gt;

&lt;p&gt;Inside Playwright, we can execute JavaScript directly in the page context using &lt;code&gt;page.evaluate()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example:&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;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&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;querySelectorAll&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-component-type="s-search-result"]&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="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;card&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
          &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h2 span&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
          &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.a-price .a-offscreen&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;innerText&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;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
          &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.a-icon-alt&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;innerText&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;link&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
          &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h2 a&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;href&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;title&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;link&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will look like this:&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Acer Nitro V Gaming Laptop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$899&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4.5 out of 5 stars&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;link&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://...&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="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ASUS TUF Gaming A15&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$949&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4.4 out of 5 stars&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;link&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://...&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;At this point, SIKKI has eyes. But it still doesn’t know what it is looking at.&lt;/p&gt;

&lt;p&gt;That is where Gemini enters the architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Giving SIKKI A Brain
&lt;/h3&gt;

&lt;p&gt;I personally think many developers misunderstand LLMs. Gemini is not a magical replacement for code. It is a reasoning engine. This makes it perfect for commerce intelligence.&lt;/p&gt;

&lt;p&gt;After extracting products, we simply send structured JSON to Gemini.&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;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`You are an ecommerce analyst.
Analyze the following products.
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
Return:
1. Cheapest product
2. Average price
3. Best rated product
4. Summary of the market
5. Recommendation
`&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;Gemini may answer:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I analyzed 12 products. The cheapest option is Acer Nitro V at $899.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The average market price is $942.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ASUS TUF has slightly better reviews but is more expensive.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Based on value and user ratings, Acer Nitro V provides the best balance between performance and affordability.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Now SIKKI is not only obtaining information but also&lt;/em&gt; analyzing &lt;em&gt;the output.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🛸 Building the Final SIKKI Agent
&lt;/h2&gt;

&lt;p&gt;At this point, we already have everything we need.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  🌩️ A cloud browser powered by Bright Data&lt;/li&gt;
&lt;li&gt;  🧐 Playwright connected through CDP&lt;/li&gt;
&lt;li&gt;  ⛑️ Gemini API access&lt;/li&gt;
&lt;li&gt;  🚚 A local Node.js project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s put everything together and build the final version of SIKKI.&lt;/p&gt;

&lt;p&gt;The goal is straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open an e-commerce website.&lt;/li&gt;
&lt;li&gt; Search for a product.&lt;/li&gt;
&lt;li&gt; Extract product information.&lt;/li&gt;
&lt;li&gt; Ask Gemini to analyze the results.&lt;/li&gt;
&lt;li&gt; Export the findings into a Markdown report.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By the end of this section, you will have a fully functional browser-use AI Agent running locally.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create the Agent File
&lt;/h3&gt;

&lt;p&gt;Replace your previous local Sikki project index.js file (if you didn’t follow through with our initial “Building Sikki Agent” section) and import the required modules. Paste your Browser CDP endpoint inside your index.js file if you want instant access or follow best practice by creating an .env file (using the dotenv library) to secure your API keys:&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="s2"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//to use environment variables from .env file&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//to read and write files&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;playwright&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@google/genai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//api keys and endpoints from environment variables&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;GEMINI_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize Gemini with a fixed prompt text first, then we will make it dynamic:&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;//initialize the GoogleGenAI client with the Gemini API key&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;//the prompt to send to the Gemini API&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Write a short introduction to the Gemini API.&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gemini-2.5-flash&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the results in our local terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0angv4haf9kqt07f3xdn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0angv4haf9kqt07f3xdn.png" alt="captionless image" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Setup Playwright to connect to Bright Data’s WebSocket
&lt;/h3&gt;

&lt;p&gt;As I have already shown you how to set up Bright Data with Playwright earlier, I will go straight to searching for e-commerce products.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Unlike a Playwright’s normal local browser chromium.launch() we used chromium.connectOverCDP(). This browser runs inside Bright Data’s infrastructure. IP rotation, browser fingerprinting, and anti-bot protection are handled automatically. Your local machine only sends instructions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To test our playwright and bright data working properly, let’s search for “gaming laptops” from amazon:&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;//setup Playwright to connect to Bright Data's WebSocket endpoint and navigate to Amazon search results for "gaming laptop"&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&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;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gaming laptop&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;searchUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://www.amazon.com/s?k=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Navigating Bright Data Playwright to:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;domcontentloaded&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Amazon search page title:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bright Data navigation complete for query:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is our terminal output 👇:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxvry0ort8opb2mt7nbm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzxvry0ort8opb2mt7nbm.png" alt="terminal output for gaming lapto on amazon" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can replace Amazon with: BestBuy, Walmart, Product Hunt, g2, Ebay etc. The logic remains &lt;strong&gt;exactly&lt;/strong&gt; the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Extract Product Information
&lt;/h3&gt;

&lt;p&gt;Now let’s collect structured data.&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;// Playwright to connect to Bright Data's WebSocket endpoint and navigate to Amazon search results for "gaming laptop"&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&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;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gaming laptop&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;searchUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://www.amazon.com/s?k=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Navigating Bright Data Playwright to:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;domcontentloaded&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;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&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;querySelectorAll&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-component-type="s-search-result"]&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="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;card&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="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="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h2 span&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.a-price .a-offscreen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.a-icon-alt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;title&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nx"&gt;rating&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Step 3: Extract Product Information&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Amazon search page title:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bright Data navigation complete for query:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our Result 👇:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi7ptddrbz3jdnyfyfrba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi7ptddrbz3jdnyfyfrba.png" alt="Using playwright to connect to Bright Data’s WebSocket endpoint and navigate to Amazon search results for “gaming laptop”" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, SIKKI has successfully observed the environment.&lt;/p&gt;

&lt;p&gt;Now we give it the ability to reason.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Ask Gemini To Analyze The Market
&lt;/h3&gt;

&lt;p&gt;Create a prompt:&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;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`You are an ecommerce analyst.
Analyze these products:
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
Return:
1. Cheapest Product
2. Average Market Price
3. Best Rated Product
4. Competitor Comparison
5. Final Recommendation
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate:&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&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;analysis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terminal output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frpkb637mjkor5ubuo94d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frpkb637mjkor5ubuo94d.png" alt="terminal results for generated content by gemini image" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the “Best reated product” result and analysis that I pasted from my terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;### 3. Best Rated Product&lt;/span&gt;
There are three products tied &lt;span class="k"&gt;for &lt;/span&gt;the highest rating of &lt;span class="k"&gt;**&lt;/span&gt;5.0 out of 5 stars&lt;span class="k"&gt;**&lt;/span&gt;:
1.  &lt;span class="k"&gt;**&lt;/span&gt;HP OMEN 16&lt;span class="s2"&gt;" Gaming Laptop Computer** (Intel Ultra 9 285H, NVIDIA GeForce RTX 5070 8GB, 16GB DDR5, 1TB PCIe SSD, 144Hz IPS WUXGA Display) at **&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;,745.99**
2.  **HP OMEN 16 Slim RTX 5070 Gaming Laptop** (Intel Ultra 9 285H, NVIDIA RTX 5070, 32GB DDR5, 1TB SSD, 16"&lt;/span&gt; FHD+ Anti-Glare&lt;span class="o"&gt;)&lt;/span&gt; at &lt;span class="k"&gt;**&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;,929.00&lt;span class="k"&gt;**&lt;/span&gt;
3.  &lt;span class="k"&gt;**&lt;/span&gt;ASUS ROG Strix G16 Gaming Laptop&lt;span class="k"&gt;**&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;Intel Core i7 14650HX, NVIDIA RTX 5060, 32 GB DDR5 RAM, 1 TB SSD, 16&lt;span class="s2"&gt;" FHD+ LED Display, &amp;amp; Gaming Accessories) at **&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;,999.99**
**Analysis:** It's noteworthy that two HP OMEN laptops achieved perfect ratings, both featuring high-end Ultra 9 CPUs and RTX 5070 GPUs. 
This suggests strong customer satisfaction with HP's premium gaming line. 
The ASUS ROG Strix G16 also achieved a 5.0 rating, 
despite having a slightly lower-tier GPU (RTX 5060) than the 
HP OMENs in this bracket, possibly due to the included 
"&lt;/span&gt;Gaming Accessories&lt;span class="s2"&gt;" and overall perceived value. 
The Alienware product has no rating, so it cannot be considered here.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what just happened? The browser extracted raw information.&lt;/p&gt;

&lt;p&gt;Gemini transformed it into business intelligence. That small architectural separation is what turns automation into an AI Agent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Export The Sikki Market Report
&lt;/h3&gt;

&lt;p&gt;Now we save the scraped product data and Gemini analysis into real files.&lt;/p&gt;

&lt;p&gt;Instead of dumping raw JSON into the output, the final agent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  extracts clean product titles&lt;/li&gt;
&lt;li&gt;  normalizes URLs&lt;/li&gt;
&lt;li&gt;  writes a Markdown report&lt;/li&gt;
&lt;li&gt;  writes a CSV table&lt;/li&gt;
&lt;li&gt;  writes a short &lt;code&gt;summary.txt&lt;/code&gt; dashboard&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example report generation:&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;report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
# SIKKI Market Report
## Search Query
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
## Products
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
## Gemini Analysis
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;analysis&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
Generated: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reportPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&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;You will see &lt;strong&gt;sikki-report.md&lt;/strong&gt; after running this agent in your terminal.&lt;/p&gt;

&lt;p&gt;Here is the full 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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// use environment variables from .env file&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fs&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;playwright&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GoogleGenAI&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@google/genai&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;BRIGHT_WS_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;GEMINI_API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GEMINI_API_KEY&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Missing BRIGHT_WS_ENDPOINT environment variable.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Missing GEMINI_API_KEY environment variable.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GoogleGenAI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GEMINI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;retryWithBackoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxRetries&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="nx"&gt;initialDelayMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2000&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="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;maxRetries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;attempt&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="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&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;errorMsg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;error&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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;attempt&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;maxRetries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Final attempt failed. Error: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;errorMsg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&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;delayMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialDelayMs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Attempt &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; failed: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;errorMsg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Retrying in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;delayMs&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;ms... (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;maxRetries&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delayMs&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BRIGHT_WS_ENDPOINT&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;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gaming laptop&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;searchUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://www.amazon.com/s?k=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Connecting Playwright to Bright Data...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Navigating to:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;domcontentloaded&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;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&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;querySelectorAll&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-component-type="s-search-result"]&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="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;card&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="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="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h2 span&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.a-price .a-offscreen&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.a-icon-alt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nx"&gt;innerText&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;title&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
              &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="nx"&gt;rating&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Extracted &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; products.`&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;analysisPrompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`You are an ecommerce analyst.
Analyze these products:
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
Return:
1. Cheapest Product
2. Average Market Price
3. Best Rated Product
4. Competitor Comparison
5. Final Recommendation
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sending products to Gemini for analysis (with retry logic)...&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;analysisResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;retryWithBackoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &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="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gemini-2.5-flash&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;analysisPrompt&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&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;analysis&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;analysisResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No analysis text returned.&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;report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`# SIKKI Market Report
## Search Query
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
## Products
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;
## Gemini Analysis
&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;analysis&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
Generated: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sikki-report.md&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Step 5: Export the Results&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Report generated: sikki-report.md&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Final analysis saved. Open sikki-report.md to review the result.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&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="nx"&gt;error&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;browser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="k"&gt;catch&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="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the output of Sikki market report:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7d9wcij67s3c5r26m6le.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7d9wcij67s3c5r26m6le.png" alt="sikki market report terminal image" width="800" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: 📸Teach SIKKI To Capture Evidence
&lt;/h3&gt;

&lt;p&gt;Now that SIKKI can scrape product metadata, the next job is proof.&lt;/p&gt;

&lt;p&gt;Capture evidence by taking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  one search-results summary screenshot&lt;/li&gt;
&lt;li&gt;  a product card screenshot for the top result&lt;/li&gt;
&lt;li&gt;  direct product page screenshots for the highest-ranked items&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is how:&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;searchScreenshot&lt;/span&gt; &lt;span class="o"&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;screenshotDir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;search-results.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&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;searchScreenshot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fullPage&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;summaryPath&lt;/span&gt; &lt;span class="o"&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;screenshotDir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;top-product-summary.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;cards&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;screenshot&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;summaryPath&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Focx6ovkdv6ybzofvqqxi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Focx6ovkdv6ybzofvqqxi.png" alt="generate screenshot for sikki agent image" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Capture Every Product Page
&lt;/h3&gt;

&lt;p&gt;Now we’re able to extract product information using Bright Data (Playwright) without getting blocked by antibot walls, analyze the market using Gemini, and make a report that will be stored inside our /Reports directory. SIKKI should visit each selected product URL and save the page image and it should be graceful without error loops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the fun part:&lt;/strong&gt; we don’t want only search result screenshots; we want each product page detail picked by Gemini intelligence. We will generate up to five screenshots; the first screenshot will be a summary. The remaining 4 screenshots should be: top products and individual product details pages. They will be generated based on the user search query and carefully analyzed by Gemini.&lt;/p&gt;

&lt;p&gt;Let’s update our code, but this code is too long to paste here (you should check my git repo) so I will explain what I am changing along the way.&lt;/p&gt;

&lt;p&gt;Let’s first have a look at what changes our new updated code made. This time I will search for “ryzen processor”:&lt;/p&gt;

&lt;p&gt;Key points we are making:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;normalize the URL first&lt;/li&gt;
&lt;li&gt;visit the direct product page&lt;/li&gt;
&lt;li&gt;wait briefly for the page to render&lt;/li&gt;
&lt;li&gt;save up to 4 product screenshots&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;normalized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;normalizeAmazonUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;retryWithBackoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
 &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;domcontentloaded&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120000&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt; 
 &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
 &lt;span class="mi"&gt;1500&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitForTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&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;outPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fullPage&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is our intelligent agent picking the top product from &lt;a href="https://get.brightdata.com/codewithshahan" rel="noopener noreferrer"&gt;Bright Data’s extracted data&lt;/a&gt; after a successful analysis and saving a screenshot inside the “screenshot” folder:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcmp2p6gl8db9zot6lwuk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcmp2p6gl8db9zot6lwuk.png" alt="bright data web unblocker api generated result image" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This turns SIKKI from “just data” into “evidence-backed market intelligence.”&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8: Create a CSV Export
&lt;/h3&gt;

&lt;p&gt;A CSV file is essential for downstream analysis and makes the agent practical.&lt;/p&gt;

&lt;p&gt;Write a simple export with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;title&lt;/li&gt;
&lt;li&gt;price&lt;/li&gt;
&lt;li&gt;rating&lt;/li&gt;
&lt;li&gt;normalized URL&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;csvLines&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="s2"&gt;TITLE,PRICE,RATING,URL&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;enriched&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;safe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`"&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/"/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;""&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;csvLines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;""&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,&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;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;csvPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;csvLines&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="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&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;utf8&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;The result is a readable products.csv file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqbfl837fih272nbwpets.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqbfl837fih272nbwpets.png" alt="csv generation terminal image" width="800" height="664"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 9: Generate A Dashboard Summary
&lt;/h3&gt;

&lt;p&gt;Finally, create a human-readable summary file with the important metrics.&lt;/p&gt;

&lt;p&gt;Compute:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;total products extracted&lt;/li&gt;
&lt;li&gt;cheapest offer&lt;/li&gt;
&lt;li&gt;average price&lt;/li&gt;
&lt;li&gt;best rated product&lt;/li&gt;
&lt;li&gt;top 5 product summary&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;priced&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enriched&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priceValue&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;cheapestObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;priced&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;priced&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priceValue&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priceValue&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&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;avgPriceVal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;priced&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;priced&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p&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;s&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;priceValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;priced&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&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;bestRatedObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;enriched&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ra&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“”&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“”&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;rb&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="nx"&gt;ra&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then write:&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;dashboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="o"&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;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;SIKKI&lt;/span&gt; &lt;span class="nx"&gt;MARKET&lt;/span&gt; &lt;span class="nx"&gt;DASHBOARD&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="o"&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;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Query: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Products Extracted: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;enriched&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Cheapest Product: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cheapestObj&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cheapestObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cheapestObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Average Price: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;avgPriceVal&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`$&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;avgPriceVal&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Best Rated: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bestRatedObj&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bestRatedObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bestRatedObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“\&lt;/span&gt;&lt;span class="nx"&gt;nTop&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="nx"&gt;Products&lt;/span&gt;&lt;span class="p"&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;enriched&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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;dashboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dashboardPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dashboard&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="err"&gt;“\&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets have a look at the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fktst24exuiqt1y6u1s9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fktst24exuiqt1y6u1s9p.png" alt="SIKKI summary report" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it for today. What we’ve built is a foundation, not a finished product. The interesting part is what you scale it into, and there’s a lot of room.&lt;/p&gt;

&lt;p&gt;Here is the github repo of this project (SIKKI agent): &lt;a href="https://github.com/codewithshahan/sikki-agent" rel="noopener noreferrer"&gt;https://github.com/codewithshahan/sikki-agent&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🏌️Where To Go From Here
&lt;/h2&gt;

&lt;p&gt;This article intentionally focused on the foundations. But SIKKI can become significantly more powerful. You can extend it with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  🤹Multi-site product comparison&lt;/li&gt;
&lt;li&gt;  🔎Competitor tracking&lt;/li&gt;
&lt;li&gt;  ⏰Scheduled market reports&lt;/li&gt;
&lt;li&gt;  📊Interactive dashboards&lt;/li&gt;
&lt;li&gt;  📈Price trend monitoring&lt;/li&gt;
&lt;li&gt;  🛍️Autonomous shopping assistants&lt;/li&gt;
&lt;li&gt;  🗃️Agent memory using databases&lt;/li&gt;
&lt;li&gt;  🍶Multi-agent workflows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You could even create an agent that monitors hundreds of e-commerce websites every day and sends market intelligence directly to your inbox.&lt;/p&gt;

&lt;p&gt;The possibilities become surprisingly large once you stop thinking of browser automation as scraping and start thinking about it as an intelligent system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjpyh1zw9tsav72w1pwea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjpyh1zw9tsav72w1pwea.png" alt="clean code zero to one image" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you’re serious about mastering clean code and taking your programming career to the next level, then my book is for you:&lt;/em&gt; &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;&lt;em&gt;Clean Code Zero to One&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. I am offering a 50% discount using the code “earlybird” during checkout ;only for the first 50 copies! Plus, enjoy a 30-day money-back guarantee. no risk, all reward.&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;Many developers think AI Agents begin with LLMs. I think they begin with &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;architecture&lt;/a&gt;. An agent is not just a prompt.&lt;/p&gt;

&lt;p&gt;It is not just a browser. It is not just an API.&lt;/p&gt;

&lt;p&gt;It is the coordination between observation, reasoning, and action.&lt;/p&gt;

&lt;p&gt;That is why I built SIKKI: What began as a simple browser session eventually became something much more interesting.&lt;/p&gt;

&lt;p&gt;A system capable of exploring the web, interpreting information, and transforming raw data into actionable knowledge.&lt;/p&gt;

&lt;p&gt;And I am convinced this is only the beginning.&lt;/p&gt;

&lt;p&gt;The future of browser automation isn’t scraping pages anymore. It’s building agents that can understand them.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧲 Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Why use Bright Data instead of running Playwright locally?
&lt;/h3&gt;

&lt;p&gt;Local Playwright is perfect for development and testing, but production websites often evaluate browser fingerprints, IP reputation, TLS signatures, and other anti-bot signals before serving content. &lt;a href="https://get.brightdata.com/scraping-browser-signup" rel="noopener noreferrer"&gt;Bright Data&lt;/a&gt; provides a production-ready browser infrastructure that handles these challenges behind the scenes that allows your AI agent to interact with websites more reliably while you focus on building application logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Do I still need Playwright if I’m using Bright Data?
&lt;/h3&gt;

&lt;p&gt;Yes. Bright Data and Playwright solve different problems. &lt;a href="https://playwright.dev/" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; controls the browser by clicking, typing, navigating, and extracting data, while &lt;a href="https://get.brightdata.com/scraping-browser-signup" rel="noopener noreferrer"&gt;Bright Data&lt;/a&gt; provides a cloud browser environment designed to access modern websites reliably. Together they create a much more robust browser automation stack than using either tool alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. What kinds of AI agents can I build with Bright Data?
&lt;/h3&gt;

&lt;p&gt;Once you have reliable browser access, the possibilities extend far beyond web scraping. The same architecture can power shopping assistants, market research agents, competitor monitoring systems, travel assistants, browser testing agents, lead generation workflows, news monitoring, and autonomous research assistants. By combining an LLM for reasoning, Playwright for browser control, and Bright Data for browser infrastructure, you can build AI agents capable of operating on real websites with minimal changes to the overall architecture.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>discuss</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Bypass Anti-Bot Walls for Production-Ready Apps</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Thu, 02 Jul 2026 22:40:15 +0000</pubDate>
      <link>https://dev.to/codewithshahan/how-to-bypass-anti-bot-walls-for-production-ready-apps-2kko</link>
      <guid>https://dev.to/codewithshahan/how-to-bypass-anti-bot-walls-for-production-ready-apps-2kko</guid>
      <description>&lt;p&gt;In this guide, you’ll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Why traditional scraping approaches fail against modern anti-bot systems, even when using rotating User-Agents or browser automation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How enterprise websites actually detect and block automated traffic through fingerprinting, reputation scoring, behavioral analysis, and network signals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to architect a production-ready scraping pipeline using cloud browsers, proxies, and AI agents instead of crumbling scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to build a multi-target autonomous agent called &lt;strong&gt;Vanguard&lt;/strong&gt; that can reliably collect data from modern websites at scale.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/s8tXrYsGmUY"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you’re anything like me, you’ve probably found that many web scraping tutorials stop being useful the moment you point them at a real production website.&lt;/p&gt;

&lt;p&gt;The common advice is surprisingly predictable: use &lt;em&gt;fetch()&lt;/em&gt;, automate a browser with &lt;a href="https://autify.com/blog/playwright-vs-puppeteer" rel="noopener noreferrer"&gt;Playwright or Puppeteer&lt;/a&gt;, rotate a User-Agent, maybe add a proxy, and you’re supposedly ready to scrape almost anything.&lt;/p&gt;

&lt;p&gt;That approach might work against a small personal website. It usually falls apart against companies like Amazon, Product Hunt, G2, Walmart, or CNN.&lt;/p&gt;

&lt;p&gt;Developers often assume anti-bot protection is just another HTTP check that can be bypassed by changing a few request headers. &lt;strong&gt;Modern detection systems work quite differently:&lt;/strong&gt; they review &lt;a href="https://nordlayer.com/learn/browser-security/browser-fingerprinting/" rel="noopener noreferrer"&gt;browser fingerprints&lt;/a&gt;, &lt;a href="https://www.cloudflare.com/learning/ssl/transport-layer-security-tls/" rel="noopener noreferrer"&gt;TLS characteristics&lt;/a&gt;, IP reputation, &lt;a href="https://abnormal.ai/glossary/ip-reputation" rel="noopener noreferrer"&gt;behavioral patterns&lt;/a&gt;, request timing, JavaScript execution, and dozens of other signals before deciding whether your traffic looks human.&lt;/p&gt;

&lt;p&gt;Changing your User-Agent is only one tiny piece of that puzzle.&lt;/p&gt;

&lt;p&gt;To understand why so many automation projects eventually fail, we first need to understand how modern &lt;a href="https://www.cloudflare.com/learning/ddos/glossary/web-application-firewall-waf/" rel="noopener noreferrer"&gt;Web Application Firewalls (WAFs)&lt;/a&gt; actually inspect and classify traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Corporate website’s WAF ecosystem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdx0932ari4mjwsyyjhvf.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdx0932ari4mjwsyyjhvf.webp" alt="Image Corporate website’s WAF ecosystem" width="790" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’ve built automation that kept getting blocked after a few days, you’re not alone. I’ve written far more broken scraping systems than successful ones, and every failure taught me something about how these defenses actually work.&lt;/p&gt;

&lt;p&gt;The good news is that the problem usually isn’t your code. It’s the &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;architecture&lt;/a&gt; behind it.&lt;/p&gt;

&lt;p&gt;Throughout this guide, we’ll look beyond individual requests and focus on designing systems that can survive production environments. Regardless of how you’re building a price-monitoring platform, collecting market intelligence, or &lt;a href="https://get.brightdata.com/codewithshahan-scraping-browser" rel="noopener noreferrer"&gt;fueling AI agents with fresh web data&lt;/a&gt;, the underlying principles remain the same.&lt;/p&gt;

&lt;p&gt;By the end, you’ll understand the mechanics behind modern bot detection and build a fully operational multi-target agent called Vanguard. More importantly, you’ll understand &lt;em&gt;why&lt;/em&gt; its architecture continues working long after traditional scraping scripts have failed.&lt;/p&gt;

&lt;p&gt;P*&lt;em&gt;rerequisite:&lt;/em&gt;* All examples use plain JavaScript with Node.js so we can focus on the underlying architecture instead of framework-specific details&lt;/p&gt;

&lt;h3&gt;
  
  
  I — The Illusion of the Clean&amp;nbsp;Browser
&lt;/h3&gt;

&lt;p&gt;When an automation script fails, developers immediately look for a quick proxy patch. They focus on changing their actions to make progress toward the goal (which is low impact) instead of fundamentally changing how their connection behaves so that success naturally follows (which is high impact).&lt;/p&gt;

&lt;p&gt;Typically, developers write a script, test it on their local machine, and watch it succeed. They look at a target link (e,g. &lt;a href="https://www.amazon.com/s?k=ddr5+ram+128gb," rel="noopener noreferrer"&gt;https://www.amazon.com/s?k=ddr5+ram+128gb),&lt;/a&gt; paste it into their personal browser, and see the clean results page layout load instantly without a single CAPTCHA block:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs116bt6k9fjb32zvqur2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs116bt6k9fjb32zvqur2.gif" alt="Image results page layout load instantly without a single CAPTCHA block" width="560" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They assume the target is wide open. But they are trying to build a great pipeline on a rotting foundation.&lt;/p&gt;

&lt;p&gt;Your personal browser loads that link because it brings a lifetime of clean human history. It presents a validated residential IP address, deep cookie pools, active browser session context, and a highly complex, hardware-accelerated &lt;a href="https://fingerprint.com/blog/what-is-tls-fingerprinting-transport-layer-security/" rel="noopener noreferrer"&gt;TLS cryptographic fingerprint&lt;/a&gt;. Your browser doesn’t have to “grind” or “prove” it’s human; its natural behavior inherently aligns with what the security system requires.&lt;/p&gt;

&lt;p&gt;A vanilla automated script has none of this context. To show you exactly how fast a standard production system rejects unmanaged automation, let’s look at the naive code most engineers write when they are being naive.&lt;/p&gt;

&lt;h3&gt;
  
  
  II — The Anatomy of an Immediate Rejection
&lt;/h3&gt;

&lt;p&gt;If you want to understand how anti-bot engines work, you must look at how they treat raw, unmanaged server requests.&lt;/p&gt;

&lt;p&gt;If this doesn’t make sense, let’s run through an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyqhdobvsy60kvwfov95.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyqhdobvsy60kvwfov95.webp" alt="Image how anti-bot engines work" width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you execute this, your connection is dropped. Amazon’s WAF doesn’t care that your string header says “Mozilla”. It looks at the &lt;a href="https://github.com/CarterPerez-dev/Cybersecurity-Projects/blob/main/SYNOPSES/intermediate/JA3.JA4.TLS.Fingerprinting.Tool.md" rel="noopener noreferrer"&gt;TCP handshake&lt;/a&gt; behavior, notices that your &lt;a href="https://www.tenable.com/audits/items/CIS_MS_IIS_10_v1.2.1_Level_2.audit:402c63d34c7c6a259868d26c647860af" rel="noopener noreferrer"&gt;TLS cipher suite order&lt;/a&gt; doesn’t match an actual Windows Chrome installation, maps your datacenter or unrotated local IP, and flags the machine instantly.&lt;/p&gt;

&lt;p&gt;So… security systems read what your connection does. Your headers are irreverent. Take a look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4t67t88z8yr4e3uvpztq.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4t67t88z8yr4e3uvpztq.webp" alt="Image Amazon’s WAF" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you think the real human browser has to “grind” to bypass a CAPTCHA? Does their machine have to trick the target to load a product page? To you, it may seem like a &lt;a href="https://dev.to/codewithshahan/your-first-backend-application-using-nodejs-45i"&gt;basic request&lt;/a&gt; on the surface, but the truth is that the security gateway cannot see them as anything other than authentic. The human browser has to try incredibly hard to trigger an anti-bot wall. The bare automated script has to force its way through a firewall, and &lt;a href="https://www.buzzstream.com/blog/publishers-block-ai-study/" rel="noopener noreferrer"&gt;it gets flagged every single second of it.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To some developers, a professional enterprise proxy mesh seems extreme and over-engineered. To me, it’s natural, and I don’t say that to contrast it with any other kind of architecture. I simply enjoy running production systems that do not break. When my peers tell me that I should just use a basic string rotation utility… I hold my tongue from telling them, “If your scripts are constantly breaking, why are you doing what you’re doing?”&lt;/p&gt;

&lt;p&gt;This next sentence may sound simple, &lt;em&gt;but it is baffling how many people don’t get it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you want to scrape enterprise websites reliably, the request itself is only part of the equation. Modern Web Application Firewalls (WAFs) inspect your browser fingerprint, network behavior, TLS fingerprint, session history, &lt;a href="https://www.ipqualityscore.com/ip-reputation-check" rel="noopener noreferrer"&gt;IP reputation&lt;/a&gt;, and many other signals before deciding whether you’re a legitimate user or an automated bot.&lt;/p&gt;

&lt;p&gt;To understand why most scraping scripts eventually fail, we first need to look at how modern WAFs make those decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  III — The “Fake” 200 Response&amp;nbsp;Trap
&lt;/h3&gt;

&lt;p&gt;Lets look at a real-world scenario where all corporate websites play with agentic AI developers by using &lt;em&gt;“soft block”&lt;/em&gt; tricks. I will be using &lt;a href="https://www.npmjs.com/package/axios" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="http://node.js" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; &lt;a href="https://www.npmjs.com/package/axios" rel="noopener noreferrer"&gt;axios&lt;/a&gt; library locally to send asynchronous network requests to REST endpoints, in this case our target URL endpoint is Amazon’s DDR5 ram listing page (you can use any website you like for scraping data):&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;// The Lazy Scraping Pattern (Guaranteed to fail at scale)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&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;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;naiveScrape&lt;/span&gt;&lt;span class="p"&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;targetUrl&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.amazon.com/s?k=ddr5+ram+128gb&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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="nx"&gt;targetUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="na"&gt;headers&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;User-Agent&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;Mozilla/5.0…&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Success! Status:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Data Length:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Blocked!&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="nf"&gt;naiveScrape&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this code inside your terminal right now, you might see an output that looks exactly like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmjw3nymygb22h6bggvy6.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmjw3nymygb22h6bggvy6.webp" alt="Image a 200 OK response status is often a false victory" width="800" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When scraping a gigantic popular website, a 200 OK response status is often a false victory. Large e-commerce sites use a technique called a &lt;strong&gt;Soft Block&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You look at that output. You see nearly a megabyte of data. You see no errors. You see a pristine “200 Success” code. You assume your &lt;a href="https://dev.to/codewithshahan/writing-clean-reusable-components-in-react-best-practices-2gka"&gt;code cleanly outsmarted the infrastructure&lt;/a&gt;. You are wrong.&lt;/p&gt;

&lt;p&gt;This is the cleverest trap in modern web architecture. High-tier platforms rarely throw a loud &lt;a href="https://seocom.agency/en/blog/web-errors-404-403-503-502-401-meaning-and-solutions/" rel="noopener noreferrer"&gt;403 Forbidden or 503 Error code&lt;/a&gt; to standard scripts anymore. If they give you an error code, you know instantly you’re blocked, and you immediately start changing your code.&lt;/p&gt;

&lt;p&gt;Instead, they route your connection away from the raw data asset entirely. Let’s prove exactly what is inside that 650KB+ length data string. Add these logging lines directly into your try block inside the above codeblock:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Does it contain Amazon's soft-block tag?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a-no-js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First 300 characters of the page code:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run it, you won’t see the actual marketplace data from Amazon. You will see lines of obfuscated, tracking JavaScript loops meant to run in a real browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhn4vpjuz6v942rmhz3py.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhn4vpjuz6v942rmhz3py.webp" alt="Image lines of obfuscated, tracking JavaScript loops meant to run in a real browser:" width="787" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See? Your terminal &lt;em&gt;exposed&lt;/em&gt; the trap. The real clue is the content that was returned. Instead of the product page DOM you expected, Amazon responded with its &lt;a href="https://docs.aws.amazon.com/waf/latest/developerguide/waf-captcha-and-challenge.html" rel="noopener noreferrer"&gt;verification challenge wrapper&lt;/a&gt;. In other words, AWS WAF intercepted your request and served a challenge page rather than the actual marketplace content because your script wasn’t operating as a real browser session. Because your script lacked a continuous browsing fingerprint, AWS WAF silently intercepted your connection and handed you a dead-end sandbox loop.&lt;/p&gt;

&lt;p&gt;Your script spends precious compute power downloading and trying to parse almost a megabyte of empty authentication wrappers, completely blind to the fact that it didn’t capture a single item. Automated agents cannot run the tracking scripts required to clear that page, putting your pipeline at a complete dead end.&lt;/p&gt;

&lt;p&gt;Even though a target website tricks your code with a fake success redirect or drops you completely with a &lt;em&gt;403&lt;/em&gt; Forbidden block, you are losing the exact same thing: &lt;strong&gt;access to the data layer.:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7dd447qu9wgq8i4yfn4g.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7dd447qu9wgq8i4yfn4g.webp" alt="Image target website tricks your code with a fake success redirect" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will now use CNN news website as target URL, instead of falling into Amazon’s tricky “soft block” trap, you will receive an instant block since CNN use &lt;strong&gt;Cloudflare&lt;/strong&gt;; a service that will instantly reject your vanilla Axios request with a hard HTTP &lt;em&gt;&lt;strong&gt;403 Forbidden&lt;/strong&gt;&lt;/em&gt; error code and terminate your script. Have a look:&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;axios&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;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;naiveScrape&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// Switching to a Cloudflare-protected target for a clean firewall error&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;targetUrl&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.cnn.com/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Initiating naive data extraction request…&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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="nx"&gt;targetUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="na"&gt;headers&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;User-Agent&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;Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Success! Data Length:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;❌ Request Crushed by Anti-Bot Wall.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// This will capture and print the hard 403 error code&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Status Code: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Status Text: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusText&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Reason: Cloudflare WAF rejected the vanilla Axios
handshake.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error Message:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;naiveScrape&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;Here is the result inside the terminal:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jkbwwayonfnvts3vwn0.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jkbwwayonfnvts3vwn0.webp" alt="Image vanilla Axios request with a hard HTTP 403 Forbidden error" width="800" height="779"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A 403 Forbidden error is universally recognized by developers as a &lt;a href="https://brightdata.com/blog/leadership/web-unlocker-site-unblocking-capabilities" rel="noopener noreferrer"&gt;&lt;strong&gt;hard security rejection&lt;/strong&gt;.&lt;/a&gt; It removes all ambiguity. The errors will be the same for &lt;a href="http://g2.com" rel="noopener noreferrer"&gt;g2.com&lt;/a&gt; or any other protected sites, and your automated agents cannot run that script, so your code is completely stuck at a dead end.&lt;/p&gt;

&lt;h3&gt;
  
  
  IV — Moving to an Automated Gateway
&lt;/h3&gt;

&lt;p&gt;I realized I couldn’t spend my life engineering custom solutions for every single browser fingerprint update, JS challenge modification, or proxy rotation algorithm. It’s an endless game of whack-a-mole. I needed a production-ready infrastructure that handled the network-level deception for me so I could focus purely on writing data logic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzpg6n8z7atdujazqg29y.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzpg6n8z7atdujazqg29y.webp" alt="Image of focus purely on writing data logic" width="799" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is why I migrated this workflow to &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;Bright Data’s Web Unlocker&lt;/a&gt;. It treats the entire bypass pipeline as a simple managed endpoint. It acts as an abstraction layer that intercepts your raw request, automatically executes the necessary TLS handshakes, decrypts hidden challenges, mimics human behavior, and pipes back the clean HTML data.&lt;/p&gt;

&lt;p&gt;Here is exactly how to set this up and test it without turning your local computer into a messy testing ground.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Account Activation and Token Generation
&lt;/h4&gt;

&lt;p&gt;First, you need access to the proxy cluster infrastructure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Signup/login to the dashboard account on &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;Bright Data Web Unlocker&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the main dashboard sidebar, navigate to &lt;strong&gt;Web Access&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz03cys8i0fnf3w70p8x9.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz03cys8i0fnf3w70p8x9.webp" alt="Image Bright Data Web Unlocker" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3. Select &lt;strong&gt;Web Unlocker API&lt;/strong&gt; and press continue. This is the specialized cluster that houses the machine-learning-driven browser emulation layer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feo51m42euywbbirkgugg.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feo51m42euywbbirkgugg.webp" alt="Image Bright Data Web Unlocker emulation layer" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4. Name your routing zone (default is: web_unlocker1), activate it, and generate an API Token by clicking into the “API key” box.&lt;/p&gt;

&lt;p&gt;5. Allow Your Server IP: Before sending requests, there’s one important configuration step that’s easy to miss.&lt;/p&gt;

&lt;p&gt;Open your Web Unlocker zone settings, go to the configuration tab, then security settings, and finally check &lt;strong&gt;Allowed IPs&lt;/strong&gt;. Make sure to add your current IPs in the allowlist. Go to “Configuration, then “Security Settings”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fysorralazf07ts9r70ig.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fysorralazf07ts9r70ig.webp" alt="Image Bright Data Web Unlocker zone setting" width="693" height="652"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is “Add allowed IP” box. Paste your current IP from your machine or check “recent IPs allowlist”:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqhmnss2z48rtlsddtvs.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqhmnss2z48rtlsddtvs.webp" alt="Image Bright Data Web Unlocker zone" width="617" height="610"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without this step, your API key may be valid and your zone may be configured correctly, but your requests can still fail because &lt;a href="https://brightdata.com/blog/proxy-101/proxy-error-codes" rel="noopener noreferrer"&gt;Bright Data rejects connections from unauthorized IP addresses&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9skyq67e13y6ycqsmjg4.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9skyq67e13y6ycqsmjg4.webp" alt="Image Bright Data Web Unlocker Add allowed IP" width="733" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once your IP has been added and the changes have propagated, you’re ready to send your first request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Step 2: Testing Inside the Native &lt;a href="https://get.brightdata.com/scraping-browser-signup" rel="noopener noreferrer"&gt;Bright Data Playground&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Before you deploy a single line of application code to your servers, you can visually verify that the unlocking layer works by using their &lt;a href="https://get.brightdata.com/browser-api" rel="noopener noreferrer"&gt;built-in Playground&lt;/a&gt;. It allows you to run requests directly from the cloud console to check how targets respond.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqinfwokm6sr8cqck1dkb.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqinfwokm6sr8cqck1dkb.webp" alt="Image Bright Data Native Playground" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Paste your target address directly into the &lt;strong&gt;Target URL&lt;/strong&gt; field. For example: &lt;a href="https://www.amazon.com/s?k=ddr5+ram+128gb" rel="noopener noreferrer"&gt;https://www.amazon.com/s?k=ddr5+ram+128gb&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep the configuration to &lt;strong&gt;API&lt;/strong&gt; mode and device type to &lt;strong&gt;desktop.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hit the blue &lt;strong&gt;Run Request&lt;/strong&gt; button:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The interface will display a green &lt;a href="https://dev.to/codewithshahan/your-first-backend-application-using-nodejs-45i"&gt;&lt;em&gt;RESPONSE 200&lt;/em&gt;&lt;/a&gt; success state. If you look at the bottom visual block, you’ll see a rendering preview of the exact Amazon product directory list. You’ll also find the pure market tables and real product tags by managing to bypass the &lt;em&gt;security wall&lt;/em&gt; without any problems.&lt;/p&gt;

&lt;p&gt;It is a 3-in-1 tool that manages IP rotation, dynamic browser fingerprinting, and CAPTCHA solving automatically. &lt;a href="https://get.brightdata.com/bypass-antibot-walls" rel="noopener noreferrer"&gt;The API bypasses the anti-bot wall&lt;/a&gt; and returns the clean HTML source code to the software in a single response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note on verification:&lt;/strong&gt; If you download that specific raw response file from the playground UI, your computer will automatically open it up inside a local web browser, rendering it visually. If you want to see the actual raw data your backend will process, simply open that downloaded file with a basic text editor like VS Code. You will find thousands of lines of pristine, uninhibited DOM structural code strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  V — Building LaunchRadar Agent
&lt;/h3&gt;

&lt;p&gt;If you are trying to feed live web data into an LLM using basic Axios configurations or unmanaged connection structures, you are forcing your AI agent to ride a bicycle with flat tires. Modern security layers look for advanced browser behaviors and &lt;a href="https://www.tencentcloud.com/document/product/1145/54154" rel="noopener noreferrer"&gt;TLS cipher sequences&lt;/a&gt;. If you try to manually concatenate your configuration parameters as raw text blocks, a single trailing comma will break strict backend string parsing, throwing a frustrating 400 Bad Request or an empty payload block.&lt;/p&gt;

&lt;p&gt;Therefore, we need to install Bright Data’s official SDK in our project. With this, we completely eliminate Axios-style network proxy bugs and let Bright Data handle them.&lt;/p&gt;

&lt;p&gt;Lets go trough the code blocks step by step to build our first AI agent using Bright Data. We are going to assemble a product hunt’s trend intelligence agent called LaunchRadar. Its target is specific: it bypasses the tracking walls of &lt;a href="https://www.producthunt.com/" rel="noopener noreferrer"&gt;Product Hunt&lt;/a&gt;, ingests the real-time tech product feeds, and structures raw document strings into clean text data arrays ready to feed straight into an LLM context window.&lt;/p&gt;

&lt;h4&gt;
  
  
  Setup LaunchRadar Project from&amp;nbsp;Scratch
&lt;/h4&gt;

&lt;p&gt;To ensure your runtime application environment maps dependencies cleanly, we will completely drop out of folders controlled by cloud backup networks (like Microsoft OneDrive or iCloud) that lock active file permissions and disrupt local script loops.&lt;/p&gt;

&lt;p&gt;Open your terminal window (Terminal app on macOS, or your preferred shell) and run these clean setup commands sequentially to construct an isolated project workspace from scratch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Move directly to your local User Home root path to avoid file syncing errors&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~

&lt;span class="c"&gt;# 2. Provision a dedicated application folder&lt;/span&gt;
&lt;span class="nb"&gt;mkdir &lt;/span&gt;LaunchRadar

&lt;span class="c"&gt;# 3. Enter your newly initialized project workspace&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;LaunchRadar

&lt;span class="c"&gt;# 4. Initialize an isolated local package architecture&lt;/span&gt;
npm init &lt;span class="nt"&gt;-y&lt;/span&gt; 

&lt;span class="c"&gt;# 5. Tell the Node.js runtime to process modern ES Module imports natively&lt;/span&gt;
npm pkg &lt;span class="nb"&gt;set type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now install the official bright data SDK locally using node.js:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @brightdata/sdk&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, create a fresh file named index.js inside your application directory workspace and paste this exact production script to scrap raw HTML data from Product Hunt:&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="cm"&gt;/**
 * Project: LaunchRadar
 * Core Stack: Node.js + Official Bright Data JavaScript SDK
 */&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bdclient&lt;/span&gt; &lt;span class="p"&gt;}&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;@brightdata/sdk&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;BRIGHTDATA_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRIGHTDATA_API_KEY&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deployLaunchRadar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Targeting Product Hunt's active daily launch asset path&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;targetUrl&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.producthunt.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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤖 [LaunchRadar]: Initializing autonomous target ingestion loop...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Initialize the client gateway via the native constructor&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;bdclient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BRIGHTDATA_KEY&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤖 [LaunchRadar]: Tunneling through Web Unlocker cluster...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Execute the single-step browser-emulated extraction natively&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;htmlResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrapeUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;zone&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_unlocker1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;raw&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// Streams the target webpage as a raw HTML text string&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;=================== PIPELINE SUCCESS ===================&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`🤖 [LaunchRadar]: Ingestion complete. Streamed: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;htmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;========================================================&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// This will print true-proving your paid credit bypassed the security loop&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataIsValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;htmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Product Hunt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`🤖 [LaunchRadar]: Target Data Authenticated: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dataIsValid&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Gracefully disconnect active execution sockets&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;❌ [LaunchRadar Fatal]: Pipeline exception encountered.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Reason: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;deployLaunchRadar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;If you run that code inside your terminal window, you will see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsty3t4yzf8bbozdqdt5t.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsty3t4yzf8bbozdqdt5t.webp" alt="Image LaunchRadar terminal output&amp;nbsp;image" width="502" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You extracted nearly a ~megabyte of raw HTML data. Now you understand how we can collect raw HTML data, it’s time to build our final agent application: Vanguard Agent. It interfaces directly with Bright Data’s official JavaScript SDK, targets the verified backend data pipeline endpoint natively, and bypasses the front-end rendering layer completely to return beautifully structured insights straight to your terminal window.&lt;/p&gt;

&lt;h3&gt;
  
  
  VI — Building Vanguard&amp;nbsp;Agent
&lt;/h3&gt;

&lt;p&gt;Now that Web Unlocker is handling browser fingerprinting, JavaScript challenges, TLS negotiation, and request routing behind the scenes, we can focus on the part that actually creates value: extracting useful information.&lt;/p&gt;

&lt;p&gt;Now let’s build &lt;strong&gt;Vanguard Agent.&lt;/strong&gt; It will work as a lightweight agent that searches live CNN articles, extracts relevant headlines, and automatically generates a structured Markdown report.&lt;/p&gt;

&lt;p&gt;Instead of supporting multiple unrelated websites with different search endpoints and DOM structures, we’ll focus on a single production-quality example. The same architecture can later be extended to other targets by swapping the parser while keeping the networking layer exactly the same.&lt;/p&gt;

&lt;p&gt;First, install Cheerio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;cheerio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, trigger the Bright Data SDK request with the following:&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;htmlResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrapeUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="na"&gt;zone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;web_unlocker1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;raw&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;us&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;dataFormat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html&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;&lt;em&gt;dataFormat: “html”&lt;/em&gt; is the correct SDK option for returning rendered HTML. Browser emulation is already handled internally by Web Unlocker, so no additional rendering flag is required.&lt;/p&gt;

&lt;p&gt;Next, I will point the application directly at CNN’s search endpoint. This produces reproducible search results while keeping the extraction logic straightforward.&lt;/p&gt;

&lt;p&gt;After that, the HTML has been retrieved by Bright Data; Cheerio loads the document and extracts article links.&lt;/p&gt;

&lt;p&gt;Once the extraction finishes, Vanguard writes the collected results into a Markdown report that can be consumed by downstream AI agents, summarization pipelines, or analytics workflows. I will explain more clearly inside the code blocks one by one.&lt;/p&gt;

&lt;p&gt;Here is the full source code of our agent to test on your local machine:&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="cm"&gt;/**
* Project: Vanguard Agent
* Function: Autonomous CNN Trend &amp;amp; Headline Generator
* Core Stack: Node.js (ESM) + Official Bright Data JavaScript SDK + Cheerio
*
* IMPORTANT: CNN's own robots.txt disallows /search (Disallow: /search),
* so Bright Data's Web Unlocker refuses it in immediate-access mode -
* that's not a bug, it's the site opting out of that specific path for
* compliant bots. Instead, this hits CNN's own News Sitemap
* (https://www.cnn.com/sitemap/news.xml), which robots.txt explicitly
* lists as a Sitemap: entry - meaning it's meant to be fetched by bots.
* It contains real headline titles and real publish timestamps for the
* last ~48 hours of coverage across every section, which is arguably a
* better fit for "trend monitoring" than a search page anyway.
*/&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;fs&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;fs&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;readline&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;readline&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;cheerio&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;cheerio&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;bdclient&lt;/span&gt; &lt;span class="p"&gt;}&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;@brightdata/sdk&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;REPORT_FILE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vanguard_trend_report.md&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;CNN_NEWS_SITEMAP&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.cnn.com/sitemap/news.xml&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Key comes ONLY from the environment - no hardcoded fallback, ever.&lt;/span&gt;
&lt;span class="c1"&gt;// If a real key has been pasted into a file, a chat, or a log at any&lt;/span&gt;
&lt;span class="c1"&gt;// point, treat it as compromised and rotate it in your Bright Data&lt;/span&gt;
&lt;span class="c1"&gt;// dashboard immediately, even after removing it from the code.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BRIGHTDATA_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRIGHTDATA_API_KEY&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;BRIGHTDATA_KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;❌ [Vanguard Config Error] BRIGHTDATA_API_KEY is not set.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;   Run it like this instead:&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;   PowerShell:   $env:BRIGHTDATA_API_KEY=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;your_actual_key&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;; node vanguard.mjs&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;   cmd.exe:      set BRIGHTDATA_API_KEY=your_actual_key &amp;amp;&amp;amp; node vanguard.mjs&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;   macOS/Linux:  BRIGHTDATA_API_KEY=your_actual_key node vanguard.mjs&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// CNN article URLs follow /YYYY/MM/DD/category/slug - used here purely to&lt;/span&gt;
&lt;span class="c1"&gt;// derive a topic category for the breakdown, not for date (the sitemap&lt;/span&gt;
&lt;span class="c1"&gt;// gives us a real publish timestamp directly).&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CNN_ARTICLE_PATTERN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;\/(\d{4})\/(\d{2})\/(\d{2})\/([&lt;/span&gt;&lt;span class="sr"&gt;a-z0-9-&lt;/span&gt;&lt;span class="se"&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;/i&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;printDashboardHeader&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;39m%s&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&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; ┌────────────────────────────────────────────────────────┐&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;39m%s&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&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; │   VANGUARD INTELLIGENCE SERVICE // CNN TREND ENGINE     │&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;39m%s&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&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; └────────────────────────────────────────────────────────┘&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promptUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryMessage&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;interfaceInstance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;readline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createInterface&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&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="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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;interfaceInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queryMessage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputAnswer&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;interfaceInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputAnswer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;escapeRegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&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;.*+?^${}()|[&lt;/span&gt;&lt;span class="se"&gt;\]\\]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;$&amp;amp;&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;categoryFromUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&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;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;pathname&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;dated&lt;/span&gt; &lt;span class="o"&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;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CNN_ARTICLE_PATTERN&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;dated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/-/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// Some CNN URLs skip the date prefix entirely (e.g. video pages&lt;/span&gt;
        &lt;span class="c1"&gt;// like /politics/video/slug). Fall back to the first path segment&lt;/span&gt;
        &lt;span class="c1"&gt;// instead of dumping everything into "uncategorized".&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;segment&lt;/span&gt; &lt;span class="o"&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;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;segment&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;segment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/-/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &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;uncategorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uncategorized&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;deployVanguardService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;printDashboardHeader&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;244m%s&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&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="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; [CONFIGURE INTELLIGENCE FILTER]&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;searchQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;promptUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;🔍 Enter a keyword to filter recent CNN headlines (e.g., startup, election, climate): &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;searchQuery&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;❌ [Vanguard Error] Input token context empty. Pipeline aborted.&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;printDashboardHeader&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\n\x1b[38;5;214m🤖 [Vanguard]: Connecting to proxy fabric for target: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;CNN_NEWS_SITEMAP&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\x1b[0m`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤖 [Vanguard]: Initializing automated browser emulation...&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;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;bdclient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;BRIGHTDATA_KEY&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// dataFormat: 'html' returns the raw response body as-is, which&lt;/span&gt;
        &lt;span class="c1"&gt;// works fine for XML too - we just parse it with cheerio's XML&lt;/span&gt;
        &lt;span class="c1"&gt;// mode below instead of treating it as an HTML page.&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;xmlResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrapeUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CNN_NEWS_SITEMAP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;zone&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_unlocker1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;dataFormat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;country&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;us&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\x1b[38;5;46m🤖 [Vanguard]: Data stream ingestion complete. Length: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;xmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes.\x1b[0m`&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;xmlResponse&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;xmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&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;preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;xmlResponse&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;xmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&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;(empty response)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;                &lt;span class="s2"&gt;`Target returned only &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;xmlResponse&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;xmlResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes - this is too small to be `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`a real sitemap. Raw response below:\n\n&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n\n`&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`Checklist:\n`&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`  1. Confirm BRIGHTDATA_API_KEY is a valid, active key.\n`&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`  2. Confirm 'web_unlocker1' matches an active Web Unlocker zone name in your `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`Bright Data dashboard - zone names are account-specific.\n`&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`  3. If the text above mentions a block/captcha, retry in a moment or try a `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;                &lt;span class="s2"&gt;`different 'country' value.`&lt;/span&gt;            &lt;span class="p"&gt;);&lt;/span&gt;        &lt;span class="p"&gt;}&lt;/span&gt;        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤖 [Vanguard]: Processing resilient extraction analytics...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        &lt;span class="c1"&gt;// xmlMode: true keeps namespaced tags (e.g. news:title) intact        // instead of cheerio's default HTML-parsing/lowercasing behavior.&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cheerio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;xmlResponse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;xmlMode&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;insights&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
        &lt;span class="nf"&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;url&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;el&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;loc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trim&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;news&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;:title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trim&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;pubDateRaw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;news&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;:publication_date&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lastmod&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;trim&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;loc&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;title&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="c1"&gt;// skip entries without a real headline (e.g. galleries/video-only)&lt;/span&gt;
            &lt;span class="nx"&gt;insights&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&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="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pubDateRaw&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;pubDateRaw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&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;unknown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;categoryFromUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="na"&gt;postUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loc&lt;/span&gt;
            &lt;span class="p"&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;uniqueRawInsights&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;insights&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;])).&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="c1"&gt;// Sort newest first using the sitemap's own publish timestamp.        uniqueRawInsights.sort((a, b) =&amp;gt; (a.date &amp;lt; b.date ? 1 : a.date &amp;gt; b.date ? -1 : 0));        // Whole-word match, not substring - plain .includes() would match        // "war" inside "Warner" or "warrant", which are false positives        // for a search on "war". \b enforces a real word boundary.        const keywordPattern = new RegExp(`\\b${escapeRegExp(searchQuery)}\\b`, 'i');        let filteredInsights = uniqueRawInsights.filter(item =&amp;gt; keywordPattern.test(item.title));        // Phase 2: fallback to the newest overall headlines if no direct match        let isFallbackMode = false;        if (filteredInsights.length === 0) {            filteredInsights = uniqueRawInsights;            isFallbackMode = true;        }        const uniqueInsights = filteredInsights.slice(0, 10);        if (uniqueInsights.length === 0) {            throw new Error('Zero real headline entries isolated inside the sitemap buffer.');        }        const categoryCounts = uniqueRawInsights.reduce((acc, item) =&amp;gt; {            acc[item.category] = (acc[item.category] || 0) + 1;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;acc&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;topCategories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;categoryCounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;51m┌────────────────────────────────────────────────────────────────────────┐&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`│ ► VANGUARD INTELLIGENCE STREAM // CNN // '&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;searchQuery&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;76&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;│&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;└────────────────────────────────────────────────────────────────────────┘&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isFallbackMode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\x1b[33m ⚠️ [Notice] No direct matches for '&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;searchQuery&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'. Showing newest CNN headlines instead.\x1b[0m\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;uniqueInsights&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` \x1b[38;5;46m[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;]\x1b[0m \x1b[1m&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;\x1b[0m`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`     ├─ Category : &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`     ├─ Date     : &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`     └─ Link     : \x1b[38;5;39m\x1b[4m&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\x1b[0m\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[38;5;51m└────────────────────────────────────────────────────────────────────────┘&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;x1b[0m&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s1"&gt;x1b[38;5;244m📊 Top categories in this result set:&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s1"&gt;x1b[0m&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;topCategories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(([&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`   • &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;markdownReport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s2"&gt;`# Vanguard CNN Intelligence Digest`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;`* **Search Keyword:** &lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;searchQuery&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;`* **Source:** CNN News Sitemap (robots.txt-approved)`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;`* **Data Capture Status:** &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;isFallbackMode&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Newest-headlines fallback&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;Direct keyword match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;`* **Timestamp:** &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;`\n## Top Categories`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;topCategories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(([&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`* **&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;** - &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; article(s)`&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s2"&gt;`\n## Headlines`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;uniqueInsights&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="s2"&gt;`### &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n* **Date:** &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n* **Category:** &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\n* **Link:** [&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;](&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postUrl&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="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="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;REPORT_FILE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;markdownReport&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`\x1b[38;5;46m💾 [Vanguard] System Report written successfully -&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;REPORT_FILE&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;\x1b[0m\n`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pipelineException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;❌ [Vanguard Fatal]: Operational routine aborted.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Reason: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;pipelineException&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&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="nf"&gt;deployVanguardService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, the application submits a keyword, retrieves the rendered page through Web Unlocker, extracts structured information, and generates a clean report automatically. The anti-bot layer is handled by the gateway, allowing your application to stay focused on parsing and processing data instead of maintaining browser fingerprints or bypass logic.&lt;/p&gt;

&lt;p&gt;Here is our agent functionality; you can scale it as you wish:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/s8tXrYsGmUY"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  VII — Moving Past The Anti-Bot Maintenance
&lt;/h3&gt;

&lt;p&gt;As websites continue strengthening their anti-bot systems, maintaining custom bypass logic becomes an &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;increasingly expensive engineering task&lt;/a&gt;. Every browser update, fingerprinting change, or new challenge introduces additional maintenance that doesn’t contribute to your product.&lt;/p&gt;

&lt;p&gt;Using a managed gateway such as Bright Data Web Unlocker shifts that responsibility away from your application. Instead of maintaining infrastructure that keeps requests alive, you can &lt;a href="https://similarweb.partnerlinks.io/naov3hjrep9t" rel="noopener noreferrer"&gt;focus on collecting&lt;/a&gt;, processing, and analyzing the data your users actually care about.&lt;/p&gt;

&lt;p&gt;Whenever you’re building AI agents, market intelligence platforms, monitoring systems, or large-scale data pipelines, separating anti-bot handling from your business logic results in software that is &lt;a href="https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic"&gt;easier to maintain&lt;/a&gt;, easier to scale, and more reliable over time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4a4jhzg1xsssvxff8rqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4a4jhzg1xsssvxff8rqh.png" alt="Image clean code zero to one by shahan" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you’re serious about mastering clean code and taking your programming career to the next level, then my book is for you: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;. I am offering a 50% discount using the code “earlybird” during checkout, only for the first 50 copies! Plus, enjoy a 30-day money-back guarantee. No risk, all reward.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Frequently Asked Questions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Can Web Unlocker scrape JavaScript-heavy websites?
&lt;/h4&gt;

&lt;p&gt;Yes. Web Unlocker performs browser emulation behind the scenes, allowing it to retrieve rendered HTML from websites that rely heavily on JavaScript, anti-bot challenges, or advanced fingerprinting.&lt;/p&gt;

&lt;h4&gt;
  
  
  Do I still need to rotate proxies manually?
&lt;/h4&gt;

&lt;p&gt;No. Proxy rotation, browser fingerprint management, retry logic, and challenge handling are managed by the Web Unlocker infrastructure, so your application can focus on extracting data instead of maintaining network logic.&lt;/p&gt;

&lt;h4&gt;
  
  
  Can I use this architecture for AI&amp;nbsp;agents?
&lt;/h4&gt;

&lt;p&gt;Absolutely. AI agents often require reliable access to fresh web data. By separating data collection from application logic, you can feed structured information into LLM workflows without continually rebuilding scraping infrastructure.&lt;/p&gt;

&lt;h4&gt;
  
  
  Can I extend Vanguard to other websites?
&lt;/h4&gt;

&lt;p&gt;Yes. The networking layer remains the same. In most cases, you only need to replace the target URL and update the parsing logic for the new site’s HTML structure while continuing to use the same Web Unlocker workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Related DEV Article:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic"&gt;https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>ai</category>
      <category>productivity</category>
      <category>automation</category>
    </item>
    <item>
      <title>How to Write Better Code for Agile Software Development</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Thu, 18 Jun 2026 13:25:43 +0000</pubDate>
      <link>https://dev.to/codewithshahan/the-clean-code-handbook-how-to-write-better-code-for-agile-software-development-4mca</link>
      <guid>https://dev.to/codewithshahan/the-clean-code-handbook-how-to-write-better-code-for-agile-software-development-4mca</guid>
      <description>&lt;p&gt;Building scalable software applications demands writing clean code that’s so simple that any dev can understand it.&lt;/p&gt;

&lt;p&gt;In this article, I’ll explain and demonstrate what clean code is. Then I’ll share my favorite clean code patterns for building modern Agile applications.&lt;/p&gt;

&lt;p&gt;I won’t use complex jargon. I’ll provide you with simple, clear JavaScript examples that focus on the &lt;a href="https://dev.to/codewithshahan/10-hard-truths-every-dev-must-learn-in-2025-26io"&gt;core concepts&lt;/a&gt;. Straight to the point. But this article will be a bit longer than my usual posts. So take your time wisely.&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;



&lt;ul&gt;
&lt;li&gt;The Cost of Bad Code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Clean Coder vs. Messy Coder&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;AI Can’t Save You If Your Code is a Mess 🗑️&lt;/li&gt;
&lt;li&gt;
12 Clean Code Design Patterns for Building Agile Applications ⚖️

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;🌿 Use Names That Mean Something&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;🔨 Keep Functions Laser-Focused (SRP)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;🚪 Use Comments Thoughtfully&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;⚡ Best Practices for Writing Good Comments&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;🧩 Make Your Code Readable&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;🏌️ Test Everything You Write&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;💉 Use Dependency Injection&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;📂 Clean Project Structures&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;5.&lt;/strong&gt;&lt;code&gt;tests&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🤹‍♂️ Be Consistent with Formatting&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;1️⃣ Consistent Indentation&lt;/li&gt;
&lt;li&gt;2️⃣ Meaningful Whitespace: Giving Code Room to Breathe&lt;/li&gt;
&lt;li&gt;3️⃣ Clear Separation of Logic: Modular Thinking&lt;/li&gt;
&lt;li&gt;4️⃣ Readable Error Handling&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;✋ Stop Hardcoding Values&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;🤏 Keep Functions Short&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;⛺ Follow the Boy Scout Rule&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🏟️ Follow the Open/Closed Principle&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Before: Violating the principle&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Modern Best Practices to Help You Write Clean Code: A Summary 🥷

&lt;ul&gt;
&lt;li&gt;🔎 Common Code Smells and How to Fix Them&lt;/li&gt;
&lt;li&gt;💬 Effective Commenting Practices&lt;/li&gt;
&lt;li&gt;🧼 Refactoring Techniques for Clean Code&lt;/li&gt;
&lt;li&gt;🧪 Testing and Clean Code&lt;/li&gt;
&lt;li&gt;🐛 Error Handling and Clean Code&lt;/li&gt;
&lt;li&gt;🌱 Code Reviews and Clean Code&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Automated Tools for Maintaining Clean Code ⚓

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1️⃣ Static Analysis&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How does it work?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;🚨 Before static analysis:&lt;/li&gt;
&lt;li&gt;🚑 After static analysis (using ESLint):&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2️⃣ Automated Code Formatting&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;After using Prettier:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3️⃣ Continuous Integration (CI) Testing&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How Does CI Testing Work?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;4️⃣ CI/CD pipelines&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;⚡ Continuous Integration (CI) Testing with GitHub Actions&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;How to Set Up CI Testing with GitHub Actions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
The Role of Documentation in Agile Software Development 🚣

&lt;ul&gt;
&lt;li&gt;1. 🚡 Create &lt;strong&gt;Useful Docs (Explain Why, Not Just How)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;2. ⏳ &lt;strong&gt;Keep the Docs Updated (Outdated Docs Are Worse Than No Docs)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;3. 🚆 &lt;strong&gt;Integrate Comments (Good Comments in Code Are Part of Documentation)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Conclusion 🏁&lt;/li&gt;
&lt;li&gt;Frequently Asked Questions About Clean Code 🧯&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxh3j6ccn1hc3euc3lfyl.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%2Fxh3j6ccn1hc3euc3lfyl.png" alt="Image of agile software development meme" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Agile, where change is the only constant, clean code is your armor. It makes you adaptable, swift, and, most importantly, in control.&lt;/p&gt;

&lt;p&gt;Here’s the truth: writing clean code is not optional if you want to survive in the software development industry. Fortunately, we human beings are able to master clean code with some effort and practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Cost of Bad Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdai6npb55j71sguj6kl.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%2Fwdai6npb55j71sguj6kl.png" alt="Image of cost of messy code vs clean code graph by shahan" width="500" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To explain this stack bar graph, in the initial development phase, bad code is &lt;strong&gt;slightly&lt;/strong&gt; more costly to change than clean code.&lt;/p&gt;

&lt;p&gt;But as we move into the maintenance and refactoring phases, the gap widens significantly, with bad code costing nearly twice as much as clean code.&lt;/p&gt;

&lt;p&gt;By the legacy phase, bad code reaches 100% cost; now it’s extremely expensive to update, while clean code remains more manageable at 45%.&lt;/p&gt;

&lt;p&gt;As of now, the most recent analysis on the cost of poor software quality in the U.S. is the 2023 report by the &lt;a href="https://www.it-cisq.org/2023/01/10-ways-to-reduce-technical-debt/" rel="noopener noreferrer"&gt;Consortium for Information and Software Quality (CISQ)&lt;/a&gt;. This report estimates that poor software quality cost the U.S. economy at least $2.41 trillion in 2022, with technical debt accounting for about $1.52 trillion of this amount.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fry9vmob4xkrfhafedzlf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fry9vmob4xkrfhafedzlf.png" alt="Image of cisq.org critical technical debt of software engineering" width="780" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://www.it-cisq.org/the-cost-of-poor-quality-software-in-the-us-a-2022-report/" rel="noopener noreferrer"&gt;read more about that here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Recent discussions continue to highlight the significant impact of technical debt on software quality and business performance.&lt;/p&gt;

&lt;p&gt;For instance, &lt;a href="https://vfunction.com/blog/how-to-manage-technical-debt" rel="noopener noreferrer"&gt;a 2024 survey&lt;/a&gt; indicated that for more than 50% of companies, technical debt accounts for greater than a quarter of their total IT budget. And this can really hinder innovation if it’s not addressed.&lt;/p&gt;

&lt;p&gt;As you can see, there’s no doubt that bad code is a costly problem in software development.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Clean Coder vs. Messy Coder&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s a graph that shows the journey of &lt;strong&gt;two types&lt;/strong&gt; of coders:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc6ubf77uwipf4gtucw8q.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%2Fc6ubf77uwipf4gtucw8q.png" alt="Image of clean code vs bad code graph chart" width="604" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;⚠️ The Messy Coder (Red line):&lt;/strong&gt; Starts fast but crashes hard. The more lines they write, the more trouble they make.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;⚡ The Clean Coder (Blue line):&lt;/strong&gt; Starts slow but stays consistent. Growth doesn’t stop; it expands.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🫵 Now, you decide which line you want to follow.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI Can’t Save You If Your Code is a Mess 🗑️
&lt;/h2&gt;

&lt;p&gt;When you get stuck writing code, you might turn to AI. But let me tell you something: AI can’t save you if your code is a mess.&lt;/p&gt;

&lt;p&gt;It’s like building a house on sand. Sure, it stands for a while, but one strong gust of wind or big wave, and it collapses.&lt;/p&gt;

&lt;p&gt;Remember: AI is just a tool. If you don’t know how to write clean, scalable applications, you're setting yourself up for failure.&lt;/p&gt;

&lt;p&gt;If you can’t &lt;a href="https://dev.to/codewithshahan/writing-clean-reusable-components-in-react-best-practices-2gka"&gt;maintain the code you write&lt;/a&gt;, you’re in trouble.&lt;/p&gt;

&lt;p&gt;I’ve seen it over and over again: developers who know five programming languages. They can build apps, websites, software. They know algorithms and data structures like the back of their hand.&lt;/p&gt;

&lt;p&gt;But when faced with a large project or someone else’s messy code, they crumble.&lt;/p&gt;

&lt;p&gt;They’re like an aerospace engineer who designs and builds their own planes but doesn’t know how to fly them. They crash into their own code.&lt;/p&gt;

&lt;p&gt;This was me...once upon a time. I’d write thousands of lines of code, only to realize I couldn’t even understand what I wrote last week. It was chaos for me.&lt;/p&gt;

&lt;p&gt;But then it hit me;every developer struggles with this. It wasn't about how much I knew. It was about how I organized and structured what I knew. In other words, it was about knowing the art of programming itself.&lt;/p&gt;

&lt;p&gt;I decided to escape this trap. After five months of intense work; four to five hours a day writing, designing, and researching. I created something I wish I had when I started programming. A book that’s a complete beginner’s guide: &lt;strong&gt;&lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnvqegyfwy8zj31qnbbfo.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%2Fnvqegyfwy8zj31qnbbfo.png" alt="cover image of clean code zero to one: from messy code to masterpiece" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to learn more about the book, I give you all the details at the end of this tutorial. So read on to learn more about writing clean code.&lt;/p&gt;

&lt;h2&gt;
  
  
  12 Clean Code Design Patterns for Building Agile Applications ⚖️
&lt;/h2&gt;

&lt;p&gt;If your code doesn’t follow these modern clean code design patterns, you could be creating a ticking time bomb. These patterns are your tools. Master them and enjoy the success of your projects. Let me show you one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🌿 Use Names That Mean Something&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Naming your variables or functions b or x is not helpful. Call them what they are so they’re easier to understand. Here’s an example of both a bad and good variable name:&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;// Weak and vague&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Strong and clear&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numberOfUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;People who write unclear names don’t want to own their mistakes. Don’t be that person.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1httisvhttuys6kef9u.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%2Fz1httisvhttuys6kef9u.png" alt="Comic showing a bad vs a good variable name, by Shahan" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🔨 Keep Functions Laser-Focused (SRP)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A function should do &lt;strong&gt;one thing&lt;/strong&gt;—and do it perfectly. This is called the Single Responsibility Principle ( &lt;strong&gt;SRP&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Good code is like a hammer. It hits one nail, not ten. For example, if you are hiring someone to do everything in your company—finance, sales, marketing, janitorial work, and so on;they'll likely fail miserably because they can’t focus one one thing. The same goes for your classes in code.&lt;/p&gt;

&lt;p&gt;🚧 When a class or function does more than one thing, it becomes a tangled mess. Debugging it feels like solving a puzzle upside down. If your class handles both user input and database operations, for example, it’s not multitasking—it's madness. Break it up. One method, one job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔥 My Rule:&lt;/strong&gt; Your code works for you. Keep it sharp, focused, and controllable, or it’s going to control you. Here is how to make that happen:&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;// Clean: One job, one focus&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;logTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`User: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Total: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Messy: Trying to do EVERYTHING&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateAndLogTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`User: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Total: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🪧 When you mix tasks, you mix in confusion. As simple as that.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🚪 Use Comments Thoughtfully&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There is a great saying among professional developers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“ Code speaks for itself. ”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You don’t explain what a door does every time someone walks into a room, do you? Your code should work the same way.&lt;/p&gt;

&lt;p&gt;Comments aren’t bad, but if your code can’t stand on its own, then you may have a problem.&lt;/p&gt;

&lt;p&gt;🪧 A good comment should tell “why” not “how or what”. If a developer doesn’t understand “how” something works, then they likely aren’t going to understand “why” either.&lt;/p&gt;

&lt;p&gt;Here are some short examples of good comments vs bad comments. I’ll also show you a real-world project for writing clean comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: Bad Comment 👎&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="c1"&gt;// Multiply the price by the quantity to calculate the total&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a &lt;strong&gt;bad comment&lt;/strong&gt; because it simply repeats what the code already says. The code &lt;code&gt;price * quantity&lt;/code&gt; is self-explanatory, so the comment doesn’t add anything useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Comment: 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the code is clear and simple, &lt;strong&gt;you don’t need a comment.&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvzt1fx5miz7jfw09bled.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%2Fvzt1fx5miz7jfw09bled.png" alt="Image illustrating unnecessary comment vs " width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Bad Comment 👎&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="c1"&gt;// Check if the user logged in&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isUserLoggedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&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 comment is bad because it doesn’t explain why the &lt;code&gt;isUserLoggin()&lt;/code&gt; exists. It just explains what happens. But we already know that this is an auth function. This comment is a waste of time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Example 👍&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="c1"&gt;// The user is authenticated before accessing protected resources&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isUserLoggedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&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 is a &lt;strong&gt;good comment&lt;/strong&gt; because it explains &lt;strong&gt;why&lt;/strong&gt; the code exists. It tells us that the function checks if the user is authenticated before allowing access to sensitive parts of the app. It focuses on the bigger picture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnwh4ssmfb8jgctboyej.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%2Fpnwh4ssmfb8jgctboyej.png" alt="Before: " width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;⚡ Best Practices for Writing Good Comments&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Explain the “Why,” not the “What”:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Write comments to explain the purpose or context of the code, not what the code is doing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Avoid obvious comments:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t write comments for things the code already makes clear.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Keep them short and precise:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Write concise comments that are easy to read and directly explain the purpose.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Update comments regularly:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Outdated comments can mislead developers, so always update them when the code changes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real-World Example (with Good Comments) 🛒&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s implement these practices into a real-world project: a large e-commerce application. One function calculates shipping costs based on the order details. Here's the full code, I will explain each comment 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="c1"&gt;// Shipping rules:&lt;/span&gt;
&lt;span class="c1"&gt;// - Free shipping for orders over $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Standard shipping ($10) for orders below $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Additional $5 for international orders&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if the order qualifies for free shipping&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Free shipping&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;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Standard shipping cost&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Add additional cost for international orders&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;shippingCost&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="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;shippingCost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;order1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;order2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isInternational&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: 0&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the start of the function, we include a comment explaining the rules for shipping costs. This gives the reader an overview of the logic without needing to read the full 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="c1"&gt;// Shipping rules:&lt;/span&gt;
&lt;span class="c1"&gt;// - Free shipping for orders over $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Standard shipping ($10) for orders below $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Additional $5 for international orders&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, the first condition checks if the order total is greater than or equal to $100. A comment here clarifies &lt;strong&gt;why&lt;/strong&gt; free shipping is applied.&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;// Check if the order qualifies for free shipping&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Free shipping&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second condition applies an additional charge for international shipping. The comment explains &lt;strong&gt;why&lt;/strong&gt; the extra cost is added.&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;// Add additional cost for international orders&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;shippingCost&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why are these comments good?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you’re working in a team of 20 developers. Someone reads the &lt;code&gt;calculateShipping&lt;/code&gt; function six months later. Without these comments, they might waste time guessing why international orders have an extra fee. Good comments clarify the why and save hours of frustration.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🧩 Make Your Code Readable&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If someone reading your code feels like they’re solving a riddle, you’ve already become a troublemaker. Here is the proof:&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;// Clean: Reads like a story&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;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please log in.&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="c1"&gt;// Messy: Feels like chaos&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;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please log in.&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 your code is messy and hard to read, it will confuse others;and even yourself later! Think about coming back to your own &lt;a href="https://youtu.be/_s71XCQ7BbQ" rel="noopener noreferrer"&gt;code after six months&lt;/a&gt; and feeling like you’re reading a foreign language. Readable code saves time, reduces bugs, and makes everyone’s life easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🍵 Why is Readability Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;For yourself:&lt;/strong&gt; When you revisit your code after weeks or months, clean code helps you pick up where you left off without wasting time figuring out what you did.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;For your team:&lt;/strong&gt; If someone else reads your code, they shouldn’t have to solve a puzzle. Clean code makes teamwork smoother and prevents miscommunication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fewer bugs:&lt;/strong&gt; Clear code is easier to debug because you can quickly spot mistakes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🧙‍♂️ How to Write Readable Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s build a simple program to manage books in a library. We’ll make it clean and readable and then I will break down this code 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="c1"&gt;// A class to represent a book&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;borrow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You borrowed "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;".`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Sorry, "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;" is not available.`&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="nf"&gt;returnBook&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You returned "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;".`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// A function to display available books&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;books&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Available books:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;books&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;book&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`- &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; by &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&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;// Example usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The Clean Coder&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;Robert Martin&lt;/span&gt;&lt;span class="dl"&gt;"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You Don’t Know JS&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;Kyle Simpson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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;book3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Eloquent JavaScript&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;Marijn Haverbeke&lt;/span&gt;&lt;span class="dl"&gt;"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;library&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;book2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;book3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Show available books&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;borrow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Borrow a book&lt;/span&gt;
&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Show available books again&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;returnBook&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Return the book&lt;/span&gt;
&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Final list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We created a &lt;code&gt;Book&lt;/code&gt; class to represent each book. It has properties like &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;author&lt;/code&gt;, and &lt;code&gt;isAvailable&lt;/code&gt; to track its status.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;borrow&lt;/code&gt; method checks if the book is available. If yes, it marks it as unavailable and prints a message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;returnBook&lt;/code&gt; method makes the book available again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;displayAvailableBooks&lt;/code&gt; function loops through the library and prints only the books that are available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We create three books (&lt;code&gt;book1&lt;/code&gt;, &lt;code&gt;book2&lt;/code&gt;, &lt;code&gt;book3&lt;/code&gt;) and store them in a &lt;code&gt;library&lt;/code&gt; array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We borrow and return books, showing how the list of available books changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see, readable code is not just about style. It saves time, prevents bugs, and preserves your code as useful for years to come.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🏌️ Test Everything You Write&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you don’t take the time to write tests, you shouldn’t be surprised if your code breaks. If you do want to write tests, follow this unit testing strategy to catch problems ahead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is Unit Testing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Concretely, unit testing checks &lt;a href="https://www.geeksforgeeks.org/software-testing/unit-testing-software-testing/" rel="noopener noreferrer"&gt;individual parts of your code&lt;/a&gt; (like functions or classes) to verify that they work correctly. Just like checking each brick of your house for soundness before building the walls.&lt;/p&gt;

&lt;p&gt;Let me give you an example of how unit testing works:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Test it (Unit Test)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subtraction failed&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’s what’s going on in this code:&lt;/p&gt;

&lt;p&gt;First, we create the calculator class:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="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 &lt;code&gt;Calculator&lt;/code&gt; class has two methods: &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;subtract&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;add(a, b)&lt;/code&gt; takes two numbers and returns their sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;subtract(a, b)&lt;/code&gt; takes two numbers and returns their difference.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we set up the tests:&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;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Calculator&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’re creating an instance of the &lt;code&gt;Calculator&lt;/code&gt; class to test its methods.&lt;/p&gt;

&lt;p&gt;Then we write test cases:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subtraction failed&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;&lt;code&gt;console.assert(condition, message)&lt;/code&gt; checks if the condition is &lt;code&gt;true&lt;/code&gt;. If it’s &lt;code&gt;false&lt;/code&gt;, the message ("Addition failed" or "Subtraction failed") is displayed in the console.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;First test&lt;/strong&gt;: &lt;code&gt;calculator.add(2, 3) === 5&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calls the &lt;code&gt;add&lt;/code&gt; method with &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Checks if the result is &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Second test&lt;/strong&gt;: &lt;code&gt;calculator.subtract(5, 3) === 2&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calls the &lt;code&gt;subtract&lt;/code&gt; method with &lt;code&gt;5&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Checks if the result is &lt;code&gt;2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what happens if something breaks? It’s pretty simple to solve any issues that arise here. In this case, if the &lt;code&gt;add&lt;/code&gt; or &lt;code&gt;subtract&lt;/code&gt; method doesn’t work correctly, the test will fail. For example:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&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;ul&gt;
&lt;li&gt;&lt;p&gt;The condition &lt;code&gt;calculator.add(2, 3) === 6&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The console will display: &lt;code&gt;"Addition failed"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-World Example: Testing a Login System 👥&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s test a simple login system to see how unit testing works in a real-world scenario.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234&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="c1"&gt;// Test the Auth class&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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;et5t45#@&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login failed for valid credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&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;wrongpassword&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login succeeded for invalid credentials&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;First, create the &lt;code&gt;Auth&lt;/code&gt; class:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234&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;The &lt;code&gt;login&lt;/code&gt; method checks if the username is &lt;code&gt;"admin"&lt;/code&gt; and the password is &lt;code&gt;"1234"&lt;/code&gt;. If both match, it returns &lt;code&gt;true&lt;/code&gt; – otherwise, &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, set up the tests:&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;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an instance of the &lt;code&gt;Auth&lt;/code&gt; class. Then write the test cases:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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;1234&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login failed for valid credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&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;wrongpassword&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login succeeded for invalid credentials&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First test&lt;/strong&gt;: Checks if valid credentials (&lt;code&gt;"admin"&lt;/code&gt;, &lt;code&gt;"1234"&lt;/code&gt;) succeed. If not, &lt;code&gt;"Login failed for valid credentials"&lt;/code&gt; is displayed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Second test&lt;/strong&gt;: Checks if invalid credentials (&lt;code&gt;"user"&lt;/code&gt;, &lt;code&gt;"wrongpassword"&lt;/code&gt;) fail. If not, &lt;code&gt;"Login succeeded for invalid credentials"&lt;/code&gt; is displayed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🌱 Why testing results in clean code:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You naturally write smaller, more focused functions to make your code testable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tests verify that your code behaves as expected under different conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With tests in place, you can confidently update your code, knowing the tests will catch any mistakes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💉 Use Dependency Injection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hardcoding dependencies is like tattooing someone’s name on your forehead — it’s permanent, can be abrasive, and locks you in.&lt;/p&gt;

&lt;p&gt;So, what does Dependency Injection do? It lets you manage your code's relationships by passing dependencies as arguments. It’s flexible, adaptable, and maintainable.&lt;/p&gt;

&lt;p&gt;To demonstrate how it works, here I’m using the Nodemailer dependency for sending emails to users:&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;// Dependency: Sending emails with Nodemailer&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nodemailer&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;nodemailer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&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;transporter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nodemailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTransport&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="cm"&gt;/* config */&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;transporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMail&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;programmingwithshahan@gmail.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;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&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;⚠️ To save yourself from risk, make sure to avoid &lt;strong&gt;hardcoding&lt;/strong&gt; dependencies. Use abstraction or configuration files for secure maintenance.&lt;/p&gt;

&lt;p&gt;This is just one example. As a developer, you may use hundreds of libraries or dependencies.&lt;/p&gt;

&lt;p&gt;I’m not saying you shouldn’t rely on dependencies/libraries at all, as nowadays it is hard to avoid them. But you should be very careful before installing them in your coding projects.&lt;/p&gt;

&lt;p&gt;You should check the security, performance, quality, or functionality of an organization's software systems. Because they sometimes contain risks that can ruin your entire project.&lt;/p&gt;

&lt;p&gt;🚧 Always control your tools, don't let them control you.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;📂 Clean Project Structures&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A well-organized project is the difference between a &lt;strong&gt;trash heap&lt;/strong&gt; and a high-end &lt;strong&gt;boutique&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is how each folder should be organized:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xwyg9iqqcybz21lsgxz.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%2F9xwyg9iqqcybz21lsgxz.png" alt="Image of clean code project structure by shahan" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your codebase looks like a junk drawer, you’ve already caused trouble for your future self.&lt;/p&gt;

&lt;p&gt;Let’s go through the clean project structure you can see above to better understand it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt;&lt;code&gt;myProjet/src&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the main container for your entire application. Everything your app needs is stored inside this folder. It has subfolders to keep things tidy and managed in one place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt;&lt;code&gt;components&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is where you keep all the reusable pieces of your app. You can use these components in multiple places without building them again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt;&lt;code&gt;services&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the "brain" of your app. It handles all the work behind the scenes for both the frontend and backend. &lt;code&gt;emailService.js&lt;/code&gt;, &lt;code&gt;userService.js&lt;/code&gt; and &lt;code&gt;productService.js&lt;/code&gt; are some of the example files for your &lt;code&gt;services&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt;&lt;code&gt;utils&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This contains all the small, handy tools you need to make your application run smoothly and make your life easier. For example, &lt;code&gt;formatedate.js&lt;/code&gt;, &lt;code&gt;validateEmail.js&lt;/code&gt; and &lt;code&gt;generateId.js&lt;/code&gt; are some of the common utils files to make reusable pieces of components for your entire project.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5.&lt;/strong&gt;&lt;code&gt;tests&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Conventionally, test files are typically located &lt;strong&gt;outside&lt;/strong&gt; the &lt;code&gt;src&lt;/code&gt; folder, at the project root level. This keeps your production code (&lt;code&gt;src&lt;/code&gt;) separate from your test code (&lt;code&gt;tests&lt;/code&gt;), making it cleaner and easier to manage. Have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;myProject/
├── src/              &lt;span class="c"&gt;# Production code&lt;/span&gt;
│   ├── components/
│   ├── services/
│   └── utils/
├── tests/            &lt;span class="c"&gt;# Test files&lt;/span&gt;
│   ├── components/
│   ├── services/
│   └── utils/
├── package.json      &lt;span class="c"&gt;# Project configuration&lt;/span&gt;
└── README.md         &lt;span class="c"&gt;# Documentation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some developers may prefer creating one testing file inside the &lt;code&gt;test&lt;/code&gt; folder to test everything in one place. Unfortunately, it may feel clean at first, but as your project grows, you’ll have to find and search for specific code blocks. It’s ugly and can produce unexpected testing results. So breaking them into multiple testing files inside the &lt;code&gt;tests&lt;/code&gt; folder is highly recommended.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world example 📧&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So let me create a clean, durable project structure for you to apply in any future projects you might work on. Needless to say, clean project structure is the foundation of building a maintainable project.&lt;/p&gt;

&lt;p&gt;From our previous email sending application example, we will write a clean project structure for this app. We want to build an application that sends emails to users. Your clean project structure for this app should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v6rlc5qiplgxz1h4dps.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%2F6v6rlc5qiplgxz1h4dps.png" alt="Image of email app clean code project structure by shahan" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I packed every subfolder and file inside the &lt;code&gt;src&lt;/code&gt; folder which is the main container of our application. Inside the &lt;code&gt;src&lt;/code&gt; folder, we created &lt;code&gt;components&lt;/code&gt;, &lt;code&gt;services&lt;/code&gt;, &lt;code&gt;utiles&lt;/code&gt;. Finally, we have a manageable &lt;code&gt;test&lt;/code&gt; folder outside the &lt;code&gt;src&lt;/code&gt; folder to test each component independently. This test folder has nothing to do with our production code that is located inside the &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🤹‍♂️ Be Consistent with Formatting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Don’t write code like you’re 10 different people. Be consistent with your formatting.&lt;/p&gt;

&lt;p&gt;Use tools like &lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; or &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; to enforce a consistent style. If every file looks different, you’re creating chaos that no one wants to fix.&lt;/p&gt;

&lt;p&gt;I would say that consistency in formatting is one of the most important aspects of writing clean code.&lt;/p&gt;

&lt;p&gt;Have a look...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46zu4k5nnrkcdesgqrye.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%2F46zu4k5nnrkcdesgqrye.png" alt="Image of consistent formatting snippets from clean code zero to one book" width="800" height="960"&gt;&lt;/a&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="c1"&gt;// Always use 2 spaces for indentation&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dimensions must be positive numbers.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Add meaningful whitespace for readability&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Clear separation of logic&lt;/span&gt;
&lt;span class="k"&gt;try&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;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;Let’s examine some of the aspects of this code that make it clean:&lt;/p&gt;

&lt;h4&gt;
  
  
  1️⃣ Consistent Indentation
&lt;/h4&gt;

&lt;p&gt;Why 2 or 4 spaces? It’s clean, minimal, and universally accepted in many JavaScript style guides. It doesn’t overwhelm the eyes, and the code structure stands out clearly. When you mix inconsistent indentation (2 spaces here, 4 spaces there), you confuse people—and confused people make mistakes.&lt;/p&gt;

&lt;h4&gt;
  
  
  2️⃣ Meaningful Whitespace: Giving Code Room to Breathe
&lt;/h4&gt;

&lt;p&gt;That extra line break between the rectangle definition and the &lt;code&gt;try&lt;/code&gt; block is like a pause in a sentence—it gives the reader time to process.&lt;/p&gt;

&lt;h4&gt;
  
  
  3️⃣ Clear Separation of Logic: Modular Thinking
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&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;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;Look at how the logic is divided into clear sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, the calculation (&lt;code&gt;calculateArea&lt;/code&gt; function).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, the output (&lt;code&gt;console.log&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, error handling (&lt;code&gt;catch&lt;/code&gt; block).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each task has its own space and purpose.&lt;/p&gt;

&lt;h4&gt;
  
  
  4️⃣ Readable Error Handling
&lt;/h4&gt;

&lt;p&gt;When you throw errors or log messages, you format them cleanly. No vague or cryptic messages here. A developer seeing this will immediately know the problem.&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;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dimensions must be positive numbers.&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;&lt;strong&gt;🐦‍⬛ General tips for consistent formatting:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use 2 or 4 spaces for indentation consistently throughout your codebase. Avoid tabs to maintain uniformity across different editors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep lines to a maximum of 100-120 characters to prevent horizontal scrolling and improve readability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group related logic together and separate blocks of code with blank lines to highlight their purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, avoid over-aligning code. Instead, let indentation naturally guide the flow of logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;✋ Stop Hardcoding Values&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hardcoding values is a lazy way to code. Here is the proof:&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;// Bad: Hardcoded and rigid&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&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;maxUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;currentUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;maxUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Too many users!&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="c1"&gt;// Clean: Dynamic and flexible&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_USERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;MAX_USERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Too many users!&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;You see, changing this variable won’t surprise you in the future. You know exactly where to find it to change uncertain values.&lt;/p&gt;

&lt;p&gt;Its best to store your fixed values in the global configuration (config) file.&lt;/p&gt;

&lt;p&gt;🪧 So, avoid hardcoding values at all costs. Hardcoding is the shortcut that may drive your future self (or others) crazy.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🤏 Keep Functions Short&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If your function is longer than 20 lines, it’s probably trying to do too much &lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Short functions are sharp functions. They hit their mark every time.&lt;/p&gt;

&lt;p&gt;Long, bloated functions are messy and hard to read, but short functions are clear and focused. Here is how your large functions should break down:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;addItemToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;logTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addItemToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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;Let me explain this code so you understand why breaking down large functions is a winning strategy.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Main Function:&lt;/strong&gt;&lt;code&gt;updateCart()&lt;/code&gt; calls smaller helper functions to handle specific tasks like:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adds the item to the cart.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculates the total price.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logs the details of the transaction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, it returns the total price.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of one long block of code that tries to do everything, it delegates tasks to helper functions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Helper Function:&lt;/strong&gt;&lt;code&gt;addItemToCart()&lt;/code&gt; This function &lt;strong&gt;only&lt;/strong&gt; handles adding the item to the cart. if you need to change how items are added (for example, checking for duplicates). You could just edit this small function instead of digging through a giant block of code in &lt;code&gt;updateCart&lt;/code&gt;. That’s how you write clean code functions that’s a joy to read and easy to maintain.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What Happens If Functions Are Too Long? 💤&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s say you didn’t break down the &lt;code&gt;updateCart&lt;/code&gt; function. Here’s what it might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for &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;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&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;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Added &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&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="s2"&gt;. Total is now $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;total&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;What are the problems here?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s trying to do everything.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s hard to read, especially if it grows bigger.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If something breaks, you’ll waste time figuring out which part is the problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the choice is yours: stick with the messy all-in-one approach or practice the clean one function one job mindset.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;⛺ Follow the Boy Scout Rule&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Always leave your campsite cleaner than you found it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me break it down for you. You don’t just use something and leave it worse than before. That’s inconsiderate behavior. Real professionals leave things better than they found them.&lt;/p&gt;

&lt;p&gt;In coding terms, every time you touch the codebase, &lt;strong&gt;make it better.&lt;/strong&gt; Clean it up, refactor messy parts, and improve readability. If you don’t, you’re just piling on garbage that will eventually collapse on your head.&lt;/p&gt;

&lt;p&gt;Here is an example. Instead of improving it, we’re just adding more layers of complexity:&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;// Original code: Hard to read, poorly named variables&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// We're adding to it but not cleaning it up&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;final&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;final&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;After: it gets better every time. Here’s how a disciplined coder works — they improve as they go:&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;// Improved code: Clear names, refactored for clarity&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateSubtotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateDiscountedTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&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;subtotal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateSubtotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&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;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;discount&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, anyone can tell what’s happening at a glance. Because we’ve broken down the code into smaller, more focused functions. Thus, adding new features won’t break existing functionality. 🏕️&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🏟️ Follow the Open/Closed Principle&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This design principle suggests your code should be designed to allow extensions without changing the existing foundation.&lt;/p&gt;

&lt;p&gt;You want to add features &lt;em&gt;—&lt;/em&gt; not rip it apart every time you upgrade &lt;em&gt;.&lt;/em&gt; Modifying old code to fit new requirements is exactly like trying to rebuild your house every time you buy new furniture. It’s not sustainable.&lt;/p&gt;

&lt;p&gt;Let’s see how you can build smarter, scalable code that lets you add features without breaking everything else.&lt;/p&gt;

&lt;h4&gt;
  
  
  Before: Violating the principle
&lt;/h4&gt;

&lt;p&gt;You’ve got a class to handle payments — simple enough. At first, it just handles credit cards.&lt;/p&gt;

&lt;p&gt;But then your boss shows up and says, &lt;em&gt;“Hey, now we need PayPal support.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And because you didn’t bother learning clean code, your code looks like a spaghetti monster straight out of a legacy enterprise system from 1995. Here’s the masterpiece you’ve crafted:&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;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;creditCard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing credit card payment of $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paypal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing PayPal payment of $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="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="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unsupported payment type&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;paymentProcessor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;paymentProcessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;creditCard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;paymentProcessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paypal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alas! Every new payment type (like Apple Pay, Google Pay, and so on) requires modifying the &lt;code&gt;processPayment&lt;/code&gt; method. Needless to say, you risk breaking existing functionality while adding new features. If you had learned this principle, you might not be in this mess.&lt;/p&gt;

&lt;p&gt;Don’t worry: I’ll help you to fix this. First, we need to refactor the code. Instead of modifying the existing class, we’ll extend its functionality using &lt;a href="https://stackify.com/oop-concept-polymorphism/" rel="noopener noreferrer"&gt;polymorphism&lt;/a&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="nx"&gt;javascriptCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="c1"&gt;// Base class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;processPayment() must be implemented&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="c1"&gt;// Credit card payment&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing credit card payment of $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// PayPal payment&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing PayPal payment of $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Adding a new payment type? Just extend the class!&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplePayPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing Apple Pay payment of $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApplePayPayment&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="nx"&gt;payments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;payment&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;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, adding new payment methods doesn’t require changing the existing &lt;code&gt;PaymentProcessor&lt;/code&gt; class. You just created a new subclass. So the original code remains untouched, meaning there’s no risk of breaking existing features.&lt;/p&gt;

&lt;p&gt;Each payment type has its own class, and adding PayPal payment support, for example, doesn’t break the code. Now you can reply to your boss: &lt;em&gt;“Of course, I will add this feature in 5 minutes.”&lt;/em&gt; Your promotion is waiting for you to accept it.&lt;/p&gt;

&lt;p&gt;I share even more tips in my book &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modern Best Practices to Help You Write Clean Code: A Summary 🥷
&lt;/h2&gt;

&lt;p&gt;Now let me show you the best practices and summarise our 12 Clean Code design principles to help you write clean code for agile application development.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔎 Common Code Smells and How to Fix Them
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;💊 Duplication: If you're copying code, you’re creating more work for yourself. Extract it into a function, and do it right.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🛤️ Long methods: If your method needs a scroll bar, it's doing too much. Break it down, keep it focused.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;👑 King objects: No class should be doing everything. Simplify responsibilities, or your codebase will become messy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  💬 Effective Commenting Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;💭 When to comment: Only comment if the code isn't clear. If it is, comments are just clutter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🫗 Clarity: Comments should tell why, not what. If your code needs explaining, it might be too complex.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🌴 Avoid redundancy: Don't comment what's obvious. If your function is addNumbers, don't comment it does that.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧼 Refactoring Techniques for Clean Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🏭 Extract methods: Big methods? Break them down. It's not just about cleanliness –– it's about control.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🫕Rename variables: If your variable names don’t shout their purpose, change and improve them. Precision in naming is precision in thought.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🍃 Simplify conditionals: If your conditionals look like algebra, simplify them. If a == true, just write if(a).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧪 Testing and Clean Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🧙 Unit tests: Test every piece of code like you're interrogating a suspect. No stone unturned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🏇TDD (Test Driven Development): Write tests first. It's not just about catching bugs, it's about knowing exactly what your code should do before you write it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🧽 Clean tests: Your tests should be as clean as your code. If they're messy, they’re not going to be helpful.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🐛 Error Handling and Clean Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;⁉️ Exceptions: Use them. They're not just for errors, they're also for keeping your code clean from error clutter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🖍️ Fail fast: If something's wrong, stop right there. Don't let errors add up. Deal with them immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🚨 Logging: Log like you're documenting a crime scene. Clear, precise, and only what's necessary.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🌱 Code Reviews and Clean Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🚢 Process: Have a system. No cowboy coding. Review, critique, improve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🔪 Tools: Use tools that make reviews easy. They're not just for catching mistakes, they're also for teaching discipline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🧦 Culture: Cultivate a culture where feedback is gold. Help your team learn how to handle and receive critiques.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Automated Tools for Maintaining Clean Code ⚓
&lt;/h2&gt;

&lt;p&gt;Tools and automation techniques can be really helpful in writing clean code. If you’re not using the right tools and automating things to save yourself time, you’re missing out.&lt;/p&gt;

&lt;p&gt;You think you can "eyeball" your way through code quality? Guess again. Without automation, this is what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;👎 You miss obvious mistakes because you're "too busy."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🤕 Your code looks different in every file, making collaboration a headache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🪦 Deployment breaks because you skipped a critical test.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Successful developers use the right tools to automate code and get things done. Here are four strategies for maintaining clean code using modern tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ Static Analysis&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Static analysis is actually a code inspector that reads through your code and points out potential issues early on. The best part? It works &lt;strong&gt;before&lt;/strong&gt; runtime, catching errors that could otherwise lead to crashes, downtime, or embarrassing bugs.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;How does it work?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Syntax checking&lt;/strong&gt;: It looks at your code to analyze everything written in the correct syntax. If you misspell a variable or forget a closing bracket, it’ll call you out instantly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code quality rules&lt;/strong&gt;: Tools like ESLint enforce rules like consistent indentation, avoiding unused variables, and sticking to best practices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error prevention&lt;/strong&gt;: It identifies logic errors, such as using variables that haven’t been defined, or making comparisons that don’t make sense.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s how static analysis works in action:&lt;/p&gt;

&lt;h4&gt;
  
  
  🚨 Before static analysis:
&lt;/h4&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Typo, unnoticed until runtime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem&lt;/strong&gt;: The typo in &lt;code&gt;sume&lt;/code&gt; will only cause an error when the code runs, and that could lead to frustrating debugging sessions or worse — breaking the app in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🚑 After static analysis (using ESLint):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;codeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sume&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; immediately flags the typo before you even run the code. The error is caught early, saving you time and headaches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ Automated Code Formatting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before Formatting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculate&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;calculate &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&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;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem&lt;/strong&gt;: Inconsistent spacing and formatting make the code harder to read.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  After using Prettier:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: Clean, consistent, and professional formatting is applied automatically. No more nitpicking over spaces or alignment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pretty basic stuff though. I covered this in case you write code in notepad or something where IDE is not provided (for example, a job interview).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣ Continuous Integration (CI) Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;CI testing make sure every new change to your code is verified automatically. It’s like a safety net that catches bugs introduced during development. CI tools run your tests every time you push code, so nothing breaks after deployment.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;How Does CI Testing Work?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Triggers on change&lt;/strong&gt;: Each time code is committed, the CI tool (like &lt;a href="https://github.com/features/actions" rel="noopener noreferrer"&gt;GitHub Actions&lt;/a&gt;, &lt;a href="https://www.jenkins.io/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;) runs automated tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback&lt;/strong&gt;: It gives you instant feedback if something fails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prevents broken code&lt;/strong&gt;: Commits only clean, and the working code gets merged into the main branch.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣ CI/CD pipelines&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We also use CI/CD pipelines as a continuous process that includes code building, testing, and deployment, while CI testing is a part of that process that focuses on automating the testing of code changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Differece between CI/CD pipelines vs CI testing:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CI/CD pipelines:&lt;/strong&gt; A CI/CD pipeline combines code building, testing, and deployment into a single process. This process make sure that all changes to the main branch code are releasable to production. CI/CD pipelines can reduce deployment time, decrease costs, and improve team collaboration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CI testing:&lt;/strong&gt; CI testing is the process of automatically testing code changes that are integrated into a central repository. CI testing focuses on making sure the codebase is stable and that integration issues are resolved. CI testing help developer build software that is stable, bug-free, and meets functional requirements&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚧 This is what CI testing CI/CD pipelines concepts are really about. Not as complex as it seems. So let me elaborate more on CI testing with GitHub Actions, as we usually run tests through automated tools nowadays.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;⚡ Continuous Integration (CI) Testing with GitHub Actions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As I said earlier, CI tools run automated tests every time you push code or open a pull request. This guarantees that only working, bug-free code gets merged into the main branch.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to Set Up CI Testing with GitHub Actions
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create Your Repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set up a GitHub repository for your project. Then, push your code to GitHub using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit for CI Testing"&lt;/span&gt;
git branch &lt;span class="nt"&gt;-M&lt;/span&gt; main
git remote add origin https://github.com/codewithshahan/codewithshahan.git
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can create a new repo from your GitHub account without using the command. Just log in to your GItHub account and visit dashboard. Here you will find a “New” button to create a brand new repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwu4mnv92uvvbcyn95bo.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%2Fzwu4mnv92uvvbcyn95bo.png" alt="image of creating a new repo on github by Shahan" width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Add a GitHub Actions Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate to your repository’s &lt;strong&gt;Actions&lt;/strong&gt; tab. To do this, first, you have to visit your repo on Github (you will find the link after creating your repo). In this case, I created a new repo called “codewithshahan”. Here, look for the &lt;strong&gt;Actions&lt;/strong&gt; tab on the right side of the navigation bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxs63er6prc63ph8c8vp0.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%2Fxs63er6prc63ph8c8vp0.png" alt="Image of github actions navigation tab by shahan" width="799" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After navigating the Actions tab, scroll down a little and you will find the &lt;strong&gt;continuous integration&lt;/strong&gt; section:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6je4zwug4js9khb27oxz.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%2F6je4zwug4js9khb27oxz.png" alt="Image of CI (Continuous Integration) testing on Github Actions Page by Shahan" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a setup workflow yourself. I will use Node.js for this project.&lt;/p&gt;

&lt;p&gt;After clicking the configure button, a &lt;code&gt;node.js.yml&lt;/code&gt; file will be created automatically, and you can adjust the code depending on your goals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxsxic171busrm0f4k44.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%2Foxsxic171busrm0f4k44.png" alt="Image of GitHub workflow snippet for automated testing by Shahan" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won’t go into detail about how should modify your &lt;code&gt;.yml&lt;/code&gt; file. It depends on your project goals and personal preference. Also, it is a whole different broader topic and as this article has already become quite long, so I’ll explain it in a future article. For now, just stick with this foundational knowledge.&lt;/p&gt;

&lt;p&gt;This CI Testing workflow is best for modern application development. Your app remains stable while incorporating key features including testing (e,g. Dark Mode), Building and deploying applications directly within your GitHub repository. This way, you can push your code confidently, knowing your code is always clean and ready for production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Role of Documentation in Agile Software Development 🚣
&lt;/h2&gt;

&lt;p&gt;If you want your code to be top-notch, you need to understand how to write good documentation. If you think documentation is just about scribbling down how the code works, you’re wrong. It's about explaining &lt;strong&gt;why&lt;/strong&gt; it works, not just how it works. That’s where most people miss the mark.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. 🚡 Create &lt;strong&gt;Useful Docs (Explain Why, Not Just How)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you write documentation, you're not just throwing down some instructions for how to use the code. You're telling the next person (or even yourself in the future) why this piece of code exists in the first place. That’s the difference between good and bad documentation.&lt;/p&gt;

&lt;p&gt;Bad docs leave people scratching their heads. They’re too vague, too simple, and they don’t answer the big questions. If your documentation is unclear, that likely means your thinking is unclear. You’re basically saying, &lt;em&gt;"I don’t care if you understand this, it works, just use it."&lt;/em&gt; That’s not helpful.&lt;/p&gt;

&lt;p&gt;Great documentation answers the tough questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅ Why did you choose this approach over another?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Why does this function exist? What problem does it solve?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Why did you write this code the way you did?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your docs are just regurgitating how to use the code, you’re not being as helpful as you can be. Start thinking deeper and explaining the reasoning behind everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. ⏳ &lt;strong&gt;Keep the Docs Updated (Outdated Docs Are Worse Than No Docs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Outdated documentation is the worst. In fact, it can be worse than having no docs at all. When you leave documentation that’s out of sync with the code, you’re doing your future self — or whoever has to deal with it next — a huge disservice.&lt;/p&gt;

&lt;p&gt;Every time your code changes, your documentation needs to change too. It has to reflect the current state of things. Don’t mislead future developers (or yourself) by leaving outdated info that will only confuse them and waste their time. If something is no longer relevant, delete it. Outdated documentation is the equivalent of a cluttered mind — it holds you back.&lt;/p&gt;

&lt;p&gt;Make it a habit to check and update your documentation regularly. The minute a line of code changes, so should your documentation. Period.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. 🚆 &lt;strong&gt;Integrate Comments (Good Comments in Code Are Part of Documentation)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here’s the deal — comments in your code should &lt;strong&gt;integrate&lt;/strong&gt; with your documentation. Good comments aren’t just a crutch for developers who can’t explain their code elsewhere. They should improve your docs, not replace them.&lt;/p&gt;

&lt;p&gt;Comments are supplements to your documentation. You write clean, understandable code that needs minimal explanation, but when something isn’t crystal clear, throw in a comment. Remember the rule for comments in your code: explain the &lt;strong&gt;why&lt;/strong&gt;, not the &lt;strong&gt;how&lt;/strong&gt;. It’s the same here. Don’t repeat yourself. Let your code do the talking. Comments should complement the bigger picture of your documentation, not act as a band-aid for sloppy code.&lt;/p&gt;

&lt;p&gt;🪧 Great code should be self-explanatory. Fix the code, then add comments for clarification if necessary. Keep comments clean, short, and to the point.&lt;/p&gt;

&lt;p&gt;If you want to write clean, efficient, and maintainable code, documentation is key. Stop thinking of docs as an afterthought or something you do to fill space. It’s an extension of your code — your way of communicating clearly and effectively. It’s your roadmap for future developers, and it’s a reflection of your thought process.&lt;/p&gt;

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

&lt;p&gt;Clean code isn't a nice-to-have –– it's a must-have for those who aim to lead. It's about control, efficiency, and improvement over time in the long run. And ultimately, it’ll help you succeed in the game of agile software development.&lt;/p&gt;

&lt;p&gt;🪧 If you want to truly master your craftsmanship, write clean code, and let the efficiency speak for itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions About Clean Code 🧯
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What is clean code?&lt;/strong&gt; It's code that doesn't make you want to throw your laptop out the window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why is clean code important in Agile?&lt;/strong&gt; Because Agile is about speed and change, and you can't be quick with a mess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What are code smells?&lt;/strong&gt; Signs that you're about to lose control of your codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How can I improve commenting?&lt;/strong&gt; Only comment on what's necessary, and make sure each comment adds value, not noise.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you for being with me. &lt;/p&gt;

&lt;p&gt;If you’re serious about learning clean code and taking your programming career to the next level, then this book is for you: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;&lt;strong&gt;Clean Code Zero to One&lt;/strong&gt;&lt;/a&gt;. Grab this and master the art of programming. After reading this book you can pick any programming language you like and build software without facing countless bugs using AI agents:&lt;/p&gt;

&lt;p&gt;40% discount using the code "earlybird", only for the first 100 copies. Plus, there’s a 30-day money-back guarantee. no risk, all reward.&lt;/p&gt;

&lt;p&gt;📘: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;https://codewithshahan.gumroad.com/l/cleancode-zero-to-one&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Related articles:&lt;br&gt;
&lt;a href="https://dev.to/codewithshahan/writing-clean-reusable-components-in-react-best-practices-2gka"&gt;Building clean reusable components in react&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/codewithshahan/your-first-backend-application-using-nodejs-45i"&gt;Your first backend application with node.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>javascript</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Anthropic is paying $570k for engineers..why not just use Claude Code? 🤔</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Sun, 26 Apr 2026 11:36:11 +0000</pubDate>
      <link>https://dev.to/horsecoder/anthropic-is-paying-570k-for-engineerswhy-not-just-use-claude-code-36ci</link>
      <guid>https://dev.to/horsecoder/anthropic-is-paying-570k-for-engineerswhy-not-just-use-claude-code-36ci</guid>
      <description>&lt;p&gt;Anthropic is paying $570k for engineers&lt;/p&gt;

&lt;p&gt;why not just use Claude Code? 🤔&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69y7hv3rnfyobzby40k7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69y7hv3rnfyobzby40k7.jpg" alt="Anthropic is paying $570k for engineers why not just use Claude Code? 🤔" width="800" height="691"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>dev job market is insane in 2026!</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Wed, 22 Apr 2026 10:06:35 +0000</pubDate>
      <link>https://dev.to/codewithshahan/how-to-learn-to-code-in-2026-before-the-hiring-surge-starts-54ho</link>
      <guid>https://dev.to/codewithshahan/how-to-learn-to-code-in-2026-before-the-hiring-surge-starts-54ho</guid>
      <description>&lt;p&gt;Learning to code in 2026 is not what it used to be.&lt;/p&gt;

&lt;p&gt;And if you still think it is&lt;/p&gt;

&lt;p&gt;You are already behind.&lt;/p&gt;

&lt;p&gt;And the way you become a developer?&lt;/p&gt;

&lt;p&gt;It's &lt;em&gt;completely&lt;/em&gt; different. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuaqvdkb1hsxt8uwy2aom.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%2Fuaqvdkb1hsxt8uwy2aom.png" alt="Image of developer asking AI agent: " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;You may ask: "should I even learn to code in 2026?"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;100% yes.&lt;/p&gt;

&lt;p&gt;Because some people think AI replaced programmers.&lt;/p&gt;

&lt;p&gt;It didn’t.&lt;/p&gt;

&lt;p&gt;It removed bad programmers.&lt;/p&gt;

&lt;p&gt;And increased demand for REAL BUILDERS.&lt;/p&gt;

&lt;p&gt;This is still one of the highest-leverage skills.&lt;/p&gt;

&lt;p&gt;Plus the software engineer (SWE) job market is picking up in 2026. &lt;/p&gt;

&lt;p&gt;SignalFire &lt;a href="https://www.signalfire.com/blog/report-engineering-talent-retention" rel="noopener noreferrer"&gt;reported&lt;/a&gt; that firms like Meta, Netflix, Uber, and Google are hiring engineers FASTER than people are leaving:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faxbmfvbhkmjptfh99c3v.webp" 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%2Faxbmfvbhkmjptfh99c3v.webp" alt="firms like Meta, Netflix, Uber, and Google are hiring engineers faster than people are leaving" width="800" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The US Bureau of Labor Statistics still expects &lt;a href="https://www.bls.gov/ooh/computer-and-information-technology/software-developers.htm#tab-6" rel="noopener noreferrer"&gt;software developer jobs to grow by about 15%&lt;/a&gt;, which is way faster than most other careers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fply6c2a2f0ctmv8dbyjm.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%2Fply6c2a2f0ctmv8dbyjm.png" alt="US Bureau of Labor Statistics still expects software developer jobs to grow by about 15%" width="576" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, &lt;a href="https://www.itransition.com/software-development/statistics" rel="noopener noreferrer"&gt;72% of organizations outsource software development&lt;/a&gt; to achieve better access to talent [32%], meet increasing customer demands more efficiently [35%], optimize spending [34%], and improve quality or performance [33%]:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbkiq6ed5e9mrypbt002.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%2Flbkiq6ed5e9mrypbt002.png" alt="72% of organizations outsource software development image graph" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Meanwhile, Python is the most sought-after programming language, with 45.7% of recruiters seeking candidates with Python skills, followed by JavaScript [41.5%], Java [39.5%], TypeScript [27.9%], and C# [24.4%].&lt;/p&gt;

&lt;p&gt;according to &lt;a href="https://www.devjobsscanner.com/python-jobs" rel="noopener noreferrer"&gt;devjobsscanner&lt;/a&gt; Python is the most in-demand language as of January 2026 with 43,300+ posted job openings:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcptasmsx23fjta0luofn.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%2Fcptasmsx23fjta0luofn.png" alt="Image statistic: Python is the most in-demand language as of January 2026" width="799" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AND&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gartner.com/en/newsroom/press-releases/2024-10-03-gartner-says-generative-ai-will-require-80-percent-of-engineering-workforce-to-upskill-through-2027" rel="noopener noreferrer"&gt;Gartner predicts&lt;/a&gt; that by 2027, 80% of the engineering workforce will need to upskill to keep pace with generative AI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5oqos795x14j7x91sca5.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%2F5oqos795x14j7x91sca5.png" alt="by 2027, 80% of the engineering workforce will need to upskill to keep pace with generative AI." width="799" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so if you can code in 2026 you certainly can &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📲 build complex application&lt;/li&gt;
&lt;li&gt;😴 automate your entire projects &lt;/li&gt;
&lt;li&gt;💼 land your dream job&lt;/li&gt;
&lt;li&gt;🦮 and instruct AI instead of being replaced by it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The good news is: learning to code today is much easier than ever before.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2y7up6g2rvc9kotvj9h6.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%2F2y7up6g2rvc9kotvj9h6.png" alt="developer using secret ai prompt to learn code faster" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in this article, I will show you:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. 🍱 what coding looks like now in 2026&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. 🏫 what you MUST learn for the future&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. ⚡ AND how to speed up your learning massively&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's jump in.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;💊TABLE OF CONTENTS:&lt;/strong&gt;&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FIRST: Why "Vibe coding" to "Agentic Engineering" shift happened?&lt;/li&gt;
&lt;li&gt;
🍼 STEP 1: Coding Fundamentals (non-negotiable)

&lt;ul&gt;
&lt;li&gt;Language choice&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;🍌 STEP 2: Software Architecture&lt;/li&gt;
&lt;li&gt;🧪 STEP 3: Testing &lt;/li&gt;
&lt;li&gt;🛫 STEP 4: Deployment &lt;/li&gt;
&lt;li&gt;🛩️🎮 STEP 5: Version Control&lt;/li&gt;
&lt;li&gt;🔐 STEP 6: Security &amp;amp; Privacy &lt;/li&gt;
&lt;li&gt;🚢 STEP 7: Microservices &amp;amp; Containers &lt;/li&gt;
&lt;li&gt;
💪 NOW you are ready for AI coding

&lt;ul&gt;
&lt;li&gt;⚡ The new coding shift: Agentic Engineering&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
🧠 How to learn code faster 

&lt;ul&gt;
&lt;li&gt;🤔 1. Use AI to THINK, not just code&lt;/li&gt;
&lt;li&gt;🔍 2. Reverse engineer code&lt;/li&gt;
&lt;li&gt;🏗️ 3. Projects = everything&lt;/li&gt;
&lt;li&gt;🧠 4. Ask AI for multiple solutions&lt;/li&gt;
&lt;li&gt;📄 5. Documentation shortcut&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;📚 Recommendation&lt;/li&gt;
&lt;li&gt;🧭 Final thoughts&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  FIRST: Why "Vibe coding" to "Agentic Engineering" shift happened?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgbz3p9rkf8ul7xuz9cf.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%2Fqgbz3p9rkf8ul7xuz9cf.png" alt="Image of developer coding agentic engineering" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 2025, Andrej Karpathy introduced something called&lt;/p&gt;

&lt;p&gt;👉 “Vibe coding”&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1886192184808149383-98" src="https://platform.twitter.com/embed/Tweet.html?id=1886192184808149383"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1886192184808149383-98');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1886192184808149383&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;It meant&lt;/p&gt;

&lt;p&gt;🤖 you talk to AI&lt;br&gt;
🍎 you let it generate code&lt;br&gt;
🥱 you don’t care about details&lt;/p&gt;

&lt;p&gt;It worked for small projects. &lt;/p&gt;

&lt;p&gt;It was fun.&lt;/p&gt;

&lt;p&gt;But it was never serious engineering.&lt;/p&gt;

&lt;p&gt;Then things changed in 2026.&lt;/p&gt;

&lt;p&gt;By 2026, a new workflow became normal:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Agentic Engineering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1egvkjhdlsmxdujbp1ly.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%2F1egvkjhdlsmxdujbp1ly.png" alt="Image of agentic engineerin shift amon devevelopers" width="800" height="902"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This hits &lt;em&gt;different&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now you don’t just “talk to AI”&lt;/p&gt;

&lt;p&gt;You:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🤹 manage AI coding agents&lt;/li&gt;
&lt;li&gt;🏗️ structure systems&lt;/li&gt;
&lt;li&gt;🦮 guide architecture&lt;/li&gt;
&lt;li&gt;🪸 correct mistakes&lt;/li&gt;
&lt;li&gt;🛫 control outputs like a system designer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You are no longer a coder.&lt;/p&gt;

&lt;p&gt;You are now a &lt;strong&gt;Chief of Commander&lt;/strong&gt; of machine. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tnhs8wagp7md8ztbtoh.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%2F5tnhs8wagp7md8ztbtoh.png" alt="developer doing agentic engeering to fix customer feedback" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But here’s the trap:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can’t command what you don’t understand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So fundamentals still rule everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  🍼 STEP 1: Coding Fundamentals (non-negotiable)
&lt;/h2&gt;

&lt;p&gt;Before AI, &lt;a href="https://dev.to/codewithshahan/skills-to-become-a-backend-developer-in-6-months-roadmap-4li3"&gt;coding fundamentals&lt;/a&gt; &lt;em&gt;was&lt;/em&gt; everything.&lt;/p&gt;

&lt;p&gt;Now?&lt;/p&gt;

&lt;p&gt;Still everything.&lt;/p&gt;

&lt;p&gt;You must learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[variables]&lt;/li&gt;
&lt;li&gt;[data types]&lt;/li&gt;
&lt;li&gt;conditions (if/else)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loops&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;[functions]&lt;/li&gt;
&lt;li&gt;object-oriented programming&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;privacy &amp;amp; security&lt;/li&gt;
&lt;li&gt;clean code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because if you cannot &lt;a href="https://dev.to/codewithshahan/clean-code-zero-to-one-4ihk"&gt;read, scale or maintain code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You CAN'T control AI-generated code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ok5zdmsaep4jwgv3qen.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%2F3ok5zdmsaep4jwgv3qen.png" alt="ai agent leaking production database because dev doesn't know how to write code securely" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You become dependent. &lt;/p&gt;

&lt;p&gt;Your software becomes useless. &lt;/p&gt;

&lt;h3&gt;
  
  
  Language choice
&lt;/h3&gt;

&lt;p&gt;You should pick only one tech field first and go deep.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff913mw2hvrv3oz7jifq6.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%2Ff913mw2hvrv3oz7jifq6.png" alt="what programming language to learn in 2026? a developer confuse what coding language to learn" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To begin with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;learn Python for AI, automation, data systems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;learn JavaScript for web/mobile apps, frontend/backend&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pick ONE. Don’t jump.&lt;/p&gt;

&lt;h2&gt;
  
  
  🍌 STEP 2: Software Architecture
&lt;/h2&gt;

&lt;p&gt;This is where beginners quit.&lt;/p&gt;

&lt;p&gt;And professionals are built.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feve56ysqgbahztqu8x2r.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%2Feve56ysqgbahztqu8x2r.png" alt="Image of software dev learning sotware architecture and google is scanning if this app legit" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;how software is structured&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;how systems are designed (clean code)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;how tech stacks are chosen&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;how APIs connect systems&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;how data flows&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;where data is stored (databases)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now think: you want to build an app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3i7beryky1xiyz94m1b.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%2Fc3i7beryky1xiyz94m1b.png" alt="a confused AI agent sitting down arguing why developer don't know clean code architecture" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must answer these questions:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Where does data go?&lt;br&gt;
How does it scale?&lt;br&gt;
How do users interact with it?&lt;br&gt;
How fast is it under load?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These are NOT coding questions.&lt;/p&gt;

&lt;p&gt;These are &lt;strong&gt;engineering decisions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And AI cannot reliably decide them for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 STEP 3: Testing
&lt;/h2&gt;

&lt;p&gt;AI can write code.&lt;/p&gt;

&lt;p&gt;But AI also makes mistakes silently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcohux2ne440joklxqcgl.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%2Fcohux2ne440joklxqcgl.png" alt="ai coding agents breaking project in production image illustration" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;So you must learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🍽️ how to write test cases&lt;/li&gt;
&lt;li&gt;🍳 how to verify logic&lt;/li&gt;
&lt;li&gt;🪠 how to validate features&lt;/li&gt;
&lt;li&gt;🫗 how to catch failures early&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Concretely, without testing you are guessing.&lt;/p&gt;

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

&lt;p&gt;You are controlling your output.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛫 STEP 4: Deployment
&lt;/h2&gt;

&lt;p&gt;Code that ONLY runs locally is useless.&lt;/p&gt;

&lt;p&gt;learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🪂 how to host applications&lt;/li&gt;
&lt;li&gt;🗼 how servers work&lt;/li&gt;
&lt;li&gt;🪟 how environments are structured&lt;/li&gt;
&lt;li&gt;🪈 how deployment pipelines function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Job recruiters often ask about it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6sok9ox9dc1vnefnf9x.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%2Fs6sok9ox9dc1vnefnf9x.png" alt="image of concept art of dev deploying facebook app and explain to Google recruiter" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must ship to create history. &lt;/p&gt;

&lt;p&gt;You must understand and explain WHY things does/doesn't work.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛩️🎮 STEP 5: Version Control
&lt;/h2&gt;

&lt;p&gt;Version control (e,g. Git) is not optional. Its the baseline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fekwonjtui3td7eyhc6gq.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%2Fekwonjtui3td7eyhc6gq.png" alt="a developer is frustrated after losing his 2.5months of work and git assuring use me or lose another work" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
You need it even if AI is knocking on your door.&lt;/p&gt;

&lt;p&gt;Learn what version control does and master the most useful commands. &lt;/p&gt;

&lt;p&gt;You will thank me later. &lt;/p&gt;

&lt;p&gt;Now in AI-driven coding&lt;/p&gt;

&lt;p&gt;This becomes even more important.&lt;/p&gt;

&lt;p&gt;Because AI can break your project while you blink.&lt;/p&gt;

&lt;p&gt;Git or version control system will help you tackle it.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔐 STEP 6: Security &amp;amp; Privacy
&lt;/h2&gt;

&lt;p&gt;This is where AI fails the most. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frr9z3g90wiwu4x8zk643.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%2Frr9z3g90wiwu4x8zk643.png" alt="Image of claude code meme stealing password from dev" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AI acts as a child to "security and privacy" &lt;/p&gt;

&lt;p&gt;And that's where beginners get destroyed without knowing.&lt;/p&gt;

&lt;p&gt;So learn&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;🥷 authentication&lt;/li&gt;
&lt;li&gt;👨‍🦯‍➡️ authorization&lt;/li&gt;
&lt;li&gt;🛟 data safety&lt;/li&gt;
&lt;li&gt;🗝️ secure APIs&lt;/li&gt;
&lt;li&gt;🔏 secret management&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AI does NOT care about security unless you force it to.&lt;/p&gt;

&lt;p&gt;And real engineers know this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Paranoia is not fear. it is protection."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which means build a proactive security-first mindset where you assume threats exist and systems will fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚢 STEP 7: Microservices &amp;amp; Containers
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fka0mpfzarvcvjf61y35g.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%2Fka0mpfzarvcvjf61y35g.png" alt="Image of developer using docker where AI fails" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is advanced.&lt;/p&gt;

&lt;p&gt;But important.&lt;/p&gt;

&lt;p&gt;You should learn:&lt;/p&gt;

&lt;p&gt;-0  how applications are packaged&lt;br&gt;
-01 how dependencies are bundled&lt;br&gt;
-02 how systems run in isolation&lt;br&gt;
-04 how environments stay consistent&lt;/p&gt;

&lt;p&gt;Why does this matter now?&lt;/p&gt;

&lt;p&gt;Because AI agents can break your projects, break environments and create unpredictable setups&lt;/p&gt;

&lt;p&gt;Containers (e.g., Docker) protect you from drowning.&lt;/p&gt;




&lt;h2&gt;
  
  
  💪 NOW you are ready for AI coding
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1pi9vvd6p4pr6b7914mq.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%2F1pi9vvd6p4pr6b7914mq.png" alt="developer ready for using AI coding and buid projects much faster" width="800" height="905"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Only after all this…&lt;/p&gt;

&lt;p&gt;You use AI properly.&lt;/p&gt;

&lt;p&gt;But as a tool.&lt;/p&gt;

&lt;p&gt;Now you can&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📢 direct AI agents&lt;/li&gt;
&lt;li&gt;🍔 build systems faster&lt;/li&gt;
&lt;li&gt;🤜 correct mistakes&lt;/li&gt;
&lt;li&gt;🏠 design architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ The new coding shift: Agentic Engineering
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1egvkjhdlsmxdujbp1ly.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%2F1egvkjhdlsmxdujbp1ly.png" alt="Image of agentic engineerin shift amon devevelopers" width="800" height="902"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now coding looks like this:&lt;/p&gt;

&lt;p&gt;You open your machine.&lt;/p&gt;

&lt;p&gt;Multiple AI agents working:&lt;/p&gt;

&lt;p&gt;One builds backend. One writes tests. One handles docs&lt;/p&gt;

&lt;p&gt;You assign tasks, correct mistakes, guide structure, AND enforce logic.&lt;/p&gt;

&lt;p&gt;This is not coding anymore. &lt;/p&gt;

&lt;p&gt;This is agentic engineering. &lt;/p&gt;

&lt;p&gt;Make sure to learn it early. &lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 How to learn code faster
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp6zpewla8ydspjgtl811.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%2Fp6zpewla8ydspjgtl811.png" alt="how to learn code faster meme" width="800" height="902"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most people fail here because they consume too much content.&lt;/p&gt;

&lt;p&gt;or learn but never build&lt;/p&gt;

&lt;p&gt;Before, it took 2–5 years to become solid developer&lt;/p&gt;

&lt;p&gt;Now ~6 months if you are focused. &lt;/p&gt;

&lt;p&gt;Because tools will multiply your output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So here is the solid strategy to learn code faster:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🤔 1. Use AI to THINK, not just code
&lt;/h3&gt;

&lt;p&gt;Don’t ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“write code”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"explain this"&lt;br&gt;
"break it down"&lt;br&gt;
"give analogies"&lt;br&gt;
"show mistakes"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🔍 2. Reverse engineer code
&lt;/h3&gt;

&lt;p&gt;Take real projects.&lt;/p&gt;

&lt;p&gt;Then: break them, modify them and ask AI to explain them&lt;/p&gt;

&lt;p&gt;That is actual serious learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  🏗️ 3. Projects = everything
&lt;/h3&gt;

&lt;p&gt;No projects = no skill.&lt;/p&gt;

&lt;p&gt;You must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;☑️ build APIs&lt;/li&gt;
&lt;li&gt;☑️ build apps&lt;/li&gt;
&lt;li&gt;☑️ build features&lt;/li&gt;
&lt;li&gt;☑️ break and fix things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s how neural memory forms. &lt;/p&gt;

&lt;p&gt;Reading or watching tutorials is another word for procrastination. &lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 4. Ask AI for multiple solutions
&lt;/h3&gt;

&lt;p&gt;NEVER accept one answer.&lt;/p&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“give me 3 approaches”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;this way you'll learn: tradeoffs. efficiency. structure&lt;/p&gt;

&lt;h3&gt;
  
  
  📄 5. Documentation shortcut
&lt;/h3&gt;

&lt;p&gt;Nobody likes reading documentation.&lt;/p&gt;

&lt;p&gt;Don’t struggle through docs.&lt;/p&gt;

&lt;p&gt;Use AI to translate them.&lt;/p&gt;

&lt;p&gt;But still understand them.&lt;/p&gt;

&lt;h2&gt;
  
  
  📚 Recommendation
&lt;/h2&gt;

&lt;p&gt;If you want a clean, structured path:&lt;/p&gt;

&lt;p&gt;📘 My &lt;strong&gt;&lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;&lt;/strong&gt; book is for you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fic3yhzc59cy84ftdt9ew.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%2Fic3yhzc59cy84ftdt9ew.png" alt="developer reading clean code zero to one book written by Shahan Chowdhury" width="800" height="953"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After reading this book you'll think like a system designer. Write clean architecture. Scale and maintain your application and avoid beginner's mistakes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧭 Final thoughts
&lt;/h2&gt;

&lt;p&gt;Coding in 2026 is easy. &lt;/p&gt;

&lt;p&gt;BUT its not "too easy" as 63% of non-developers so called "vibe coders" think. They all face the reality when seriously get involved in buidling softwares. &lt;/p&gt;

&lt;p&gt;either you learn fundamentals&lt;/p&gt;

&lt;p&gt;Or you skip fundamentals and get replaced. &lt;/p&gt;

&lt;p&gt;There is no middle. &lt;/p&gt;

&lt;p&gt;Now open your code editor and build something cool from scratch! 🥂&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://www.linkedin.com/in/codewithshahan" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;. Thanks.&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>ai</category>
      <category>career</category>
    </item>
    <item>
      <title>learn these 12 git commands and forget</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Fri, 17 Apr 2026 22:31:10 +0000</pubDate>
      <link>https://dev.to/codewithshahan/mastering-git-github-12-most-useful-git-commands-3l70</link>
      <guid>https://dev.to/codewithshahan/mastering-git-github-12-most-useful-git-commands-3l70</guid>
      <description>&lt;h2&gt;
  
  
  🌱 Introduction
&lt;/h2&gt;

&lt;p&gt;Most devs think they can vibe code with a few Git commands.&lt;br&gt;
They run &lt;code&gt;git add .&lt;/code&gt;, "push commit" … and start acting like they built Linux.&lt;/p&gt;

&lt;p&gt;I’ve seen the opposite.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj17y2egh5b0w75tp7cs5.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%2Fj17y2egh5b0w75tp7cs5.png" alt="Image description: 12 advanced Git commands 2026 by Shahan" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;they trust AI agents and then the project turns into something nobody wants to touch.&lt;/p&gt;

&lt;p&gt;I’ve done that too, early on.&lt;/p&gt;

&lt;p&gt;The difference is that you eventually get tired of fixing avoidable problems. That’s when Git stops being a checklist of commands and starts becoming a way of working.&lt;/p&gt;

&lt;p&gt;These 12 git commands I actually rely on when things get messy or when I want to keep things clean from the start.&lt;/p&gt;

&lt;p&gt;now lets get started.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎂 1) Rebasing
&lt;/h2&gt;

&lt;p&gt;AI code reviewers and merge queues DO NOT babysit premature branches. &lt;/p&gt;

&lt;p&gt;They &lt;u&gt;expect&lt;/u&gt; discipline.&lt;/p&gt;

&lt;p&gt;most so called git expert stack commits like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;fix&lt;br&gt;
fix again&lt;br&gt;
testing&lt;br&gt;
oops&lt;br&gt;
final-final-v3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then they open a PR (pull request) and &lt;a href="https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic"&gt;hope it works&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately it doesn’t. &lt;/p&gt;
&lt;h3&gt;
  
  
  🍄‍🟫 What rebase actually is
&lt;/h3&gt;

&lt;p&gt;Look at the image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh1d6t1a4s1gci3l4vljf.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%2Fh1d6t1a4s1gci3l4vljf.png" alt="Image description of " width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bottom = old commits&lt;br&gt;
Top = latest main&lt;br&gt;
Dog = your feature branch&lt;/p&gt;

&lt;p&gt;Right now your branch is behind.&lt;/p&gt;

&lt;p&gt;The dog is sitting somewhere in the middle.&lt;/p&gt;

&lt;p&gt;But he wants the top.&lt;/p&gt;

&lt;p&gt;So what does he do?&lt;/p&gt;

&lt;p&gt;He cLimbs.&lt;/p&gt;

&lt;p&gt;Step by step.&lt;/p&gt;

&lt;p&gt;And then he sits on top of the latest main.&lt;/p&gt;

&lt;p&gt;That’s &lt;strong&gt;rebase.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don’t build sideways.&lt;br&gt;
You don’t stay behind.&lt;/p&gt;

&lt;p&gt;You move your work to the top.&lt;/p&gt;

&lt;p&gt;Clean. Straight. Done.&lt;/p&gt;

&lt;p&gt;🤔 You ask &lt;strong&gt;why?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Look, modern teams use &lt;a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request" rel="noopener noreferrer"&gt;AI merge queues, automated reviewers, async PR pipelines.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These systems are NOT your mother.&lt;/p&gt;

&lt;p&gt;THey don’t review your failure.&lt;/p&gt;

&lt;p&gt;AI pipelines don’t fix your alienated history.&lt;/p&gt;

&lt;p&gt;They see this:&lt;/p&gt;

&lt;p&gt;random commits&lt;br&gt;
unclear changes&lt;br&gt;
outdated branch&lt;/p&gt;

&lt;p&gt;🙅‍♂️ And they reject it.&lt;/p&gt;

&lt;p&gt;Not because you’re bad.&lt;/p&gt;

&lt;p&gt;Because your &lt;em&gt;git history&lt;/em&gt; is turmoil. 🧐🌡️&lt;/p&gt;

&lt;p&gt;WitH rebase you fix everything before PR.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Now merge is simple.&lt;/u&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🍨 Rebase workflow
&lt;/h3&gt;

&lt;p&gt;This is what you actually do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch feature-login
git fetch origin
git rebase origin/main

git add &lt;span class="nb"&gt;.&lt;/span&gt;
git rebase &lt;span class="nt"&gt;--continue&lt;/span&gt;

git push &lt;span class="nt"&gt;--force-with-lease&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🏗️ Code demonstrations for beginners:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1) 🧗‍♂️ Switch to your feature branch = &lt;code&gt;git switch feature-login&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You move into your own work area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) ⛅ Get latest updates from remote = &lt;code&gt;git fetch origin&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You look at what changed on the server using fetch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) 🛟 Rebuild your work on top of latest main = &lt;code&gt;git rebase origin/main&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the core moment.&lt;/p&gt;

&lt;p&gt;Git takes your commits and replays them one by one on top of the newest main.&lt;/p&gt;

&lt;p&gt;So instead of:&lt;/p&gt;

&lt;p&gt;messy branch history&lt;br&gt;
outdated base&lt;/p&gt;

&lt;p&gt;You now get:&lt;/p&gt;

&lt;p&gt;clean linear history&lt;br&gt;
same work, new foundation&lt;/p&gt;

&lt;p&gt;If conflicts happen, Git stops here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) 🚤 Fix conflicts (if any)&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;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git rebase &lt;span class="nt"&gt;--continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;you fix the files&lt;br&gt;
you tell Git: “okay continue”&lt;/p&gt;

&lt;p&gt;Git keeps replaying your commits until everything is applied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5) Push updated history = &lt;code&gt;git push --force-with-lease&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Important part:&lt;/p&gt;

&lt;p&gt;You are not just pushing code.&lt;/p&gt;

&lt;p&gt;You are rewriting history.&lt;/p&gt;

&lt;p&gt;So Git says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Only push if nobody else changed this branch while you were working.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s what &lt;code&gt;--force-with-lease&lt;/code&gt; protects you from. &lt;/p&gt;

&lt;p&gt;It checks if someone else updated the branch.&lt;/p&gt;

&lt;p&gt;If yes, it stops you.&lt;/p&gt;

&lt;p&gt;So you don’t destroy their work.&lt;/p&gt;

&lt;p&gt;again, rebase changes history.&lt;/p&gt;

&lt;p&gt;That’s why you don’t just &lt;code&gt;--force&lt;/code&gt; push blindly. &lt;/p&gt;


&lt;h2&gt;
  
  
  🪦 2) Reset, Revert, Restore
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4j21v0xnzqj5aqzn16t.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%2Ff4j21v0xnzqj5aqzn16t.png" alt="Image description: 2) Reset, Revert, Restore" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mistakes will happen.&lt;/p&gt;

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

&lt;p&gt;Panicking is optional.&lt;/p&gt;

&lt;p&gt;Some developers break things… then freeze.&lt;/p&gt;

&lt;p&gt;Others fix it in 10 seconds and move on.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Read &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt; and become like them.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;The difference is knowing which command to use.&lt;/p&gt;
&lt;h3&gt;
  
  
  Git gives you &lt;strong&gt;three weapons&lt;/strong&gt; to reverse damage:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert HEAD 
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; app.js
git restore app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;[ code demonstration is below ]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) 🦺 &lt;code&gt;git revert&lt;/code&gt; | safe undo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don’t delete anything.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git revert HEAD&lt;/code&gt; = Makes a &lt;em&gt;new&lt;/em&gt; commit that cancels the last one.&lt;/p&gt;

&lt;p&gt;History stays clean.&lt;/p&gt;

&lt;p&gt;Nothing is hidden.&lt;/p&gt;

&lt;p&gt;This is what serious teams want.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) 🗑️ &lt;code&gt;git reset&lt;/code&gt; | delete it completely&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This one is different.&lt;/p&gt;

&lt;p&gt;It moves your branch back.&lt;/p&gt;

&lt;p&gt;The commit is gone.&lt;/p&gt;

&lt;p&gt;Like it never happened.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git reset --hard HEAD~1&lt;/code&gt; = Deletes the last commit and your changes.&lt;/p&gt;

&lt;p&gt;Fast. Clean. But dangerous.&lt;/p&gt;

&lt;p&gt;If someone already pulled that commit… you just created a big mess.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use it when you’re alone on the branch.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) 🗃️ &lt;code&gt;git restore&lt;/code&gt; | fix files only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This doesn’t touch history.&lt;/p&gt;

&lt;p&gt;It just fixes your working files.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git restore --staged app.js&lt;/code&gt; = Removes &lt;code&gt;app.js&lt;/code&gt; from staging (undo git add). Your edits stay untouched.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git restore app.js&lt;/code&gt; = Deletes your changes. File goes back to last commit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Concretely:&lt;/strong&gt;&lt;br&gt;
revert → undo safely&lt;br&gt;
reset → erase history&lt;br&gt;
restore → fix files&lt;/p&gt;

&lt;p&gt;Three different jobs.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Where people mess up?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;They use reset when they should use revert.&lt;/p&gt;

&lt;p&gt;Now history is broken.&lt;/p&gt;

&lt;p&gt;Team is confused.&lt;/p&gt;

&lt;p&gt;Time is wasted.&lt;/p&gt;
&lt;h3&gt;
  
  
  🦐 2026 RRR Best Practices
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffoh3nxjx6ri88jt7iwk5.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%2Ffoh3nxjx6ri88jt7iwk5.png" alt="Image description: git checkout no longer needed use git switch and git checkout" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git switch&lt;/code&gt; and &lt;code&gt;git restore&lt;/code&gt; replaced the overloaded confusing &lt;code&gt;git checkout&lt;/code&gt;. This isn’t optional anymore.&lt;/p&gt;

&lt;p&gt;Modern teams would love to see you using them.&lt;/p&gt;

&lt;p&gt;Old messy &lt;code&gt;git checkout&lt;/code&gt; command did everything: &lt;br&gt;
Switch branches. Restore files. Confuse everyone.&lt;/p&gt;

&lt;p&gt;Now it’s split into two:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git switch&lt;/code&gt;: move between branches&lt;br&gt;
&lt;code&gt;git restore&lt;/code&gt;: fix files / undo file changes&lt;/p&gt;

&lt;p&gt;ITs much cleaner and accurate. &lt;/p&gt;

&lt;p&gt;That’s why you will &lt;strong&gt;never&lt;/strong&gt; see me use &lt;code&gt;checkout&lt;/code&gt; in this article.&lt;/p&gt;

&lt;p&gt;It’s outdated. &lt;/p&gt;

&lt;p&gt;Just like a serious dev who &lt;a href="https://dev.to/codewithshahan/how-to-write-clean-code-tips-for-developers-with-examples-25ic"&gt;refuses to shallow AI hypes.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will show you EXACTLY how they work in the next section (#3).&lt;/p&gt;


&lt;h2&gt;
  
  
  🫰3) Switch &amp;amp; Restore
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9igzuuiz0akqqinm29x.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%2Fz9igzuuiz0akqqinm29x.png" alt="Image description: Git Switch &amp;amp; Restore (Modern Navigation)" width="800" height="336"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch main
git switch &lt;span class="nt"&gt;-c&lt;/span&gt; feature-payment

git restore README.md
git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; utils.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  👉 &lt;code&gt;git switch main&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;with that, you leave your current branch and return to mission control.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
You’re on: &lt;code&gt;bugfix/login-issue&lt;/code&gt;&lt;br&gt;
You’ve got random work-in-progress edits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After running:&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;git switch main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are now on the &lt;code&gt;main&lt;/code&gt; branch. &lt;/p&gt;

&lt;p&gt;Your files instantly match the &lt;code&gt;main&lt;/code&gt; branch’s state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✍️ NOTE:&lt;/strong&gt; Uncommitted edits may follow, unless switching would create conflicts, in which case Git stops you to avoid damage. That's protection.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;either way, you’ve returned to home base. You’re back to clean ground..&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  👉 &lt;code&gt;git switch -c feature-payment&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;
A new branch &lt;strong&gt;is created&lt;/strong&gt;  which is &lt;code&gt;feature-payment&lt;/code&gt;&lt;br&gt;
And you immediately &lt;strong&gt;enter&lt;/strong&gt; that branch.&lt;/p&gt;

&lt;p&gt;Now your payment feature lives in isolation.&lt;/p&gt;

&lt;p&gt;No risk of breaking main.&lt;br&gt;
No overlap with other features.&lt;/p&gt;

&lt;p&gt;🪜 One branch per mission. &lt;/p&gt;


&lt;h3&gt;
  
  
  👉 &lt;code&gt;git restore --staged utils.js&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This is your emergency fix when you accidentally run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and stage files you didn’t want to include.&lt;/p&gt;

&lt;p&gt;Fix it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; utils.js

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

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;utils.js&lt;/code&gt; is &lt;em&gt;unstaged&lt;/em&gt; which is removed from the commit list.&lt;/p&gt;

&lt;p&gt;But your edits remain safely in your working directory.&lt;/p&gt;

&lt;p&gt;which means, you fix the mistake without losing a single line.&lt;/p&gt;




&lt;h2&gt;
  
  
  🐾 4) --amend Commits [Fix Without Noise]
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv15yeio3v7x7n8a7btda.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%2Fv15yeio3v7x7n8a7btda.png" alt="Image description: 4) Amend Commits [Fix Without Noise]" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You forgot a file?&lt;br&gt;
You wrote a typo?&lt;br&gt;
You missed a small edit?&lt;/p&gt;

&lt;p&gt;You &lt;code&gt;--amend&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧱 What “--amend” actually DOES?&lt;/strong&gt;&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;“Take my LAST commit and update it as if the mistake NEVER existed.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It does NOT create a new commit. It &lt;em&gt;replaces&lt;/em&gt; the previous one.&lt;/p&gt;

&lt;p&gt;But most commits like this:&lt;/p&gt;

&lt;p&gt;“fix again”&lt;br&gt;
“final fix”&lt;br&gt;
“real final fix”&lt;/p&gt;

&lt;p&gt;Now history looks like garbage.&lt;/p&gt;

&lt;p&gt;No worries.. you can time travel and &lt;code&gt;--amend&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Real example (this happens all the time)
&lt;/h3&gt;

&lt;p&gt;You accidentally committed .env&lt;/p&gt;

&lt;p&gt;Sensitive keys. Big mistake.&lt;/p&gt;

&lt;p&gt;You don’t say:&lt;/p&gt;

&lt;p&gt;“oops let me fix it in next commit”&lt;/p&gt;

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

&lt;p&gt;You clean it properly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--cached&lt;/span&gt; .env
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;".env"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; .gitignore
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;--no-edit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done.&lt;/p&gt;

&lt;p&gt;That commit never had .env.&lt;/p&gt;

&lt;p&gt;⏹️ You remove the sensitive file&lt;br&gt;
and rewrite the last commit like it never existed.&lt;/p&gt;

&lt;p&gt;Let me explain.. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;git rm --cached .env&lt;/code&gt; 👉 This removes .env from Git tracking (not your computer)&lt;/p&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo ".env" &amp;gt;&amp;gt; .gitignore&lt;/code&gt; 👉 So you don’t repeat the same mistake&lt;/p&gt;

&lt;p&gt;Now your changes are staged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THEN you run:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit --amend --no-edit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🫡 This rewrites the last commit&lt;br&gt;
👉 Same message&lt;br&gt;
🦵 But WITHOUT the .env file&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why &lt;code&gt;--no-edit&lt;/code&gt;?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because you don’t want to waste time rewriting the message.&lt;/p&gt;

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

&lt;p&gt;“Same commit message. Just fix the mistake.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🤔 What if you WANT to edit?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then DO NOT use &lt;code&gt;--no-edit.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Just do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit --amend&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now Git opens the editor.&lt;/p&gt;

&lt;p&gt;You can fix the message, explain what changed and make it more professional&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let me illustrate an everyday use case scenario:&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;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~5
&lt;span class="nt"&gt;--amend&lt;/span&gt; → fix your last mistake instantly
rebase &lt;span class="nt"&gt;-i&lt;/span&gt; → squash, reorder, clean commits like a surgeon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how you turn:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“fixed stuff lol”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;into [for example]:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Refactor auth flow + fix token expiry bug” &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now your history makes sense.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;⚠️ WARNING (read twice):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Only --amend local commits.&lt;/p&gt;

&lt;p&gt;Never &lt;code&gt;--amend&lt;/code&gt; commits already pushed to a &lt;u&gt;team branch&lt;/u&gt;.&lt;/p&gt;

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

&lt;p&gt;Because you rewrite history.&lt;/p&gt;

&lt;p&gt;Automated pipelines, merge queues and AI agents HATE rewritten history.&lt;/p&gt;

&lt;p&gt;🥍 Push amended commits ONLY if you're 100% sure NO ONE else has pulled them.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏫 5) Git Log / Learn From History
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0t2gfsv58c1evp10pv5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj0t2gfsv58c1evp10pv5.gif" alt="Image description 5) Git Log [Learn From History]" width="600" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git doesn’t lie.&lt;/p&gt;

&lt;p&gt;Your code can lie. Your memory can lie. Your teammates can lie.&lt;/p&gt;

&lt;p&gt;nowadays devs zombie scroll through Git logs.&lt;/p&gt;

&lt;p&gt;They don’t understand the POWER &lt;em&gt;hidden&lt;/em&gt; in "history".&lt;/p&gt;

&lt;p&gt;Good history = easy debugging&lt;br&gt;
Bad history = endless suffering&lt;/p&gt;
&lt;h3&gt;
  
  
  ⚖️ The 50/72 rule
&lt;/h3&gt;

&lt;p&gt;Follow 50/72 Rule for efficient bug tracing AND debugging.&lt;/p&gt;

&lt;p&gt;keep titles under 50 characters and wrap descriptions at 72. &lt;/p&gt;

&lt;p&gt;write messages like "Add feature" instead of "Added feature". &lt;/p&gt;

&lt;p&gt;and do not mix code refactors with new features in the same commit.&lt;/p&gt;

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

&lt;p&gt;commit 1: "fixed stuff"&lt;br&gt;
commit 2: "final update&lt;br&gt;
commit 3: "changes lol.."&lt;/p&gt;

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

&lt;p&gt;commit 1: "fix(auth): resolve token expiry issue"&lt;/p&gt;

&lt;p&gt;Now you know what happened without opening code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Basic survival commands
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git log --oneline&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git log --oneline --graph --decorate&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git log --oneline --author="Shahan"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git log --oneline -- path/to/file&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What they really mean:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--oneline&lt;/code&gt; = fast history scan + short, readable commits&lt;br&gt;
&lt;code&gt;--graph&lt;/code&gt; = see branch chaos visually&lt;br&gt;
&lt;code&gt;--graph --decorate&lt;/code&gt; → visualize merges &amp;amp; branches&lt;br&gt;
&lt;code&gt;--author&lt;/code&gt; = see who broke what&lt;br&gt;
&lt;code&gt;-- path/to/file&lt;/code&gt; = see only a single file’s history&lt;/p&gt;

&lt;p&gt;This is how you stop guessing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When things get serious you type&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;git log -p&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git log -S "functionName"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git blame file.js&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git reflog&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you’re not reading history.&lt;/p&gt;

&lt;p&gt;You’re hunting problems.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-p&lt;/code&gt; shows exact code changes&lt;br&gt;
&lt;code&gt;-S&lt;/code&gt; finds when a bug was introduced&lt;br&gt;
&lt;code&gt;git blame&lt;/code&gt; shows who touched each line&lt;br&gt;
&lt;code&gt;git reflog&lt;/code&gt; brings back “lost” commits&lt;/p&gt;


&lt;h2&gt;
  
  
  6) 🪝 Git Hooks to Automate Discipline
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9x0xrkcbctd3djb9cf9.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%2Fq9x0xrkcbctd3djb9cf9.png" alt="Image description: 6) Git Hooks to Automate Discipline" width="800" height="336"&gt;&lt;/a&gt;&lt;br&gt;
Junior devs hope code is fine.&lt;/p&gt;

&lt;p&gt;Serious devs don’t hope anything.&lt;/p&gt;

&lt;p&gt;They build systems that refuse bad code.&lt;/p&gt;

&lt;p&gt;That’s what Git hooks are.&lt;/p&gt;

&lt;p&gt;Hooks are simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They run automatically when you commit, push, or merge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Without asking. Without reminders. &lt;/p&gt;

&lt;p&gt;If something is wrong they stop you.&lt;/p&gt;

&lt;p&gt;The idea is simple:&lt;/p&gt;

&lt;p&gt;You try to commit.&lt;/p&gt;

&lt;p&gt;Git says:&lt;/p&gt;

&lt;p&gt;“Wait. Let me check that first.”&lt;/p&gt;
&lt;h3&gt;
  
  
  🔧 example of git hooks pre-commit (gatekeeper)
&lt;/h3&gt;

&lt;p&gt;You create this file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.git/hooks/pre-commit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you add rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Running tests..."&lt;/span&gt;

npm &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"❌ Tests failed. Commit blocked."&lt;/span&gt;
  &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then activate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x .git/hooks/pre-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;What just happened?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You didn’t “add a tool.”&lt;/p&gt;

&lt;p&gt;You added a guard at the door.&lt;/p&gt;

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

&lt;p&gt;tests run automatically&lt;br&gt;
failure = commit rejected&lt;br&gt;
broken code never enters history&lt;/p&gt;

&lt;p&gt;Therefore, there's NO debate anymore. &lt;br&gt;
No “I’ll fix it later” nap issue.  &lt;/p&gt;
&lt;h3&gt;
  
  
  🪫2026 Git Hooks Reality
&lt;/h3&gt;

&lt;p&gt;Nowadays most teams don’t hand-write hooks anymore.&lt;/p&gt;

&lt;p&gt;They use tools:&lt;/p&gt;

&lt;p&gt;they use &lt;strong&gt;&lt;a href="https://typicode.github.io/husky/" rel="noopener noreferrer"&gt;Husky&lt;/a&gt;&lt;/strong&gt; to manage hooks cleanly&lt;/p&gt;

&lt;p&gt;or &lt;strong&gt;&lt;a href="https://github.com/lint-staged/lint-staged" rel="noopener noreferrer"&gt;lint-staged&lt;/a&gt;&lt;/strong&gt; to run checks only on changed files&lt;/p&gt;

&lt;p&gt;Because raw hooks don’t scale well.&lt;/p&gt;

&lt;p&gt;Tools make it consistent.&lt;/p&gt;
&lt;h3&gt;
  
  
  Important truth most tutorials skip
&lt;/h3&gt;

&lt;p&gt;Local hooks are not secure.&lt;/p&gt;

&lt;p&gt;Anyone can bypass them:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit --no-verify&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And everything gets ignored. &lt;br&gt;
So if you rely ONLY on local hooks you're mistaken.&lt;/p&gt;

&lt;p&gt;So hooks alone are not enough. &lt;br&gt;
Let me explain why..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real system (what professionals use):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You combine two layers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Local hooks&lt;/strong&gt; (Fast feedback. Instant rejection.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. CI/CD pipelines&lt;/strong&gt; (GitHub Actions, etc.)&lt;/p&gt;

&lt;p&gt;SO&lt;br&gt;
⚡Local = speed&lt;br&gt;
⚖️ Server = enforcement&lt;/p&gt;

&lt;p&gt;Local catches mistakes early.&lt;br&gt;
Server enforces rules for everyone.&lt;/p&gt;

&lt;p&gt;Together,nothing broken gets through. YOU WIN. &lt;/p&gt;


&lt;h2&gt;
  
  
  🍋‍🟩🪞 7) Commit References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9o4souqlws906nvj5i34.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%2F9o4souqlws906nvj5i34.png" alt="Image description  7) Commit References" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;beginners copy full commit hashes like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;a3f9c1d8b7e...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Long. Ugly. Useless in daily work.&lt;/p&gt;

&lt;p&gt;You don’t need that noise.&lt;/p&gt;
&lt;h3&gt;
  
  
  🔧 Core Commands
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff HEAD~2..HEAD
git rev-parse &lt;span class="nt"&gt;--short&lt;/span&gt; HEAD
git tag &lt;span class="nt"&gt;-a&lt;/span&gt; v2.0 &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Release v2.0"&lt;/span&gt;
git push origin v2.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;-- &lt;code&gt;HEAD~2..HEAD&lt;/code&gt; = compare recent changes &lt;/p&gt;

&lt;p&gt;-- &lt;code&gt;rev-parse --short HEAD&lt;/code&gt; = quick reference (human-friendly ID)&lt;/p&gt;

&lt;p&gt;-- &lt;code&gt;tag -a&lt;/code&gt; = mark a stable checkpoint (this matters)&lt;/p&gt;

&lt;p&gt;-- &lt;code&gt;push origin v2.0&lt;/code&gt; = share that checkpoint with the world&lt;/p&gt;
&lt;h3&gt;
  
  
  🧠 Understand this properly
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;HEAD&lt;/code&gt; = where you are&lt;br&gt;
&lt;code&gt;HEAD~1&lt;/code&gt; = one step back&lt;br&gt;
&lt;code&gt;HEAD~2&lt;/code&gt; = two steps back&lt;/p&gt;

&lt;p&gt;You’re not memorizing hashes anymore.&lt;/p&gt;

&lt;p&gt;You’re jumping up/down in a timeline. its super productive.&lt;/p&gt;
&lt;h3&gt;
  
  
  🆔 Why Tags Actually Matter??
&lt;/h3&gt;

&lt;p&gt;Tags are not decoration.&lt;/p&gt;

&lt;p&gt;They are &lt;strong&gt;anchors.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag &lt;span class="nt"&gt;-a&lt;/span&gt; v2.0 &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Release v2.0"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re declaring:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This version is stable. This is deployable.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now your CI/CD pipelines + Deployment systems and AI tools&lt;/p&gt;

&lt;p&gt;All know exactly &lt;strong&gt;what to ship.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;NOTE: ⚠️ Fix this weak idea&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Full hashes are sh$t”&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;&lt;strong&gt;Blind usage is actual sh$t.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Full hashes are for finding exact location, scripting and debugging critical issues,&lt;/p&gt;

&lt;p&gt;Short refs are for &lt;strong&gt;speed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Know both.&lt;/p&gt;




&lt;h2&gt;
  
  
  8) 🧳Stash [Pause Work Without Panic]
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94bsczid7fk7ljp1wwll.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%2F94bsczid7fk7ljp1wwll.png" alt="Image description 8) 🧳 Stash [Pause Work Without Panic]" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Interruptions are coming.&lt;/p&gt;

&lt;p&gt;Boss calls. Bug report drops. Production is on fire.&lt;/p&gt;

&lt;p&gt;And you’re sitting there with half-written code…&lt;/p&gt;

&lt;p&gt;Now what?&lt;/p&gt;

&lt;p&gt;Commit garbage?&lt;br&gt;
Lose your work?&lt;br&gt;
Panic?&lt;/p&gt;

&lt;p&gt;NO.. professionals don’t panic&lt;/p&gt;

&lt;p&gt;They &lt;code&gt;stash&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What stash actually is?
&lt;/h3&gt;

&lt;p&gt;Stash is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Save everything I’m doing right now… and bring me back to a clean state.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No commit. No history pollution.&lt;/p&gt;

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

&lt;p&gt;EXAMPLE:&lt;/p&gt;

&lt;p&gt;Let say you’re working on a feature.&lt;/p&gt;

&lt;p&gt;Suddenly you recieved a message from colleage:&lt;/p&gt;

&lt;p&gt;“URGENT: Fix login bug NOW.”&lt;/p&gt;

&lt;p&gt;You don’t argue.&lt;/p&gt;

&lt;p&gt;You run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash push &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"WIP: profile fix"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything disappears.&lt;/p&gt;

&lt;p&gt;Not deleted.&lt;/p&gt;

&lt;p&gt;Just stored safely.&lt;/p&gt;

&lt;p&gt;Your workspace becomes clean again.&lt;/p&gt;

&lt;p&gt;Now switch safely&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch main
git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you fix the urgent issue without your half-work getting in the way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;See what you saved&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git stash list&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It’s like a small vault of paused work.&lt;/p&gt;

&lt;p&gt;Nothing lost. Just parked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Bring it back&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you’re ready:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git stash apply&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your work comes back exactly as it was.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;git stash pop&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Same thing, but removes it from stash after restoring.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advanced move
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash branch hotfix-auth stash@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does something smarter:&lt;/p&gt;

&lt;p&gt;creates a new branch&lt;br&gt;
restores your work there&lt;br&gt;
keeps main branch clean&lt;/p&gt;

&lt;p&gt;So you don’t mix emergency fixes with unfinished features.&lt;/p&gt;

&lt;p&gt;No conflict with main work. &lt;/p&gt;
&lt;h3&gt;
  
  
  ⚠️🛩️ Reality Check
&lt;/h3&gt;

&lt;p&gt;Stash is NOT permanent storage.&lt;/p&gt;

&lt;p&gt;It’s temporary.&lt;/p&gt;

&lt;p&gt;Forget it… and it becomes a graveyard.🪦&lt;/p&gt;

&lt;p&gt;So use it. Don’t hoard it.&lt;/p&gt;
&lt;h3&gt;
  
  
  When to use stash
&lt;/h3&gt;

&lt;p&gt;Use it when:&lt;/p&gt;

&lt;p&gt;you saves unfinished work safely and then switch tasks instantly&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;anytime create a branch from stash (stash branch) for experiment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary.. need to switch tasks mid-flow? &lt;code&gt;Stash&lt;/code&gt; temporarily saves your changes.&lt;/p&gt;


&lt;h2&gt;
  
  
  9) Bisect 🐞
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qlq41rkygwfvfd11of1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qlq41rkygwfvfd11of1.gif" alt="Image description 9) Bisect" width="760" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Manual bug hunting? WEAK MOVE. &lt;/p&gt;

&lt;p&gt;Manual bug hunting is slow.&lt;/p&gt;

&lt;p&gt;And slow means you suffer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Bisect&lt;/code&gt; = sniper rifle for bug hunting.&lt;/p&gt;

&lt;p&gt;Think now: something breaks in production.&lt;/p&gt;

&lt;p&gt;Login stops working.&lt;/p&gt;

&lt;p&gt;No logs. No clear reason.&lt;/p&gt;

&lt;p&gt;Only one truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It worked yesterday. It’s broken today.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And now you have 50+ commits in between.&lt;/p&gt;

&lt;p&gt;Amateurs go to sleep.&lt;/p&gt;

&lt;p&gt;Professionals starts hunting.&lt;/p&gt;

&lt;p&gt;So what's the solution? you divide the problem.&lt;/p&gt;

&lt;p&gt;you use &lt;code&gt;bisect&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git bisect start      &lt;span class="c"&gt;# Begin the hunt&lt;/span&gt;
git bisect bad        &lt;span class="c"&gt;# Current version is broken&lt;/span&gt;
git bisect good v2.1  &lt;span class="c"&gt;# Last known good version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How the process works
&lt;/h3&gt;

&lt;p&gt;You test the code.&lt;/p&gt;

&lt;p&gt;Then you answer only two things:&lt;/p&gt;

&lt;p&gt;works = git bisect good&lt;br&gt;
broken = git bisect bad&lt;/p&gt;

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

&lt;p&gt;Git keeps cutting the search space in half.&lt;/p&gt;

&lt;p&gt;Again. And again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this is powerful?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;50 commits becomes&lt;/p&gt;

&lt;p&gt;~6 checks.&lt;/p&gt;

&lt;p&gt;its called the power of &lt;em&gt;&lt;a href="https://git-scm.com/docs/git-bisect" rel="noopener noreferrer"&gt;binary search&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  🔥 Now Finish the Bug Hunting mission
&lt;/h3&gt;

&lt;p&gt;When the bug is found:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git bisect reset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back to normal.&lt;/p&gt;

&lt;p&gt;Bug identified.&lt;/p&gt;

&lt;p&gt;Target eliminated. ☠️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡Tips:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can automate the entire hunt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git bisect run npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Git runs your tests automatically on each step.&lt;/p&gt;

&lt;p&gt;No manual checking.&lt;/p&gt;

&lt;p&gt;No human error.&lt;/p&gt;

&lt;p&gt;You just sit back and watch it find the culprit like &lt;a href="https://try.quillbot.com/bc5dxz39okqk" rel="noopener noreferrer"&gt;quillbot&lt;/a&gt; ;).&lt;/p&gt;

&lt;p&gt;NOTE: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Bisect&lt;/code&gt; only works if:&lt;/p&gt;

&lt;p&gt;you hAve a known good version&lt;br&gt;
your tests actually work&lt;/p&gt;

&lt;p&gt;If your tests are broken, bisect becomes useless.&lt;/p&gt;


&lt;h2&gt;
  
  
  10) 🧑‍🦯‍➡️ Don’t Merge Blindly
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzm7sb1pu43l9jkqmqtgl.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%2Fzm7sb1pu43l9jkqmqtgl.png" alt="Image description 10) Don’t Merge Blindly" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ve got a &lt;code&gt;feature-cat&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;It “works on your machine.”&lt;/p&gt;

&lt;p&gt;Now you’re about to merge into &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And you’re thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Should be fine.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That sentence along has destroyed more codebases than bugs ever did.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rule #1) Check What files are changing
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff &lt;span class="nt"&gt;--name-only&lt;/span&gt; main..feature-cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is your first reality check.&lt;/p&gt;

&lt;p&gt;It shows exactly what will be affected.&lt;/p&gt;
&lt;h3&gt;
  
  
  Rule #2) What actually changed
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff &lt;span class="nt"&gt;--color-words&lt;/span&gt; main..feature-cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now you see the real story.&lt;/p&gt;

&lt;p&gt;Not “files changed”.&lt;/p&gt;

&lt;p&gt;But what inside those files changed.&lt;/p&gt;

&lt;p&gt;This is where bad merges get exposed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two ways to compare branches:&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;git diff main..feature-cat
git diff main...feature-cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two-dot vs Three-dot:&lt;/p&gt;

&lt;p&gt;-- &lt;code&gt;..&lt;/code&gt;  = direct comparison (simple view)&lt;br&gt;
-- &lt;code&gt;...&lt;/code&gt; =true branch difference (REAL merge view)&lt;/p&gt;

&lt;p&gt;Most people never learn this difference.&lt;/p&gt;

&lt;p&gt;And that’s exactly why they merge wrong.&lt;/p&gt;

&lt;p&gt;Before merge, you don’t ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Will this work?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What exactly am I about to change?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To sum up, know the battlefield before the fight. &lt;/p&gt;

&lt;p&gt;Compare first, merge second. &lt;/p&gt;


&lt;h2&gt;
  
  
  🫳 11) Cherry-Pick (pick ONLY What You Need)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ukqn7hq7ub7n6cibnn5.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%2F0ukqn7hq7ub7n6cibnn5.png" alt="Image description 11) Cherry-Pick (pick ONLY What You Need)" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes you only need ONE commit from another branch.&lt;/p&gt;

&lt;p&gt;You Merging entire branches for one fix?&lt;/p&gt;

&lt;p&gt;That’s how you import bugs you NEVER asked for. &lt;/p&gt;

&lt;p&gt;lets cherry-pick..&lt;/p&gt;

&lt;p&gt;Real Case scenario:&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;feature-login&lt;/code&gt; branch has 10 commits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;LoginUI.tsx&lt;/code&gt; redesign ❌&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;authStyles.css&lt;/code&gt; change UI ❌&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useAuth.ts&lt;/code&gt; refactor ❌&lt;/li&gt;
&lt;li&gt;✅ Fix: token refresh bug (&lt;code&gt;authService.ts&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Production is breaking.&lt;/p&gt;

&lt;p&gt;Users getting logged out every 5 minutes.&lt;/p&gt;

&lt;p&gt;You don’t need UI changes.&lt;br&gt;
You don't need refactor.&lt;/p&gt;

&lt;p&gt;BUT you need that ONE fix: token refresh bug in &lt;code&gt;authService.ts&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  💆 Step 1: Find the exact commit
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; feature-login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;a1b2c3d fix: refresh token expiry bug &lt;span class="k"&gt;in &lt;/span&gt;authService
f4e5d6c refactor: auth hooks
9a8b7c6 style: login UI update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You take the one that matters: 👉 &lt;code&gt;a1b2c3d&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🩺 Step 2: Surgical extraction
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git pull
git cherry-pick a1b2c3d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now only this change is applied:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;authService.ts → FIXED
Everything else → untouched
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No UI risk. No side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔨 Step 3: Clean it like a pro
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git cherry-pick &lt;span class="nt"&gt;-e&lt;/span&gt; a1b2c3d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update message:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;fix(auth): resolve token refresh logout issue (hotfix)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now your history makes sense to your team + your CI/CD pipeline&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🙎‍♂️What just happened after that 3 steps workflow??&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-- Bug reported in production&lt;br&gt;
-- You located the fix commit&lt;br&gt;
-- You shipped ONLY the fix&lt;br&gt;
-- You avoided merging unstable work&lt;/p&gt;

&lt;p&gt;This is how senior SWE teams move fast &lt;strong&gt;without breaking things.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But hey.. this is also where juniors get destroyed&lt;/p&gt;

&lt;p&gt;Cherry-pick can bite you if you have:&lt;/p&gt;

&lt;p&gt;-- Same fix exists in two branches later&lt;br&gt;
-- Merge conflicts when syncing branches&lt;br&gt;
-- Duplicate commits + confusing history&lt;/p&gt;

&lt;p&gt;You didn’t remove the problem.&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;copied the solution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Big difference.&lt;/p&gt;
&lt;h3&gt;
  
  
  🧠 So when cherry-pick is the RIGHT move?
&lt;/h3&gt;

&lt;p&gt;Use cherry-pick when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚨 Production hotfix&lt;/li&gt;
&lt;li&gt;🎯 One isolated commit&lt;/li&gt;
&lt;li&gt;⛔ Full merge is risky&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌆 You need long-term branch sync&lt;/li&gt;
&lt;li&gt;♾️ You’re patching randomly without plan&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧱 12) Git Add
&lt;/h2&gt;

&lt;p&gt;If you think &lt;em&gt;git mistakes happen&lt;/em&gt; during commits.&lt;/p&gt;

&lt;p&gt;You're wrong.&lt;/p&gt;

&lt;p&gt;They happen &lt;strong&gt;before that&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At staging.&lt;/p&gt;

&lt;p&gt;You worked on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;login.js&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;profile.js&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;utils.js&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only &lt;code&gt;login.js&lt;/code&gt; is ready.&lt;/p&gt;

&lt;p&gt;But only amateurs do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And suddenly:&lt;/p&gt;

&lt;p&gt;/ half-finished code enters history&lt;br&gt;
/ unrelated changes get bundled&lt;br&gt;
/ reviews become useless&lt;br&gt;
/ AI gets confused&lt;br&gt;
/ debugging becomes harder later&lt;/p&gt;

&lt;p&gt;That’s how conflicts starts.&lt;/p&gt;
&lt;h3&gt;
  
  
  🧑‍⚕️Professional workflow
&lt;/h3&gt;

&lt;p&gt;You don’t &lt;code&gt;git add .&lt;/code&gt; everything.&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;choose what deserves to exist in history.&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;git add &lt;span class="nt"&gt;-p&lt;/span&gt; login.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Stage only specific parts of a file&lt;br&gt;
👉 Build clean, intentional commits&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 Preview before committing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Shows what &lt;em&gt;would&lt;/em&gt; be staged&lt;/p&gt;

&lt;h3&gt;
  
  
  ⚠️ Advanced control (use carefully)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nt"&gt;--force&lt;/span&gt; .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Used only when you intentionally need ignored files&lt;br&gt;
👉 Dangerous if you don’t understand why&lt;/p&gt;

&lt;p&gt;Staging is not “pre-commit.”&lt;/p&gt;

&lt;p&gt;It is &lt;strong&gt;decision-making.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are deciding:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What deserves to become history?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✍️ NOTE:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Amateurs commit everything and fix later. Professionals stage with intention and never create havoc in the first place.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




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

&lt;p&gt;Git is not complicated. &lt;/p&gt;

&lt;p&gt;Most of the commands above aren’t even complicated. &lt;/p&gt;

&lt;p&gt;They just force you to slow down at the right moments.&lt;/p&gt;

&lt;p&gt;It becomes messy when you stop paying attention.&lt;/p&gt;

&lt;p&gt;After a while, you stop thinking in commands and start thinking in states:&lt;/p&gt;

&lt;p&gt;what changed, what matters, and what should actually be saved.&lt;/p&gt;

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

&lt;p&gt;Hope you find this article useful. let me know in the comments section what  you have learned so far. Its great to hear. Cheers 🥂&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📘 Recommendations:&lt;/strong&gt; &lt;strong&gt;&lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Git is a tool. it handles history. &lt;em&gt;Clean Code&lt;/em&gt; handles everything inside that history. Developers don’t fail because of Git. They fail because the code itself becomes way too HARD to manage. If you fix that part early, Git becomes your oblige coworker.&lt;/p&gt;

&lt;p&gt;use code: &lt;code&gt;POWER40&lt;/code&gt; 40% OFF for one week.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;👉 Clean Code Zero to One&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;for those building apps &lt;a href="https://get.brightdata.com/codewithshahan-scraping-browser" rel="noopener noreferrer"&gt;Bright Data&lt;/a&gt; takes care of your data: proxies, scraping, data pipelines, all handled. You build. It runs on your behalf.&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>git</category>
      <category>programming</category>
    </item>
    <item>
      <title>10 hard truths EVERY DEV must learn in 2025</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Wed, 09 Apr 2025 17:26:43 +0000</pubDate>
      <link>https://dev.to/codewithshahan/10-hard-truths-every-dev-must-learn-in-2025-26io</link>
      <guid>https://dev.to/codewithshahan/10-hard-truths-every-dev-must-learn-in-2025-26io</guid>
      <description>&lt;p&gt;I've been in the coding game for 5 years.&lt;/p&gt;

&lt;p&gt;Written messy code.&lt;/p&gt;

&lt;p&gt;Struggled with debugging nightmares.&lt;/p&gt;

&lt;p&gt;Made dumb mistakes.&lt;/p&gt;

&lt;p&gt;Learned the hard way.&lt;/p&gt;

&lt;p&gt;Here are the cold, hard lessons I had to learn the hard way (every developer must learn)...&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Looks help but they’re not everything.
&lt;/h2&gt;

&lt;p&gt;I remember when I first started using AI code assistants. I thought once I had them, coding would be effortless.&lt;/p&gt;

&lt;p&gt;They provided suggestions, completed lines... but my projects still had issues. Because I still lacked the understanding of clean code principles. AI tools got me started, but my lack of foundational knowledge closed doors just as fast.&lt;/p&gt;

&lt;p&gt;What I learned is this: AI tools don’t just respond to what you input; they amplify your existing coding habits. A developer who codes with clarity, who structures functions with purpose, who doesn’t rely solely on AI -- that developer will outperform someone who blindly follows AI suggestions every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. If you’re always chasing, you’re not in control.
&lt;/h2&gt;

&lt;p&gt;This one stung. I used to think effort was everything. If I just kept tweaking and adding features, the code would improve. So, I’d refactor endlessly, integrate every new library, follow every trend... and I ended up with bloated, unmanageable codebases.&lt;/p&gt;

&lt;p&gt;Because when you’re doing 90% of the work without a clear direction, you’re not developing; you’re floundering. Real progress is intentional. If a feature truly adds value, it will integrate seamlessly. Stop chasing every new tool or framework that barely fits your project. Start valuing simplicity and purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Your purpose is more attractive than your tools.
&lt;/h2&gt;

&lt;p&gt;I had phases where I’d focus all my energy on mastering the latest coding tools. Everything revolved around having the newest gadgets in my developer toolkit. I’d spend hours customizing my IDE, setting up complex workflows... and I got nowhere.&lt;/p&gt;

&lt;p&gt;But when I locked in on my goals—building meaningful projects, solving real problems—when I was too busy creating to constantly tweak my setup, suddenly my work stood out.&lt;/p&gt;

&lt;p&gt;Clients and peers would say, “You’re different,” “You’re focused,” “You’ve got something going.” That’s when I realized: developers who chase purpose attract recognition without even trying. Because that energy is rare, and people feel it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. I’ve learned to stop coding so much.
&lt;/h2&gt;

&lt;p&gt;Early on, I thought I had to prove myself. I’d over-engineer. Add unnecessary complexity. Implement features no one asked for. It came off as overcompensation and it killed project momentum.&lt;/p&gt;

&lt;p&gt;I started studying minimalism in code, the beauty of simplicity. I realized users notice everything.&lt;/p&gt;

&lt;p&gt;The way an application flows. The intuitiveness of the interface. The speed of execution. A developer who can deliver powerful functionality with clean, simple code is a developer who gets attention. Simplicity is power. Let your code speak for itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Your past code matters.
&lt;/h2&gt;

&lt;p&gt;I worked on projects where I ignored my previous mistakes—spaghetti code, lack of documentation, poor structure — and I told myself, “I’ll do better next time.” I wanted to move forward without addressing the past. I couldn’t. I became trapped in a cycle of repeating errors.&lt;/p&gt;

&lt;p&gt;A developer’s past work is a preview of their future. It doesn’t mean you have to be perfect, but you do need accountability. You need to learn and grow. If all your past projects were chaotic, ask why you approached them that way. If you consistently avoided testing and documentation, ask what that means for your development process.&lt;/p&gt;

&lt;p&gt;Don’t ignore the signs just because you’re eager to move on.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Not every tool is worth your time.
&lt;/h2&gt;

&lt;p&gt;When I was younger, I treated every new framework or library as a must-learn. If it was popular, that was enough. I’d ignore its relevance to my work, its learning curve, its community support—just to have it on my resume. I paid for it every time.&lt;/p&gt;

&lt;p&gt;Now? I care more about effectiveness than trendiness.&lt;/p&gt;

&lt;p&gt;Does this tool solve a problem I have? Does it integrate well with my existing stack? Does it have long-term viability? If it’s just trendy but brings nothing substantial, I pass. My time is valuable. My focus is sacred. And not every tool deserves attention.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. The less you rely, the better things go.
&lt;/h2&gt;

&lt;p&gt;This doesn’t mean rejecting help or tools. It means independence. I used to depend heavily on AI code assistants. Let them dictate my coding style. Follow their suggestions blindly. But when I stopped relying so much—when I focused on understanding, improving, and staying grounded—things shifted.&lt;/p&gt;

&lt;p&gt;My code became cleaner. My problem-solving skills sharpened. And ironically, that’s what made me a better developer. The one who can code without assistance holds the power. Not out of arrogance but out of competence.&lt;/p&gt;

&lt;p&gt;Clean code isn’t optional... it’s your edge. AI can’t fix chaos. If your code is unreadable, your future’s unstable. I learned the hard way. You don’t have to. Grab my book "Clean Code Zero to One" on Gumroad and level up forever:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxls5d3vkg4jgu7oezfn.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%2Ffxls5d3vkg4jgu7oezfn.png" alt="Image of clean code zero to one book by shahan" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📘: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;https://codewithshahan.gumroad.com/l/cleancode-zero-to-one&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Being a “yes developer” doesn’t work.
&lt;/h2&gt;

&lt;p&gt;I used to think agreeing to every feature request was the way to please clients. I’d say yes to everything, avoid pushing back, always accommodate. It made me overworked.&lt;/p&gt;

&lt;p&gt;Even worse—it made me look unprofessional.&lt;/p&gt;

&lt;p&gt;Clients don’t want a pushover. They want a professional with a backbone. Someone who sets boundaries. Someone who’s accommodating but not afraid to say no. Someone who makes informed decisions.&lt;/p&gt;

&lt;p&gt;Be a good developer but don’t be a submissive one. There’s a difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Comments are cool, but clarity is better.
&lt;/h2&gt;

&lt;p&gt;“// This function calculates the sum.” Blah, blah, blah. Every developer writes that. But the one who names the function calculateSum()... who structures code so its purpose is self-evident... who doesn’t rely on excessive comments to explain convoluted logic—that’s the developer whose code is respected.&lt;/p&gt;

&lt;p&gt;Clarity isn’t verbose. It’s in the structure, the naming, the organization. I stopped trying to explain my code with comments and started writing code that needed no explanation. That’s when my work became exemplary.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Your project should add to your life, not be your life.
&lt;/h2&gt;

&lt;p&gt;I’ve taken on projects where I lost myself. I stopped learning new skills. Stopped networking. Stopped pursuing personal growth. And every time, it ended with regret.&lt;/p&gt;

&lt;p&gt;That's all for today. Hope you learned something new. Feel free to follow me and subscribe to my weekly &lt;a href="https://Horsecoder.beehiiv.com/" rel="noopener noreferrer"&gt;horsecoder newsletter&lt;/a&gt; for the latest updates. &lt;/p&gt;




&lt;p&gt;&lt;em&gt;🏖️ This article is sponsored by &lt;a href="https://fntechsolution.com/" rel="noopener noreferrer"&gt;FN Tech Solution&lt;/a&gt;, where you can find people to do marketing for you: create apps/websites/designs, grow your business, and more.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌱🗃️ More Learning Resources:&lt;/strong&gt;&lt;br&gt;
📘 My Book: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;&lt;br&gt;
📹 YouTube: &lt;a href="https://www.youtube.com/programmingwithshahan" rel="noopener noreferrer"&gt;Programming with Shahan&lt;/a&gt;&lt;br&gt;
🩻 𝕏: &lt;a href="https://x.com/shahancd" rel="noopener noreferrer"&gt;shahancd&lt;/a&gt;&lt;br&gt;
🌐 Website: &lt;a href="http://codewithshahan.com/" rel="noopener noreferrer"&gt;codewithshahan.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>ai</category>
    </item>
    <item>
      <title>How to land your first frontend job (11 Rules!)</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Sat, 15 Mar 2025 23:55:40 +0000</pubDate>
      <link>https://dev.to/codewithshahan/11-rules-to-land-your-first-frontend-job-3h53</link>
      <guid>https://dev.to/codewithshahan/11-rules-to-land-your-first-frontend-job-3h53</guid>
      <description>&lt;p&gt;You wanna land your first front-end job in 2025? You think slapping together a few React components and calling yourself a "developer" is enough? News flash: it's not.&lt;/p&gt;

&lt;p&gt;Most of you are out here writing spaghetti code, hoping some company will bless you with a job. Wrong. Employers want weapons—clean, scalable, maintainable code machines. You follow these 11 rules, and you’ll have hiring managers fighting over you. Ignore them? Enjoy your job at McJavaScript's.&lt;/p&gt;

&lt;p&gt;Let’s get into it&lt;/p&gt;

&lt;h2&gt;
  
  
  📽️ 1. Not building projects
&lt;/h2&gt;

&lt;p&gt;If you really want to know how far you have come, create real-world projects. A simple quiz app can be entertaining to start with. &lt;/p&gt;

&lt;p&gt;Make sure to resist the temptation to copy code. Do it from scratch.&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;// A simple quiz app with array-based questions&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;questions&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="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;What does HTML stand for?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HyperText Markup Language&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="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;What is the output of 2+2 in 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;answer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;startQuiz&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;q&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userAnswer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prompt&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;userAnswer&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;userAnswer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Your score is: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;startQuiz&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🍽️ 2. Choose Your Learning Resources Wisely
&lt;/h2&gt;

&lt;p&gt;You want to read every tutorial, watch every video, jump on every trendy platform. That’s a &lt;strong&gt;crime&lt;/strong&gt; in software development. &lt;/p&gt;

&lt;p&gt;Pick &lt;strong&gt;one or two&lt;/strong&gt; solid resources/courses. Stick to them until you grasp critical concepts 100%.&lt;/p&gt;

&lt;p&gt;You are not gonna make it unless you grasp these two principles of learning coding online: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🫗 Jumping around too much = zero progress.
&lt;/li&gt;
&lt;li&gt;🌴 A single consistent source builds a strong mental framework.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🪛 3. Start with the Basics
&lt;/h2&gt;

&lt;p&gt;Most devs want to build an entire e-commerce platform on Day One.&lt;/p&gt;

&lt;p&gt;Don’t. It’s like trying to fight a heavyweight champion before you’ve thrown your first punch.&lt;/p&gt;

&lt;p&gt;Build hundreds of small projects with pure HTML, CSS, and plain JavaScript. &lt;/p&gt;

&lt;p&gt;Then choose a front-end framework like Vue.js, Angular or React.js and stick with it. Master them, and everything else is easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  🐣 4. Begin with Easy Projects
&lt;/h2&gt;

&lt;p&gt;You want to jump into a giant game or a social media clone? &lt;/p&gt;

&lt;p&gt;Resist. Start small. A to-do list, a simple calculator, or a color picker. &lt;/p&gt;

&lt;p&gt;These little wins matter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👇 Easy Project Example (Color Picker):&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;colorInput&lt;/span&gt; &lt;span class="o"&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="s2"&gt;colorInput&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;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;colorInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colorInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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;One input, one background change. Easy. But it cements your knowledge.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚤 5. Take Your Time to Learn
&lt;/h2&gt;

&lt;p&gt;Some of you want to “speedrun” coding. Big mistake. &lt;/p&gt;

&lt;p&gt;This is not a race. &lt;/p&gt;

&lt;p&gt;True mastery comes from &lt;strong&gt;slow, deliberate practice&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Don’t sin by rushing. That only leads to half-baked knowledge.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎐 6. Regular Practice Is Good, But Don’t Overdo It
&lt;/h2&gt;

&lt;p&gt;Coding every day is nice, but if you burn out, you’ll crash in the long run. &lt;/p&gt;

&lt;p&gt;Pace yourself. Show up consistently, but take breaks. That’s how you stay hungry without losing your mind.&lt;/p&gt;




&lt;h2&gt;
  
  
  🥞/🍋 7. Stuck on Something? Take a Break
&lt;/h2&gt;

&lt;p&gt;When your code refuses to work, you might feel the urge to fight it for hours. Sometimes, that’s necessary. &lt;/p&gt;

&lt;p&gt;But other times, walk away. Let your mind breathe. Come back fresh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔥 Break Trick&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step away from your desk.
&lt;/li&gt;
&lt;li&gt;Drink water or take a short walk.&lt;/li&gt;
&lt;li&gt;Eat delicious food. I personally do push-ups instead.
&lt;/li&gt;
&lt;li&gt;Fight the bug with a brand new fresh mind.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⛷️ 8. Learn by Doing
&lt;/h2&gt;

&lt;p&gt;Reading docs, watching videos—good. But &lt;strong&gt;if you’re not coding&lt;/strong&gt;, you’re lying to yourself. Real skill is built by typing, failing, debugging, and repeating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💪 Mini-Challenge&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick a small feature from any website you love.
&lt;/li&gt;
&lt;li&gt;Recreate it from scratch in your own code.&lt;/li&gt;
&lt;li&gt;Push to github (your future self will be surprised)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📜 9. Plan Your Projects
&lt;/h2&gt;

&lt;p&gt;Moving into code without a plan is a sin. &lt;/p&gt;

&lt;p&gt;That’s how you end up with spaghetti code and random errors. Sketch a quick layout. Identify data structures. Then code.&lt;/p&gt;

&lt;p&gt;Let me give an example of planning a Note App prior to writing code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt;: Where to store notes (array, localStorage?).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functions&lt;/strong&gt;: &lt;code&gt;addNote()&lt;/code&gt;, &lt;code&gt;deleteNote()&lt;/code&gt;, &lt;code&gt;displayNotes()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI&lt;/strong&gt;: Minimal HTML to show notes in a list. &lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🏎️ 10. Focus on Quality, Not Speed
&lt;/h2&gt;

&lt;p&gt;Speed is tempting. “Let me build this in one night!” Then you brag about it. But your code is a big mess. Always breaks, and most often, the entire project collapses. &lt;/p&gt;

&lt;p&gt;That’s the result of short-term glory. &lt;/p&gt;

&lt;p&gt;Real devs write maintainable code. They think about the future. That's why writing clean code matters more than anything in the tech industry. &lt;/p&gt;

&lt;p&gt;The reason most software companies fire these types of devs is clear:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Poor code 🆚 Clean Code&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="c1"&gt;// Poor code: Hard-coded, zero flexibility&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;tax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;tax&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Clean code: Configurable, easy to adapt&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcPrice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;basePrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&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;📘 Grab my book, &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt; to master clean coding strategies and join a few who truly can write adaptable, maintainable software. &lt;/p&gt;




&lt;h2&gt;
  
  
  🧘‍♂️ 11. Be Patient with Your Learning
&lt;/h2&gt;

&lt;p&gt;You see others landing big dev jobs. You panic. Stop comparing. Your path is your own. Focus on your front-end path and complete your 6-month or 1-year commitment regardless how you feel.   &lt;/p&gt;

&lt;p&gt;This is how all devs find their first life-changing job. &lt;br&gt;
Consistency is the key. Be patient.&lt;/p&gt;




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

&lt;p&gt;Coding is a journey, not a sprint. &lt;/p&gt;

&lt;p&gt;Don’t let mistakes or slow progress discourage you. &lt;br&gt;
Fight through the struggle. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🛬 The more you resist the temptation to quit, the closer you are to landing your dream job.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Now Go Build Something and build it right.&lt;/strong&gt; &lt;br&gt;
That’s the ONLY way you survive in this game. &lt;/p&gt;

&lt;p&gt;Happy coding and share your thoughts in the comment section. I would love to hear that.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>career</category>
      <category>webdev</category>
    </item>
    <item>
      <title>9 frontend devs mistakes</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Mon, 10 Mar 2025 18:43:06 +0000</pubDate>
      <link>https://dev.to/codewithshahan/9-frontend-mistakes-beginners-often-make-5am6</link>
      <guid>https://dev.to/codewithshahan/9-frontend-mistakes-beginners-often-make-5am6</guid>
      <description>&lt;p&gt;You’re a newbie? Good. &lt;/p&gt;

&lt;p&gt;That means you have nowhere to go BUT UP. &lt;/p&gt;

&lt;p&gt;it can feel overwhelming. That’s natural.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsq0y4isyf9l2zj0t34g5.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%2Fsq0y4isyf9l2zj0t34g5.png" alt="Image of frontend devs meme trying to keep moving forward illustrated by Shahan Chowdhury" width="800" height="960"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Frontend development is all about &lt;strong&gt;[how well]&lt;/strong&gt; you understand. &lt;/p&gt;

&lt;p&gt;Not how &lt;strong&gt;[fast]&lt;/strong&gt; you learn.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🪜 You either step up and do it right, or you watch your code breaks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 Let me walk you through the biggest mistakes beginner frontend devs ever make, and &lt;u&gt;how to avoid them&lt;/u&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. 🤧 NOT Optimizing Images
&lt;/h2&gt;

&lt;p&gt;Some of you test locally on a blazing-fast machine. &lt;/p&gt;

&lt;p&gt;You forget real users have slower networks. &lt;/p&gt;

&lt;p&gt;Some devs are too lazy to think about their users. &lt;/p&gt;

&lt;p&gt;Let me get it straight: A 6MB image shrunk to 200px is a SIN. &lt;/p&gt;

&lt;p&gt;Optimize your images. Every. Single. Time.&lt;/p&gt;

&lt;p&gt;Some criminal devs try to reduce image file size by using CSS like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* keeps the aspect ratio */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 However, this does not reduce the ACTUAL file size.&lt;/p&gt;

&lt;p&gt;If your image is still 6MB, it will still take a LONG TIME to download CSS just displays it smaller. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What a [BIG WASTE] of bandwidth. 🚮&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;🪧 So, CSS resizing is mostly for layout, not real optimization.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So what is the solution?&lt;/p&gt;

&lt;p&gt;Well, the first solution I would suggest is to use online image compressor tools. &lt;/p&gt;

&lt;p&gt;I found &lt;a href="https://tinypng.com/" rel="noopener noreferrer"&gt;tinypng&lt;/a&gt; is a great tool for optimizing website images without reducing their quality. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4q0x1w2ivqnxjs258wwe.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%2F4q0x1w2ivqnxjs258wwe.png" alt="Image of tiny png online image compressor" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see my photo file size reduced to -75% (4mb to 890kb); that's crazy. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚡ Compressed images = faster load times = happy users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;⚠️ Warning:&lt;/strong&gt; DO NOT &lt;em&gt;compress&lt;/em&gt; images for &lt;strong&gt;[larger screens]&lt;/strong&gt;. Use HTML &lt;code&gt;srcset&lt;/code&gt; attribute instead:&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;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Responsive Images Example&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- 
    The browser will pick the most appropriate image based on 
    the user's device width. 
    - "small.jpg" is for screens up to ~400px wide
    - "medium.jpg" is for screens up to ~800px wide
    - "large.jpg" is for anything bigger

    Each file is physically smaller in size, so smaller devices 
    don't waste bandwidth on huge images.
  --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt;
    &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"images/large.jpg"&lt;/span&gt;
    &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A beautiful scenic view"&lt;/span&gt;
    &lt;span class="na"&gt;srcset=&lt;/span&gt;&lt;span class="s"&gt;"
      images/small.jpg   400w,
      images/medium.jpg  800w,
      images/large.jpg   1200w
    "&lt;/span&gt;
    &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"
      (max-width: 400px)  400px,
      (max-width: 800px)  800px,
      1200px
    "&lt;/span&gt;
  &lt;span class="nt"&gt;/&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;h3&gt;
  
  
  🪨🔨 How to Optimize Images Using Node.js?
&lt;/h3&gt;

&lt;p&gt;My second solution would be... use a trustworthy JavaScript library.  &lt;/p&gt;

&lt;p&gt;If you have some experience with Node.js, then here is a popular Node.js library to optimize image without reducing quality: &lt;a href="https://www.npmjs.com/package/sharp" rel="noopener noreferrer"&gt;Sharp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👇 Here’s how to use 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;sharp&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="s2"&gt;sharp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;sharp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;large-image.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// The original, large file&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;// Shrink dimensions&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jpeg&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="na"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// Convert to JPEG with 80% quality&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;optimized-image.jpg&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="nf"&gt;then&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Image optimized successfully!&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="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error optimizing image:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;
  
  
  2. 🥸 Using Inline Styles
&lt;/h2&gt;

&lt;p&gt;Let's say you're working on a website that has &lt;strong&gt;[10 job offers]&lt;/strong&gt; listed. You want them to be red to catch the user’s eye.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzysa3dye6rennk6bhph.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzysa3dye6rennk6bhph.gif" alt="gif hard working octopus" width="375" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👇 You took the easy path:&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="c"&gt;&amp;lt;!-- Inline style approach --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/123"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"color: red;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Junior Developer&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/456"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"color: red;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Frontend Engineer&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/789"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"color: red;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Backend Specialist&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- ...and so on for all your job offer links --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, it works. But &lt;strong&gt;the moment&lt;/strong&gt; your boss says:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey dude, make all those links blue instead. My wife hates red.🥱”  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You’re in TROUBLE. &lt;br&gt;
You’d have to edit &lt;strong&gt;[each]&lt;/strong&gt; inline style to &lt;code&gt;color: blue;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If you have 100 links scattered across multiple pages, &lt;br&gt;
that’s a MASSIVE chore. &lt;/p&gt;

&lt;p&gt;That's one of the &lt;strong&gt;[quick-fix traps]&lt;/strong&gt; most devs fall into. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ The CSS-Only Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s do it the &lt;strong&gt;right way&lt;/strong&gt;. You define a simple class in your CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.link-job-offer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* maybe other styles, too */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.link-job-offer&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;darkred&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;👇 Then, in your HTML:&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="c"&gt;&amp;lt;!-- Class-based approach --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/123"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"link-job-offer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Junior Developer&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/456"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"link-job-offer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Frontend Engineer&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/job-offer/789"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"link-job-offer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Backend Specialist&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- ...repeat for all job offer links --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Change one line in &lt;code&gt;.link-job-offer&lt;/code&gt; for a global update. That’s power. &lt;/p&gt;




&lt;h2&gt;
  
  
  3. 🎭 Using Inadequate Heading Tags
&lt;/h2&gt;

&lt;p&gt;Don’t use &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; just because it’s [big and bold]. That’s an SEO sin. &lt;/p&gt;

&lt;p&gt;Headings must reflect hierarchy. If it’s purely decorative, use a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; or a CSS class:&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="c"&gt;&amp;lt;!-- Bad --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"font-size: 50px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Promoted&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Good --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"promo-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Promoted&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then style it in your CSS with &lt;code&gt;.promo-text&lt;/code&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🔥🧯 Don’t sabotage your SEO for a cheap hack.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  4. ❌📲 Ignoring Mobile Media Queries
&lt;/h2&gt;

&lt;p&gt;You tested on desktop? Great. But &lt;strong&gt;[half]&lt;/strong&gt; your users are on mobile. &lt;/p&gt;

&lt;p&gt;If you &lt;em&gt;skip&lt;/em&gt; media queries, you CHEAT half your audience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;It doesn't take much time; you just need to add the following CSS codes:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Mobile first approach */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;95%&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;Resist the lazy mindset. Always check your phone or dev tools. Because if it breaks on mobile, you lose. Your users matter most. &lt;/p&gt;




&lt;h2&gt;
  
  
  5. 🪟 Not Benefitting from Flexbox or CSS Grid
&lt;/h2&gt;

&lt;p&gt;It’s 2025. Floats are archaic. Resist your old habits. Use &lt;strong&gt;flex&lt;/strong&gt; or &lt;strong&gt;grid&lt;/strong&gt;. It’s faster, cleaner, simpler.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.navbar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;🙅‍♂️ No more float nightmares.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. 🗂️ Not Abstracting Elements
&lt;/h2&gt;

&lt;p&gt;If you find yourself reusing &lt;code&gt;.newsletter__title&lt;/code&gt; all over, that’s a sign of mistakes. Abstract it. Make a &lt;code&gt;.section-title&lt;/code&gt; that you can use anywhere. That’s maintainable.&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="c"&gt;&amp;lt;!-- ❌ Wrong Approach: Using .newsletter__title everywhere --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"newsletter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"newsletter__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Subscribe to Our Newsletter&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"blog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"newsletter__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Latest Blog Posts&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Wrong! --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"events"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"newsletter__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Upcoming Events&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Wrong! --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;



&lt;span class="c"&gt;&amp;lt;!-- ✅ Correct Approach: Abstracting with .section-title --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"newsletter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"section-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Subscribe to Our Newsletter&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- and so on... --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  7. 🧹 NOT Removing Redundant Styles
&lt;/h2&gt;

&lt;p&gt;Some of you love to add &lt;code&gt;display: block&lt;/code&gt; and &lt;code&gt;float: right&lt;/code&gt; in the same rule. Or &lt;code&gt;width: 100%&lt;/code&gt; on a block element. &lt;/p&gt;

&lt;p&gt;That’s dead code. Clean it up.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&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;Right:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* automatically block */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🤏 Less is more.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. 🏯 Uppercasing Things in HTML
&lt;/h2&gt;

&lt;p&gt;Typing &lt;code&gt;&amp;lt;h2&amp;gt;JOB OFFERS&amp;lt;/h2&amp;gt;&lt;/code&gt; is the easy route. &lt;/p&gt;

&lt;p&gt;But that’s a sin against separation of concerns. Use CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"section-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Job Offers&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.section-title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;uppercase&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;Done. Now, your text is uppercase only in presentation.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. 💎 NOT Focusing on QUALITY
&lt;/h2&gt;

&lt;p&gt;Speed is tempting. “Let me build this in one night!” Then you brag about it. But your code is a mess. Most often, the entire project collapses. &lt;/p&gt;

&lt;p&gt;That’s the sin of short-term glory. &lt;/p&gt;

&lt;p&gt;Real devs write maintainable code. They think about the future. &lt;/p&gt;

&lt;p&gt;That's why writing clean code matters most in the tech industry. Grab my book &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt; to master this skill and join a few who truly understand everything about clean code. &lt;/p&gt;

&lt;p&gt;The reason most software companies fire these types of devs is clear:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Poor code 🆚 Clean Code&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="c1"&gt;// Poor code: Hard-coded, zero flexibility&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;tax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;tax&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Clean code: Configurable, easy to adapt&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcPrice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;basePrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;basePrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&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;
  
  
  🏁. Conclusion
&lt;/h2&gt;

&lt;p&gt;Frontend dev is a journey, not a sprint. Mistakes happen. That doesn't mean you SHOULD NOT look into them and struggle later. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🥊 Fight through the struggle NOW before it puts you in a painful punishment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding and share your thoughts in the comment section. I would love to hear that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌱🗃️ More Learning Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📘 My Book: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🌐 Website: &lt;a href="https://codewithshahan.com/" rel="noopener noreferrer"&gt;codewithshahan.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🩻 𝕏: &lt;a href="https://x.com/shahancd" rel="noopener noreferrer"&gt;shahancd&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
    </item>
    <item>
      <title>Which JavaScript framework is best (React or Vue in 2025?)</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Thu, 20 Feb 2025 13:34:41 +0000</pubDate>
      <link>https://dev.to/codewithshahan/which-javascript-framework-is-best-react-or-vue-1iaj</link>
      <guid>https://dev.to/codewithshahan/which-javascript-framework-is-best-react-or-vue-1iaj</guid>
      <description>&lt;p&gt;&lt;strong&gt;React vs. Vue.js in 2025, Which One Should You Choose?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React remains one of the most popular JavaScript libraries for building single-page applications in 2025. Meanwhile, Vue.js continues to call itself a “progressive framework” and its popularity skyrocketing day by day. Both share more in common than, say... Angular, which is often considered a “true” framework.&lt;/p&gt;

&lt;p&gt;In this article, I will walk you through a detailed comparison between React.js and Vue.js, updated with the &lt;strong&gt;latest 2025 trends&lt;/strong&gt;, so you can decide which library or framework is best for your next project.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚖️ Framework Overview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnbqn3nz8cpoklyt26e70.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%2Fnbqn3nz8cpoklyt26e70.png" alt="Image of JS framework overview by @codewithshahan" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React&lt;/strong&gt; was created by &lt;a href="https://twitter.com/jordwalke?lang=en" rel="noopener noreferrer"&gt;Jordan Walke&lt;/a&gt;, a software engineer at Facebook (now Meta). It’s maintained by Meta and a large community of individual developers and companies. In 2025, React’s ecosystem is richer than ever, making it a top choice for &lt;strong&gt;building complex user interfaces&lt;/strong&gt; and handling data processing tasks.&lt;/p&gt;

&lt;p&gt;Furthermore, &lt;a href="https://reactnative.dev/" rel="noopener noreferrer"&gt;React Native&lt;/a&gt; remains a popular extension of React.js, allowing developers to create hybrid mobile applications using the same skill set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vue.js&lt;/strong&gt;, on the other hand, was created by &lt;a href="https://twitter.com/youyuxi" rel="noopener noreferrer"&gt;Evan You&lt;/a&gt; after he worked on several Google projects using AngularJS. Vue focuses on simplicity and efficiency in UI design and development. By 2025, its intuitive syntax and built-in features (like transitions and official state management via &lt;a href="https://pinia.vuejs.org/" rel="noopener noreferrer"&gt;Pinia&lt;/a&gt;) have continued to attract developers seeking a &lt;strong&gt;straightforward&lt;/strong&gt; framework for building interfaces.&lt;/p&gt;




&lt;h2&gt;
  
  
  🍏 Reasons for Using Vue.js
&lt;/h2&gt;

&lt;p&gt;Vue.js has maintained its reputation for simplicity. Developers appreciate its &lt;strong&gt;clear and logical design&lt;/strong&gt;, which speeds up development workflows. Unlike some other frameworks, Vue.js retains a consistent syntax throughout UI functionality. That's why I love it personally. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Official Plugins&lt;/strong&gt;: Vue’s core team provides well-structured solutions for common tasks like routing and state management.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Corporate Ownership&lt;/strong&gt;: As of 2025, Vue remains community-driven and independent, appealing to developers wary of data exploitation by large tech companies.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Great Ecosystem&lt;/strong&gt;: Plugins like &lt;a href="https://router.vuejs.org/" rel="noopener noreferrer"&gt;Vue Router&lt;/a&gt; and &lt;a href="https://pinia.vuejs.org/" rel="noopener noreferrer"&gt;Pinia&lt;/a&gt; cover most app needs out of the box.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93sfo44ncmwrkyijv72v.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%2F93sfo44ncmwrkyijv72v.png" alt="Image of vue.js security by @codewithshahan" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚛️ Reasons for Using React
&lt;/h2&gt;

&lt;p&gt;React.js brings unique features that keep it at the top of many developers’ lists (even though its popularity has been declining over time).&lt;/p&gt;

&lt;p&gt;Here is why it is still popular nowadays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JSX Syntax&lt;/strong&gt;: JSX (JavaScript XML) makes creating custom components more intuitive. You can write HTML-like code within JavaScript, streamlining component creation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SEO Support&lt;/strong&gt;: React.js applications are relatively easy to optimize for search engines, especially when combined with frameworks like Next.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Native&lt;/strong&gt;: Developers can reuse their React.js knowledge to build native mobile apps for iOS and Android.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Dev Tools&lt;/strong&gt;: In 2025, the React Developer Tools are more handy than ever, offering deep insights for debugging and organizing complex apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdk077iev1xamzvmdujl5.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%2Fdk077iev1xamzvmdujl5.png" alt="Image of react.js search engine support" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🥇 Comparison of Popularity and Performance
&lt;/h2&gt;

&lt;p&gt;Both React.js and Vue.js remain in high demand in 2025. React has a slight edge in terms of overall popularity, backed by its &lt;strong&gt;extensive ecosystem&lt;/strong&gt; and the community around React Native. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftls7u832ycedn4bw5lkn.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%2Ftls7u832ycedn4bw5lkn.png" alt="Image of react or vue popularity" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Both use a virtual DOM for efficient rendering. Vue.js often shines in component creation and updates due to its super fast optimizations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage Stats&lt;/strong&gt;: According to a 2025 developer survey, over 45% of respondents have used React.js for web development, while around 20% have used Vue.js.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;a href="https://www.appsdevpro.com/blog/vue-vs-react/#:~:text=The%20Statista%20survey%20report%20reveals,for%20web%20development." rel="noopener noreferrer"&gt;The Statista survey report&lt;/a&gt; from previous years still shows React leading in global adoption, though Vue continues to grow steadily.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧊 Scalability
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React.js&lt;/strong&gt; has the idea of “smart” and “dumb” components to manage complex architectures. Smart components handle data-heavy tasks, while dumb components focus on rendering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vue.js&lt;/strong&gt; offers official libraries like &lt;a href="https://blog.logrocket.com/complex-vue-3-state-management-pinia/" rel="noopener noreferrer"&gt;Pinia&lt;/a&gt; for state management, enabling developers to handle larger applications. By 2025, Vue 3+ has proven its ability to scale effectively in enterprise projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  📲 Adjust to Mobile Devices
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffsuvbnikg0qsbrf33vdf.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%2Ffsuvbnikg0qsbrf33vdf.png" alt="Image of react or vue for mobile application development" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both frameworks have a growing demand for cross-platform solutions, although Vue.js is becoming more popular day by day. Let's have a brief overview:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React Native&lt;/strong&gt;: An established leader for building native iOS and Android apps with React.js.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weex (Vue)&lt;/strong&gt;: A mobile UI framework by Alibaba Group, allowing Vue.js components to run on mobile. While not as widespread as React Native, Weex provides a solid Vue-based mobile solution.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚎🔩 Size and Community Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bundle Size&lt;/strong&gt;: Vue.js typically ships with a smaller bundle size, making it ideal for projects prioritizing fast load times.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community&lt;/strong&gt;: React benefits from Meta’s backing and a massive open-source ecosystem. Vue.js, though smaller, boasts an active and dedicated community with thorough documentation and ongoing improvements. I think it's becoming more popular than React.js as recent data suggests. &lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏒 Use Cases
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React.js&lt;/strong&gt;: Perfect for complex web apps, large-scale projects, and teams needing to pivot between web and mobile with React Native.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vue.js&lt;/strong&gt;: Ideal for small to medium-sized apps, real-time platforms, and content delivery systems where simplicity and performance are key.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🏇 Recommendation: Clean Code Book (2025)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd9kfe6mtlt9ttq55da82.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%2Fd9kfe6mtlt9ttq55da82.png" alt="Image of clean code zero to one book" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re serious about mastering clean code and taking your programming career to the next level, then my book for you: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;. I am offering 50% discount using the code "earlybird" during checkout — only for the first 50 copies! Plus, enjoy a 30-day money-back guarantee — no risk, all reward.&lt;/p&gt;




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

&lt;p&gt;I would say React.js is the first choice for developing large and complex apps. Also React Native for mobile apps is a huge plus. But you have to write separate code for web and mobile apps which is a huge downside as well. Therefore, plus-minus = zero. &lt;/p&gt;

&lt;p&gt;Vue.js, meanwhile, is loved for its simplicity, fast performance, and smaller default size. It’s a more lightweight framework without sacrificing modern features. The great news is, you don't have to write separate code for web or mobile. Write once and now you can build desktop, mobile, or web apps in one go. So no downside. Only plus plus. &lt;/p&gt;

&lt;p&gt;I would choose Vue.js for its simplicity and super fast performance.&lt;/p&gt;

&lt;p&gt;Thank you for your time. For more regular posts visit: &lt;a href="http://codewithshahan.com" rel="noopener noreferrer"&gt;codewithshahan.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this, check out my &lt;a href="https://twitter.com/shahancd" rel="noopener noreferrer"&gt;𝕏 (Twitter)&lt;/a&gt; account for more frontend development insights.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Related Articles:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://dev.to/codewithshahan/clean-code-zero-to-one-4ihk"&gt;Clean Code Zero to One&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/codewithshahan/lets-practice-clean-reusable-components-in-react-5flj"&gt;Writing Clean, Reusable React Components (Best Practices)&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Code Optimization for Game Development</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Sun, 16 Feb 2025 05:46:59 +0000</pubDate>
      <link>https://dev.to/codewithshahan/code-optimization-strategies-for-game-development-2n0e</link>
      <guid>https://dev.to/codewithshahan/code-optimization-strategies-for-game-development-2n0e</guid>
      <description>&lt;p&gt;Game development is a battlefield. Either you optimize, or you lose.&lt;/p&gt;

&lt;p&gt;I don’t care if you’re an experienced developer with 10 years of experience or 1 year of experience. If you want to make games that WORK, games people respect—you need to understand &lt;strong&gt;optimization&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Players demand smooth gameplay, high-quality visuals, and a flawless experience across every device. If your game stutters, crashes, or loads slower than a snail? You’re done. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqqz1mqa652edg126c1c.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%2Fdqqz1mqa652edg126c1c.png" alt="Image of slow game development meme" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Optimization isn’t magic. It’s the foundation of smooth gameplay, fast loading, and stable performance. Without it, your game will lag, crash, and be forgotten faster than you can say “game over.”  &lt;/p&gt;

&lt;p&gt;But don’t worry. In this article, I will share four effective strategies to help you with that. &lt;/p&gt;

&lt;h2&gt;
  
  
  Effective Strategies for Performance Optimization
&lt;/h2&gt;

&lt;p&gt;🤸‍♂️ What Is Optimization? Optimization means making your game run as fast and smooth as possible. SIMPLE.&lt;/p&gt;

&lt;p&gt;When you optimize your game, you:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;🤏 Reduce loading times.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🖥️ Make the game work on weaker computers or phones.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;💉 Prevent lag and crashes.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Rule 1: Memory Management&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When you’re developing a game, memory is your most valuable resource.&lt;/p&gt;

&lt;p&gt;Every player movement, every enemy on the screen, every explosion needs a little piece of memory to function. Unfortunately, &lt;strong&gt;memory isn’t unlimited.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you don’t manage memory properly, your game can get slow, laggy, or even crash. That’s why memory management is a critical skill every game developer needs. Let’s break it down step by step, with detailed examples in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy #1: Memory Pooling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This strategy is simple: reuse Objects Instead of Creating New Ones** Memory pooling is like recycling for your game. Instead of creating new objects every time you need one, you reuse objects you’ve already created.  &lt;/p&gt;

&lt;p&gt;Creating and destroying objects repeatedly takes up time and memory. Let's say you are building a shooting game where the player fires 10 bullets per second. If you create a new bullet for each shot, your game could quickly slow down.  &lt;/p&gt;

&lt;p&gt;Here’s how you can implement memory pooling for bullets in a shooting game:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bullet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;  &lt;span class="c1"&gt;# Bullet starts as inactive
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;shoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&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="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;  &lt;span class="c1"&gt;# Activate the bullet
&lt;/span&gt;        &lt;span class="n"&gt;self&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="n"&gt;x&lt;/span&gt;
        &lt;span class="n"&gt;self&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="n"&gt;y&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bullet fired at position (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;  &lt;span class="c1"&gt;# Deactivate the bullet so it can be reused
&lt;/span&gt;
&lt;span class="c1"&gt;# Create a pool of 10 bullets
&lt;/span&gt;&lt;span class="n"&gt;bullet_pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Bullet&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;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fire_bullet&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="c1"&gt;# Look for an inactive bullet in the pool
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;bullet&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bullet_pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;bullet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shoot&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="c1"&gt;# Reuse the inactive bullet
&lt;/span&gt;            &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No bullets available!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# All bullets are in use
&lt;/span&gt;
&lt;span class="c1"&gt;# Example usage
&lt;/span&gt;&lt;span class="nf"&gt;fire_bullet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Fires a bullet at position (10, 20)
&lt;/span&gt;&lt;span class="nf"&gt;fire_bullet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Fires another bullet at position (30, 40)
&lt;/span&gt;&lt;span class="n"&gt;bullet_pool&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# Reset the first bullet
&lt;/span&gt;&lt;span class="nf"&gt;fire_bullet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Reuses the reset bullet
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🍵 Explanation: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;Bullet&lt;/code&gt; Class: Defines what a bullet does and keeps track of whether it’s active (in use) or not.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;bullet_pool&lt;/code&gt;: A list of 10 reusable bullets.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;fire_bullet&lt;/code&gt; Function: Finds an inactive bullet, reuses it, and sets its position.
&lt;/li&gt;
&lt;li&gt;Recycling Bullets: When you’re done with a bullet, you reset it so it can be reused.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy #2. Data Structure Optimization&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The way you store your data can make or break your game’s performance. Choosing the wrong data structure is like trying to carry water in a leaky bucket—it’s inefficient and messy.  &lt;/p&gt;

&lt;p&gt;Let’s say you’re making a game for four players, and you want to keep track of their scores. You could use a list, but a fixed-size array is more efficient because it uses less memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;

&lt;span class="c1"&gt;# Create a fixed-size array to store player scores
&lt;/span&gt;&lt;span class="n"&gt;player_scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;i&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;# 'i' means integers
&lt;/span&gt;
&lt;span class="c1"&gt;# Update scores
&lt;/span&gt;&lt;span class="n"&gt;player_scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;  &lt;span class="c1"&gt;# Player 1 scores 10 points
&lt;/span&gt;&lt;span class="n"&gt;player_scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;  &lt;span class="c1"&gt;# Player 3 scores 15 points
&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;player_scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: array('i', [10, 0, 15, 0])
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🍵 Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The &lt;code&gt;array&lt;/code&gt; Module:&lt;/strong&gt; Creates a fixed-size array of integers (&lt;code&gt;'i'&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed Size:&lt;/strong&gt; You can’t accidentally add or remove elements, which prevents bugs and saves memory.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Updates:&lt;/strong&gt; Updating scores is quick and uses minimal resources.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy #3. Memory Profiling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Even if your code seems perfect, hidden memory problems can still exist. Memory profiling helps you monitor how much memory your game is using and find issues like memory leaks.  &lt;/p&gt;

&lt;p&gt;Python has a built-in tool called &lt;code&gt;tracemalloc&lt;/code&gt; that tracks memory usage. Here’s how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tracemalloc&lt;/span&gt;

&lt;span class="c1"&gt;# Start tracking memory
&lt;/span&gt;&lt;span class="n"&gt;tracemalloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Simulate memory usage
&lt;/span&gt;&lt;span class="n"&gt;large_list&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;  &lt;span class="c1"&gt;# A list of squares
&lt;/span&gt;
&lt;span class="c1"&gt;# Check memory usage
&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tracemalloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_traced_memory&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Current memory usage: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; MB&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Peak memory usage: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; MB&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Stop tracking memory
&lt;/span&gt;&lt;span class="n"&gt;tracemalloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🍵 Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start Tracking:&lt;/strong&gt; &lt;code&gt;tracemalloc.start()&lt;/code&gt; begins monitoring memory usage.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trigger Memory Use:&lt;/strong&gt; Create a large list to use up memory.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Usage:&lt;/strong&gt; Get the current and peak memory usage, converting it to megabytes for readability.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop Tracking:&lt;/strong&gt; &lt;code&gt;tracemalloc.stop()&lt;/code&gt; ends the tracking session.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now it’s your turn to practice these strategies and take your game development skills to the next level!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Rule 2: Asset Streaming (Load Only What You Need)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you load the entire world at once, your game will choke and die. You don’t need that drama. Instead, &lt;strong&gt;stream assets as the player needs them&lt;/strong&gt;. This is called asset streaming. &lt;/p&gt;

&lt;p&gt;For instance, inside your game, you may have a huge open-world with forests, deserts, and cities. Why load all those levels at once when the player is only in the forest? Makes no sense, right? Load &lt;strong&gt;only what’s needed&lt;/strong&gt; and keep your game lean, fast, and smooth.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy #1: Segment and Prioritize&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s break this down with an example. Your player is exploring different levels: Forest, Desert, and City. We’ll only load a level when the player enters it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here’s how to make it work in Python:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;  &lt;span class="c1"&gt;# Starts as unloaded
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loaded&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Loading level: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;  &lt;span class="c1"&gt;# Mark the level as loaded
&lt;/span&gt;
&lt;span class="c1"&gt;# Create levels
&lt;/span&gt;&lt;span class="n"&gt;levels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Forest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Desert&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;City&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;enter_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;level_name&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;level&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;levels&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;level&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;level_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# Load the level if it hasn’t been loaded yet
&lt;/span&gt;            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Entered &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;level_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Level not found!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Handle invalid level names
&lt;/span&gt;
&lt;span class="c1"&gt;# Simulate entering levels
&lt;/span&gt;&lt;span class="nf"&gt;enter_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Forest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Loads and enters the forest
&lt;/span&gt;&lt;span class="nf"&gt;enter_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;City&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# Loads and enters the city
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚡Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Levels Class:&lt;/strong&gt; Each level has a name (e.g., Forest) and a “loaded” status. If it’s loaded, it doesn’t load again.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Loading:&lt;/strong&gt; The &lt;code&gt;enter_level&lt;/code&gt; function finds the level the player wants to enter and loads it only if it hasn’t been loaded yet.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency:&lt;/strong&gt; Levels not visited don’t waste memory. The game runs smoothly because it only focuses on what the player needs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is efficiency at its finest. &lt;strong&gt;No wasted memory, no wasted time.&lt;/strong&gt; Your player moves; your game adapts. That’s how you dominate.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy #2: Asynchronous Loading (No Waiting Allowed)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Nobody likes waiting. Freezing screens? Laggy loading? It’s amateur hour. You need &lt;strong&gt;asynchronous loading&lt;/strong&gt;—this loads assets in the background while your player keeps playing.  &lt;/p&gt;

&lt;p&gt;Imagine downloading a huge map while still exploring the current one. Your game keeps moving, the player stays happy.&lt;/p&gt;

&lt;p&gt;Here’s how to simulate asynchronous loading in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AssetLoader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;asset_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;asset_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asset_name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Starting to load &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;asset_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Simulates loading time
&lt;/span&gt;        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;asset_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; loaded!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;async_load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;asset_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AssetLoader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;asset_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# Load in a separate thread
&lt;/span&gt;
&lt;span class="c1"&gt;# Simulate async loading
&lt;/span&gt;&lt;span class="nf"&gt;async_load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Forest Map&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Player is still exploring...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Wait for loading to finish
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🍵 Demonstration:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Separate Threads:&lt;/strong&gt; The &lt;code&gt;threading&lt;/code&gt; module creates a new thread to load assets without freezing the main game.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simulated Delay:&lt;/strong&gt; The &lt;code&gt;time.sleep&lt;/code&gt; function fakes the loading time to mimic how it works in a real game.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smooth Gameplay:&lt;/strong&gt; The player can continue playing while the new level or asset loads in the background.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With asynchronous loading, &lt;strong&gt;your player stays in the zone&lt;/strong&gt;, and your game feels seamless. Pro-level stuff.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy 3: Level of Detail (LOD) Systems – Be Smart About Quality&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Not everything in your game needs to look like it’s been rendered by a Hollywood studio. If an object is far away, lower its quality. It’s called &lt;strong&gt;Level of Detail (LOD)&lt;/strong&gt;, and it’s how you keep your game’s performance sharp.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Using LOD for a Tree&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a Python simulation of switching between high and low detail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;distance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;distance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# Close-up
&lt;/span&gt;            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rendering high-detail tree!&lt;/span&gt;&lt;span class="sh"&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="c1"&gt;# Far away
&lt;/span&gt;            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rendering low-detail tree.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Simulate different distances
&lt;/span&gt;&lt;span class="n"&gt;close_tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;far_tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Tree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;close_tree&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="c1"&gt;# High detail
&lt;/span&gt;&lt;span class="n"&gt;far_tree&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="c1"&gt;# Low detail
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🍵 Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Distance Matters:&lt;/strong&gt; The &lt;code&gt;distance&lt;/code&gt; property determines how far the tree is from the player.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High vs. Low Detail:&lt;/strong&gt; If the tree is close, render it in high detail. If it’s far, use low detail to save memory and processing power.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimized Performance:&lt;/strong&gt; The player doesn’t notice the difference, but your game runs smoother and faster.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is how you keep the balance between beauty and performance. Your game looks stunning up close but doesn’t waste resources on faraway objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧳To Summarize
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency Wins:&lt;/strong&gt; Only load what you need, when you need it. No wasted memory.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Player Satisfaction:&lt;/strong&gt; Smooth gameplay keeps players engaged and avoids frustration.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Professional Quality:&lt;/strong&gt; These techniques are how AAA games stay fast and responsive.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🫵 Your move now:&lt;/strong&gt; Go apply these strategies, keep your game lean, and make sure your players never even think about lag.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Rule 3: Frame Rate Stabilization&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The frame rate is how many pictures (frames) your game shows per second. If it’s unstable, your game will stutter and feel broken.  &lt;/p&gt;

&lt;p&gt;The secret? Keep the workload for each frame consistent.  &lt;/p&gt;

&lt;p&gt;🚦Here’s how you can control the timing in a game loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;game_loop&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;fixed_time_step&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.016&lt;/span&gt;  &lt;span class="c1"&gt;# 16 milliseconds = 60 frames per second
&lt;/span&gt;    &lt;span class="n"&gt;last_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;current_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;elapsed_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;last_time&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;elapsed_time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;fixed_time_step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# Update game logic
&lt;/span&gt;            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Updating game...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;last_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt;

&lt;span class="c1"&gt;# Run the game loop
&lt;/span&gt;&lt;span class="nf"&gt;game_loop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;⚖️ The game updates at a steady rate (60 times per second).
&lt;/li&gt;
&lt;li&gt;🪂 This make smooth gameplay, no matter how slow or fast the computer is.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🎯Techniques to EXCEL:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimize Rendering Paths: Fewer draw calls. Smarter culling. Simplicity wins.&lt;/li&gt;
&lt;li&gt;Dynamic Resolution Scaling: When the pressure’s on, scale down resolution to maintain the frame rate. Players won’t even notice.&lt;/li&gt;
&lt;li&gt;Fixed Time Step: Keep your physics and logic consistent. Frame rate fluctuations shouldn’t mean chaos.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Rule 4: GPU and CPU Optimization&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Your computer has two main processors:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;CPU:&lt;/strong&gt; Handles logic, like moving a character or calculating scores.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPU:&lt;/strong&gt; Handles graphics, like drawing your game world.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👇 Here's what you have to do for GPU/CPU optimization:&lt;/p&gt;

&lt;p&gt;Profile Everything: Use tools to pinpoint bottlenecks and strike hard where it hurts.&lt;br&gt;
Shader Optimization: Shaders are resource hogs. Simplify them, streamline them, and cut the fat.&lt;br&gt;
Multithreading: Spread tasks across CPU cores. Don’t overload one and leave the others idle.&lt;/p&gt;

&lt;p&gt;If one is working too hard while the other is idle, your game will lag.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution? Multithreading.&lt;/strong&gt;&lt;br&gt;
Let’s split tasks between two threads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update_game_logic&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Updating game logic...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;render_graphics&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rendering graphics...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Run tasks on separate threads
&lt;/span&gt;&lt;span class="n"&gt;logic_thread&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;update_game_logic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;graphics_thread&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;render_graphics&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;logic_thread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;graphics_thread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;🎰 One thread handles logic.
&lt;/li&gt;
&lt;li&gt;🛣️ Another thread handles graphics.
&lt;/li&gt;
&lt;li&gt;⚖️ This balances the workload and prevents bottlenecks.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;👏 Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Optimization isn’t just for “smart” people. It’s simple if you take it step by step:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Manage memory like a pro.&lt;/strong&gt; Don’t waste it.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stream assets.&lt;/strong&gt; Load only what you need.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the frame rate stable.&lt;/strong&gt; No stuttering.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balance the workload.&lt;/strong&gt; Use the CPU and GPU wisely.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Start optimizing NOW. Your future self will thank you.  &lt;/p&gt;

&lt;p&gt;Visit my website &lt;a href="http://codewithshahan.com/" rel="noopener noreferrer"&gt;codewithshahan &lt;/a&gt; to grab my book "Clean Code Zero to One" to improve your game optimization skills. &lt;/p&gt;

&lt;p&gt;Read more: &lt;a href="https://dev.to/codewithshahan/clean-code-zero-to-one-4ihk"&gt;Clean Code Zero to One&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>python</category>
      <category>cleancode</category>
      <category>performance</category>
    </item>
    <item>
      <title>How to Write Better Code for Agile Software Development (Handbook)</title>
      <dc:creator>Programming with Shahan</dc:creator>
      <pubDate>Thu, 06 Feb 2025 14:10:12 +0000</pubDate>
      <link>https://dev.to/codewithshahan/how-to-write-better-code-for-agile-software-development-handbook-417k</link>
      <guid>https://dev.to/codewithshahan/how-to-write-better-code-for-agile-software-development-handbook-417k</guid>
      <description>&lt;p&gt;Building scalable software applications requires writing clean code that’s so simple that any dev can understand it.&lt;/p&gt;

&lt;p&gt;In this article, I’ll explain and demonstrate what clean code is. Then I’ll share my favorite clean code patterns for building modern Agile applications.&lt;/p&gt;

&lt;p&gt;I won’t use complex jargon. I’ll hit you with simple, clear JavaScript examples that focus on the core concepts. Straight to the point, no nonsense – that’s how I roll.&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxh3j6ccn1hc3euc3lfyl.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%2Fxh3j6ccn1hc3euc3lfyl.png" alt="Image of agile software development meme" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Agile, where change is the only constant, clean code is your armor. It makes you adaptable, swift, and, most importantly, in control.&lt;/p&gt;

&lt;p&gt;Here’s the truth: writing clean code is not optional if you want to survive in the software development industry. Fortunately, we human beings are able to master clean code with some effort and practice. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Cost of Bad Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdai6npb55j71sguj6kl.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%2Fwdai6npb55j71sguj6kl.png" alt="Image of cost of messy code vs clean code graph by shahan" width="500" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To explain this stack bar graph, in the initial development phase, bad code is &lt;strong&gt;slightly&lt;/strong&gt; more costly to change than clean code.&lt;/p&gt;

&lt;p&gt;But as we move into the maintenance and refactoring phases, the gap widens significantly, with bad code costing nearly twice as much as clean code.&lt;/p&gt;

&lt;p&gt;By the legacy phase, bad code reaches 100% cost – now it’s extremely expensive to update, while clean code remains more manageable at 45%.&lt;/p&gt;

&lt;p&gt;As of now, the most recent analysis on the cost of poor software quality in the U.S. is the 2022 report by the Consortium for Information and Software Quality (&lt;a href="http://cisq.org" rel="noopener noreferrer"&gt;cisq.org&lt;/a&gt;). This report estimates that poor software quality cost the U.S. economy at least $2.41 trillion in 2022, with technical debt accounting for about $1.52 trillion of this amount.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://www.it-cisq.org/the-cost-of-poor-quality-software-in-the-us-a-2022-report/" rel="noopener noreferrer"&gt;read more about that here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Recent discussions continue to highlight the significant impact of technical debt on software quality and business performance.&lt;/p&gt;

&lt;p&gt;For instance, &lt;a href="https://vfunction.com/blog/how-to-manage-technical-debt" rel="noopener noreferrer"&gt;a 2024 survey&lt;/a&gt; indicated that for more than 50% of companies, technical debt accounts for greater than a quarter of their total IT budget. And this can really hinder innovation if it’s not addressed.&lt;/p&gt;

&lt;p&gt;As you can see, there’s no doubt that bad code is a costly problem in software development.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Clean Coder vs. Messy Coder&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s a graph that shows the journey of &lt;strong&gt;two types&lt;/strong&gt; of coders:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc6ubf77uwipf4gtucw8q.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%2Fc6ubf77uwipf4gtucw8q.png" alt="Image of clean code vs bad code graph chart" width="604" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;⚠️ The Messy Coder (Red line):&lt;/strong&gt; Starts fast but crashes hard. The more lines they write, the more trouble they make.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;⚡ The Clean Coder (Blue line):&lt;/strong&gt; Starts slow but stays consistent. Growth doesn’t stop — it accelerates. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🫵 Now, you decide which line you want to follow. &lt;/p&gt;

&lt;p&gt;AI Can’t Save You If Your Code is a Mess 🗑️&lt;/p&gt;

&lt;p&gt;When you get stuck writing code, you might turn to AI. But let me tell you something: AI can’t save you if your code is a mess. &lt;/p&gt;

&lt;p&gt;It’s like building a house on sand. Sure, it stands for a while, but one strong gust of wind or big wave, and it collapses.&lt;/p&gt;

&lt;p&gt;Remember: AI is just a tool. If you don’t know how to write clean, scalable applications, you're setting yourself up for failure. &lt;/p&gt;

&lt;p&gt;If you can’t maintain the code you write, you’re in trouble. &lt;/p&gt;

&lt;p&gt;I’ve seen it over and over again: developers who know five programming languages. They can build apps, websites, software. They know algorithms and data structures like the back of their hand.&lt;/p&gt;

&lt;p&gt;But when faced with a large project or someone else’s messy code, they crumble.&lt;/p&gt;

&lt;p&gt;They’re like an aerospace engineer who designs and builds their own planes but doesn’t know how to fly them. They crash into their own code.&lt;/p&gt;

&lt;p&gt;This was me...once upon a time. I’d write thousands of lines of code, only to realize I couldn’t even understand what I wrote last week. It was chaos for me.&lt;/p&gt;

&lt;p&gt;But then it hit me — every developer struggles with this. It wasn't about how much I knew. It was about how I organized and structured what I knew. In other words, it was about knowing the art of programming itself.&lt;/p&gt;

&lt;p&gt;I decided to escape this trap. After five months of intense work — four to five hours a day writing, designing, and researching — I created something I wish I had when I started programming. A book that’s a complete beginner’s guide: &lt;strong&gt;&lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnvqegyfwy8zj31qnbbfo.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%2Fnvqegyfwy8zj31qnbbfo.png" alt="cover image of clean code zero to one: from messy code to masterpiece" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to learn more about the book, I give you all the details at the end of this tutorial. So read on to learn more about writing clean code.&lt;/p&gt;

&lt;h2&gt;
  
  
  12 Clean Code Design Patterns for Building Agile Applications ⚖️
&lt;/h2&gt;

&lt;p&gt;If your code doesn’t follow these modern clean code design patterns, you could be creating a ticking time bomb. These patterns are your tools. Master them and enjoy the success of your projects. Let me show you one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🌿 Use Names That Mean Something&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Naming your variables or functions b or x is not helpful. Call them what they are so they’re easier to understand. Here’s an example of both a bad and good variable name:&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;// Weak and vague&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Strong and clear&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numberOfUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;People who write unclear names don’t want to own their mistakes. Don’t be that person.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz1httisvhttuys6kef9u.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%2Fz1httisvhttuys6kef9u.png" alt="Comic showing a bad vs a good variable name, by Shahan" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🔨 Keep Functions Laser-Focused (SRP)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A function should do &lt;strong&gt;one thing&lt;/strong&gt;—and do it perfectly. This is called the Single Responsibility Principle (&lt;strong&gt;SRP&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Good code is like a hammer. It hits one nail, not ten. For example, if you are hiring someone to do everything in your company — finance, sales, marketing, janitorial work, and so on — they’ll likely fail miserably because they can’t focus one one thing. The same goes for your classes in code.&lt;/p&gt;

&lt;p&gt;🚧 When a class or function does more than one thing, it becomes a tangled mess. Debugging it feels like solving a puzzle upside down. If your class handles both user input and database operations, for example, it’s not multitasking — it’s madness. Break it up. One method, one job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔥 My Rule:&lt;/strong&gt; Your code works for you. Keep it sharp, focused, and controllable, or it’s going to control you. Here is how to make that happen:&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;// Clean: One job, one focus&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;logTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`User: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Total: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Messy: Trying to do EVERYTHING&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateAndLogTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`User: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Total: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🪧 When you mix tasks, you mix in confusion. As simple as that.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🚪 Use Comments Thoughtfully&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There is a great saying among professional developers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“ Code speaks for itself. ”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You don’t explain what a door does every time someone walks into a room, do you? Your code should work the same way.&lt;/p&gt;

&lt;p&gt;Comments aren’t bad, but if your code can’t stand on its own, then you may have a problem.&lt;/p&gt;

&lt;p&gt;🪧 A good comment should tell “why” not “how or what”. If a developer doesn’t understand “how” something works, then they likely aren’t going to understand “why” either.&lt;/p&gt;

&lt;p&gt;Here are some short examples of good comments vs bad comments. I’ll also show you a real-world project for writing clean comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: Bad Comment 👎&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="c1"&gt;// Multiply the price by the quantity to calculate the total&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a &lt;strong&gt;bad comment&lt;/strong&gt; because it simply repeats what the code already says. The code &lt;code&gt;price * quantity&lt;/code&gt; is self-explanatory, so the comment doesn’t add anything useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Comment: 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the code is clear and simple, &lt;strong&gt;you don’t need a comment.&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvzt1fx5miz7jfw09bled.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%2Fvzt1fx5miz7jfw09bled.png" alt="Image illustrating unnecessary comment vs " width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Bad Comment 👎&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="c1"&gt;// Check if the user logged in&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isUserLoggedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&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 comment is bad because it doesn’t explain why the &lt;code&gt;isUserLoggin()&lt;/code&gt; exists. It just explains what happens. But we already know that this is an auth function. This comment is a waste of time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good Example 👍&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="c1"&gt;// The user is authenticated before accessing protected resources&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isUserLoggedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&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 is a &lt;strong&gt;good comment&lt;/strong&gt; because it explains &lt;strong&gt;why&lt;/strong&gt; the code exists. It tells us that the function checks if the user is authenticated before allowing access to sensitive parts of the app. It focuses on the bigger picture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnwh4ssmfb8jgctboyej.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%2Fpnwh4ssmfb8jgctboyej.png" alt="Before: " width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;⚡ Best Practices for Writing Good Comments&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain the “Why,” not the “What”:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Write comments to explain the purpose or context of the code, not what the code is doing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid obvious comments:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Don’t write comments for things the code already makes clear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep them short and precise:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Write concise comments that are easy to read and directly explain the purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update comments regularly:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Outdated comments can mislead developers, so always update them when the code changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Real-World Example (with Good Comments) 🛒&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s implement these practices into a real-world project: a large e-commerce application. One function calculates shipping costs based on the order details. Here's the full code, I will explain each comment 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="c1"&gt;// Shipping rules:&lt;/span&gt;
&lt;span class="c1"&gt;// - Free shipping for orders over $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Standard shipping ($10) for orders below $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Additional $5 for international orders&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if the order qualifies for free shipping&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Free shipping&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;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Standard shipping cost&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Add additional cost for international orders&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;shippingCost&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="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;shippingCost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;order1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;order2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isInternational&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: 0&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateShipping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the start of the function, we include a comment explaining the rules for shipping costs. This gives the reader an overview of the logic without needing to read the full 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="c1"&gt;// Shipping rules:&lt;/span&gt;
&lt;span class="c1"&gt;// - Free shipping for orders over $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Standard shipping ($10) for orders below $100&lt;/span&gt;
&lt;span class="c1"&gt;// - Additional $5 for international orders&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, the first condition checks if the order total is greater than or equal to $100. A comment here clarifies &lt;strong&gt;why&lt;/strong&gt; free shipping is applied.&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;// Check if the order qualifies for free shipping&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;shippingCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Free shipping&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second condition applies an additional charge for international shipping. The comment explains &lt;strong&gt;why&lt;/strong&gt; the extra cost is added.&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;// Add additional cost for international orders&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;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isInternational&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;shippingCost&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why are these comments good?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you’re working in a team of 20 developers. Someone reads the &lt;code&gt;calculateShipping&lt;/code&gt; function six months later. Without these comments, they might waste time guessing why international orders have an extra fee. Good comments clarify the why and save hours of frustration.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🧩 Make Your Code Readable&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If someone reading your code feels like they’re solving a riddle, you’ve already become a troublemaker. Here is the proof:&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;// Clean: Reads like a story&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;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please log in.&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="c1"&gt;// Messy: Feels like chaos&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;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please log in.&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 your code is messy and hard to read, it will confuse others—and even yourself later! Imagine coming back to your own code after six months and feeling like you’re reading a foreign language. Readable code saves time, reduces bugs, and makes everyone’s life easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🍵 Why is Readability Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;For yourself:&lt;/strong&gt; When you revisit your code after weeks or months, clean code helps you pick up where you left off without wasting time figuring out what you did.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;For your team:&lt;/strong&gt; If someone else reads your code, they shouldn’t have to solve a puzzle. Clean code makes teamwork smoother and prevents miscommunication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fewer bugs:&lt;/strong&gt; Clear code is easier to debug because you can quickly spot mistakes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🧙‍♂️ How to Write Readable Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s build a simple program to manage books in a library. We’ll make it clean and readable and then I will break down this code 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="c1"&gt;// A class to represent a book&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;borrow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You borrowed "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;".`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Sorry, "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;" is not available.`&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="nf"&gt;returnBook&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`You returned "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;".`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// A function to display available books&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;books&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Available books:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;books&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;book&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isAvailable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`- &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; by &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&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;// Example usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The Clean Coder&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;Robert Martin&lt;/span&gt;&lt;span class="dl"&gt;"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;book2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You Don’t Know JS&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;Kyle Simpson&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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;book3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Eloquent JavaScript&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;Marijn Haverbeke&lt;/span&gt;&lt;span class="dl"&gt;"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;library&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;book2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;book3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Show available books&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;borrow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Borrow a book&lt;/span&gt;
&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Show available books again&lt;/span&gt;
&lt;span class="nx"&gt;book1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;returnBook&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Return the book&lt;/span&gt;
&lt;span class="nf"&gt;displayAvailableBooks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Final list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We created a &lt;code&gt;Book&lt;/code&gt; class to represent each book. It has properties like &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;author&lt;/code&gt;, and &lt;code&gt;isAvailable&lt;/code&gt; to track its status.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;borrow&lt;/code&gt; method checks if the book is available. If yes, it marks it as unavailable and prints a message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;returnBook&lt;/code&gt; method makes the book available again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;displayAvailableBooks&lt;/code&gt; function loops through the library and prints only the books that are available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We create three books (&lt;code&gt;book1&lt;/code&gt;, &lt;code&gt;book2&lt;/code&gt;, &lt;code&gt;book3&lt;/code&gt;) and store them in a &lt;code&gt;library&lt;/code&gt; array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We borrow and return books, showing how the list of available books changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see, readable code is not just about style. It saves time, prevents bugs, and preserves your code as useful for years to come.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🏌️ Test Everything You Write&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you don’t take the time to write tests, you shouldn’t be surprised if your code breaks. If you do want to write tests, follow this unit testing strategy to catch problems ahead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is Unit Testing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Concretely, unit testing checks individual parts of your code (like functions or classes) to ensure they work correctly. Just like checking each brick of your house for soundness before building the walls.&lt;/p&gt;

&lt;p&gt;Let me give you an example of how unit testing works:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Test it (Unit Test)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subtraction failed&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’s what’s going on in this code:&lt;/p&gt;

&lt;p&gt;First, we create the calculator class:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Calculator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="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 &lt;code&gt;Calculator&lt;/code&gt; class has two methods: &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;subtract&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;add(a, b)&lt;/code&gt; takes two numbers and returns their sum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;subtract(a, b)&lt;/code&gt; takes two numbers and returns their difference.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we set up the tests:&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;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Calculator&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’re creating an instance of the &lt;code&gt;Calculator&lt;/code&gt; class to test its methods.&lt;/p&gt;

&lt;p&gt;Then we write test cases:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subtraction failed&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;&lt;code&gt;console.assert(condition, message)&lt;/code&gt; checks if the condition is &lt;code&gt;true&lt;/code&gt;. If it’s &lt;code&gt;false&lt;/code&gt;, the message ("Addition failed" or "Subtraction failed") is displayed in the console.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;First test&lt;/strong&gt;: &lt;code&gt;calculator.add(2, 3) === 5&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Calls the &lt;code&gt;add&lt;/code&gt; method with &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Checks if the result is &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Second test&lt;/strong&gt;: &lt;code&gt;calculator.subtract(5, 3) === 2&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Calls the &lt;code&gt;subtract&lt;/code&gt; method with &lt;code&gt;5&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  Checks if the result is &lt;code&gt;2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what happens if something breaks? It’s pretty simple to solve any issues that arise here. In this case, if the &lt;code&gt;add&lt;/code&gt; or &lt;code&gt;subtract&lt;/code&gt; method doesn’t work correctly, the test will fail. For example:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Addition failed&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;ul&gt;
&lt;li&gt;&lt;p&gt;The condition &lt;code&gt;calculator.add(2, 3) === 6&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The console will display: &lt;code&gt;"Addition failed"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-World Example: Testing a Login System 👥&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s test a simple login system to see how unit testing works in a real-world scenario.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234&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="c1"&gt;// Test the Auth class&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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;et5t45#@&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login failed for valid credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&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;wrongpassword&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login succeeded for invalid credentials&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;First, create the &lt;code&gt;Auth&lt;/code&gt; class:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234&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;The &lt;code&gt;login&lt;/code&gt; method checks if the username is &lt;code&gt;"admin"&lt;/code&gt; and the password is &lt;code&gt;"1234"&lt;/code&gt;. If both match, it returns &lt;code&gt;true&lt;/code&gt; – otherwise, &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, set up the tests:&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;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an instance of the &lt;code&gt;Auth&lt;/code&gt; class. Then write the test cases:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&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;1234&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login failed for valid credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&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;wrongpassword&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login succeeded for invalid credentials&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First test&lt;/strong&gt;: Checks if valid credentials (&lt;code&gt;"admin"&lt;/code&gt;, &lt;code&gt;"1234"&lt;/code&gt;) succeed. If not, &lt;code&gt;"Login failed for valid credentials"&lt;/code&gt; is displayed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Second test&lt;/strong&gt;: Checks if invalid credentials (&lt;code&gt;"user"&lt;/code&gt;, &lt;code&gt;"wrongpassword"&lt;/code&gt;) fail. If not, &lt;code&gt;"Login succeeded for invalid credentials"&lt;/code&gt; is displayed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🌱 Why testing results in clean code:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You naturally write smaller, more focused functions to make your code testable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tests verify that your code behaves as expected under different conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With tests in place, you can confidently update your code, knowing the tests will catch any mistakes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;💉 Use Dependency Injection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hardcoding dependencies is like tattooing someone’s name on your forehead — it’s permanent, can be abrasive, and locks you in.&lt;/p&gt;

&lt;p&gt;So, what does Dependency Injection do? It lets you manage your code's relationships by passing dependencies as arguments. It’s flexible, adaptable, and maintainable.&lt;/p&gt;

&lt;p&gt;To demonstrate how it works, here I’m using the Nodemailer dependency for sending emails to users:&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;// Dependency: Sending emails with Nodemailer&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nodemailer&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;nodemailer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&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;transporter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nodemailer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTransport&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="cm"&gt;/* config */&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;transporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendMail&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;programmingwithshahan@gmail.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;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&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;⚠️ To save yourself from risk, make sure to avoid &lt;strong&gt;hardcoding&lt;/strong&gt; dependencies. Use abstraction or configuration files for secure maintenance.&lt;/p&gt;

&lt;p&gt;This is just one example. As a developer, you may use hundreds of libraries or dependencies.&lt;/p&gt;

&lt;p&gt;I’m not saying you shouldn’t rely on dependencies/libraries at all, as nowadays it is hard to avoid them. But you should be very careful before installing them in your coding projects.&lt;/p&gt;

&lt;p&gt;You should check the security, performance, quality, or functionality of an organization's software systems. Because they sometimes contain risks that can ruin your entire project.&lt;/p&gt;

&lt;p&gt;🚧 Always control your tools, don't let them control you.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;📂 Clean Project Structures&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A well-organized project is the difference between a &lt;strong&gt;trash heap&lt;/strong&gt; and a high-end &lt;strong&gt;boutique&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is how each folder should be organized:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9xwyg9iqqcybz21lsgxz.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%2F9xwyg9iqqcybz21lsgxz.png" alt="Image of clean code project structure by shahan" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your codebase looks like a junk drawer, you’ve already caused trouble for your future self.&lt;/p&gt;

&lt;p&gt;Let’s go through the clean project structure you can see above to better understand it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;code&gt;myProjet/src&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the main container for your entire application. Everything your app needs is stored inside this folder. It has subfolders to keep things tidy and managed in one place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;code&gt;components&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is where you keep all the reusable pieces of your app. You can use these components in multiple places without building them again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; &lt;code&gt;services&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the "brain" of your app. It handles all the work behind the scenes for both the frontend and backend. &lt;code&gt;emailService.js&lt;/code&gt;, &lt;code&gt;userService.js&lt;/code&gt; and &lt;code&gt;productService.js&lt;/code&gt; are some of the example files for your &lt;code&gt;services&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; &lt;code&gt;utils&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This contains all the small, handy tools you need to make your application run smoothly and make your life easier. For example, &lt;code&gt;formatedate.js&lt;/code&gt;, &lt;code&gt;validateEmail.js&lt;/code&gt; and &lt;code&gt;generateId.js&lt;/code&gt; are some of the common utils files to make reusable pieces of components for your entire project.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;5.&lt;/strong&gt; &lt;code&gt;tests&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Conventionally, test files are typically located &lt;strong&gt;outside&lt;/strong&gt; the &lt;code&gt;src&lt;/code&gt; folder, at the project root level. This keeps your production code (&lt;code&gt;src&lt;/code&gt;) separate from your test code (&lt;code&gt;tests&lt;/code&gt;), making it cleaner and easier to manage. Have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;myProject/
├── src/              # Production code
│   ├── components/
│   ├── services/
│   └── utils/
├── tests/            # Test files
│   ├── components/
│   ├── services/
│   └── utils/
├── package.json      # Project configuration
└── README.md         # Documentation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some developers may prefer creating one testing file inside the &lt;code&gt;test&lt;/code&gt; folder to test everything in one place. Unfortunately, it may feel clean at first, but as your project grows, you’ll have to find and search for specific code blocks. It’s ugly and can produce unexpected testing results. So breaking them into multiple testing files inside the &lt;code&gt;tests&lt;/code&gt; folder is highly recommended.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world example 📧&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So let me create a clean, durable project structure for you to apply in any future projects you might work on. Needless to say, clean project structure is the foundation of building a maintainable project.&lt;/p&gt;

&lt;p&gt;From our previous email sending application example, we will write a clean project structure for this app. We want to build an application that sends emails to users. Your clean project structure for this app should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6v6rlc5qiplgxz1h4dps.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%2F6v6rlc5qiplgxz1h4dps.png" alt="Image of email app clean code project structure by shahan" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I packed every subfolder and file inside the &lt;code&gt;src&lt;/code&gt; folder which is the main container of our application. Inside the &lt;code&gt;src&lt;/code&gt; folder, we created &lt;code&gt;components&lt;/code&gt;, &lt;code&gt;services&lt;/code&gt;, &lt;code&gt;utiles&lt;/code&gt;. Finally, we have a manageable &lt;code&gt;test&lt;/code&gt; folder outside the &lt;code&gt;src&lt;/code&gt; folder to test each component independently. This test folder has nothing to do with our production code that is located inside the &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🤹‍♂️ Be Consistent with Formatting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Don’t write code like you’re 10 different people. Be consistent with your formatting.&lt;/p&gt;

&lt;p&gt;Use tools like &lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; or &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; to enforce a consistent style. If every file looks different, you’re creating chaos that no one wants to fix.&lt;/p&gt;

&lt;p&gt;I would say that consistency in formatting is one of the most important aspects of writing clean code.&lt;/p&gt;

&lt;p&gt;Have a look...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46zu4k5nnrkcdesgqrye.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%2F46zu4k5nnrkcdesgqrye.png" alt="Image of consistent formatting snippets from clean code zero to one book" width="800" height="960"&gt;&lt;/a&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="c1"&gt;// Always use 2 spaces for indentation&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dimensions must be positive numbers.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Add meaningful whitespace for readability&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Clear separation of logic&lt;/span&gt;
&lt;span class="k"&gt;try&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;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;Let’s examine some of the aspects of this code that make it clean:&lt;/p&gt;

&lt;h4&gt;
  
  
  1️⃣ Consistent Indentation
&lt;/h4&gt;

&lt;p&gt;Why 2 or 4 spaces? It’s clean, minimal, and universally accepted in many JavaScript style guides. It doesn’t overwhelm the eyes, and the code structure stands out clearly. When you mix inconsistent indentation (2 spaces here, 4 spaces there), you confuse people—and confused people make mistakes.&lt;/p&gt;

&lt;h4&gt;
  
  
  2️⃣ Meaningful Whitespace: Giving Code Room to Breathe
&lt;/h4&gt;

&lt;p&gt;That extra line break between the rectangle definition and the &lt;code&gt;try&lt;/code&gt; block is like a pause in a sentence — it gives the reader time to process.&lt;/p&gt;

&lt;h4&gt;
  
  
  3️⃣ Clear Separation of Logic: Modular Thinking
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&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;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Area: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;area&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;Look at how the logic is divided into clear sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, the calculation (&lt;code&gt;calculateArea&lt;/code&gt; function).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, the output (&lt;code&gt;console.log&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, error handling (&lt;code&gt;catch&lt;/code&gt; block).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each task has its own space and purpose.&lt;/p&gt;

&lt;h4&gt;
  
  
  4️⃣ Readable Error Handling
&lt;/h4&gt;

&lt;p&gt;When you throw errors or log messages, you format them cleanly. No vague or cryptic messages here. A developer seeing this will immediately know the problem.&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;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dimensions must be positive numbers.&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;&lt;strong&gt;🐦‍⬛ General tips for consistent formatting:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use 2 or 4 spaces for indentation consistently throughout your codebase. Avoid tabs to maintain uniformity across different editors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep lines to a maximum of 100-120 characters to prevent horizontal scrolling and improve readability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group related logic together and separate blocks of code with blank lines to highlight their purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, avoid over-aligning code. Instead, let indentation naturally guide the flow of logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;✋ Stop Hardcoding Values&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hardcoding values is a lazy way to code. Here is the proof:&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;// Bad: Hardcoded and rigid&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&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;maxUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;currentUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;maxUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Too many users!&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="c1"&gt;// Clean: Dynamic and flexible&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_USERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentUsers&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;MAX_USERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Too many users!&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;You see, changing this variable won’t surprise you in the future. You know exactly where to find it to change uncertain values.&lt;/p&gt;

&lt;p&gt;Its best to store your fixed values in the global configuration (config) file.&lt;/p&gt;

&lt;p&gt;🪧 So, avoid hardcoding values at all costs. Hardcoding is the shortcut that may drive your future self (or others) crazy.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🤏 Keep Functions Short&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If your function is longer than 20 lines, it’s probably trying to do too much_._&lt;/p&gt;

&lt;p&gt;Short functions are sharp functions. They hit their mark every time.&lt;/p&gt;

&lt;p&gt;Long, bloated functions are messy and hard to read, but short functions are clear and focused. Here is how your large functions should break down:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;addItemToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;logTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addItemToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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;Let me explain this code so you understand why breaking down large functions is a winning strategy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Main Function:&lt;/strong&gt; &lt;code&gt;updateCart()&lt;/code&gt; calls smaller helper functions to handle specific tasks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-  Adds the item to the cart.

-  Calculates the total price.

-  Logs the details of the transaction.

-  Finally, it returns the total price.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Instead of one long block of code that tries to do everything, it delegates tasks to helper functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Helper Function:&lt;/strong&gt; &lt;code&gt;addItemToCart()&lt;/code&gt; This function &lt;strong&gt;only&lt;/strong&gt; handles adding the item to the cart. if you need to change how items are added (for example, checking for duplicates). You could just edit this small function instead of digging through a giant block of code in &lt;code&gt;updateCart&lt;/code&gt;. That’s how you write clean code functions that’s a joy to read and easy to maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Happens If Functions Are Too Long? 💤&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s say you didn’t break down the &lt;code&gt;updateCart&lt;/code&gt; function. Here’s what it might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for &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;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&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;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Added &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;item&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="s2"&gt;. Total is now &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;total&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;What are the problems here?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It’s trying to do everything.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s hard to read, especially if it grows bigger.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If something breaks, you’ll waste time figuring out which part is the problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the choice is yours: stick with the messy all-in-one approach or practice the clean one function one job mindset.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;⛺ Follow the Boy Scout Rule&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Always leave your campsite cleaner than you found it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me break it down for you. You don’t just use something and leave it worse than before. That’s inconsiderate behavior. Real professionals leave things better than they found them.&lt;/p&gt;

&lt;p&gt;In coding terms, every time you touch the codebase, &lt;strong&gt;make it better.&lt;/strong&gt; Clean it up, refactor messy parts, and improve readability. If you don’t, you’re just piling on garbage that will eventually collapse on your head.&lt;/p&gt;

&lt;p&gt;Here is an example. Instead of improving it, we’re just adding more layers of complexity:&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;// Original code: Hard to read, poorly named variables&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// We're adding to it but not cleaning it up&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcDiscount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;final&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;final&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;After: it gets better every time. Here’s how a disciplined coder works — they improve as they go:&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;// Improved code: Clear names, refactored for clarity&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateSubtotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateDiscountedTotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&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;subtotal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateSubtotal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quantity&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;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;discountRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;discount&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, anyone can tell what’s happening at a glance. Because we’ve broken down the code into smaller, more focused functions. Thus, adding new features won’t break existing functionality. 🏕️&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🏟️ Follow the Open/Closed Principle&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This design principle suggests your code should be designed to allow extensions without changing the existing foundation.&lt;/p&gt;

&lt;p&gt;You want to add features &lt;em&gt;—&lt;/em&gt; not rip it apart every time you upgrade_._ Modifying old code to fit new requirements is exactly like trying to rebuild your house every time you buy new furniture. It’s not sustainable.&lt;/p&gt;

&lt;p&gt;Let’s see how you can build smarter, scalable code that lets you add features without breaking everything else.&lt;/p&gt;

&lt;h4&gt;
  
  
  Before: Violating the principle
&lt;/h4&gt;

&lt;p&gt;You’ve got a class to handle payments — simple enough. At first, it just handles credit cards.&lt;/p&gt;

&lt;p&gt;But then your boss shows up and says, &lt;em&gt;“Hey, now we need PayPal support.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And because you didn’t bother learning clean code, your code looks like a spaghetti monster straight out of a legacy enterprise system from 1995. Here’s the masterpiece you’ve crafted:&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;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;creditCard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing credit card payment of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentType&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paypal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing PayPal payment of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="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="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unsupported payment type&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;paymentProcessor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;paymentProcessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;creditCard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;paymentProcessor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paypal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alas! Every new payment type (like Apple Pay, Google Pay, and so on) requires modifying the &lt;code&gt;processPayment&lt;/code&gt; method. Needless to say, you risk breaking existing functionality while adding new features. If you had learned this principle, you might not be in this mess.&lt;/p&gt;

&lt;p&gt;Don’t worry: I’ll help you to fix this. First, we need to refactor the code. Instead of modifying the existing class, we’ll extend its functionality using &lt;a href="https://stackify.com/oop-concept-polymorphism/" rel="noopener noreferrer"&gt;polymorphism&lt;/a&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="nx"&gt;javascriptCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="c1"&gt;// Base class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;processPayment() must be implemented&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="c1"&gt;// Credit card payment&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing credit card payment of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// PayPal payment&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing PayPal payment of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Adding a new payment type? Just extend the class!&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplePayPayment&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PaymentProcessor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Processing Apple Pay payment of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApplePayPayment&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;payments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;payment&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;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, adding new payment methods doesn’t require changing the existing &lt;code&gt;PaymentProcessor&lt;/code&gt; class. You just created a new subclass. So the original code remains untouched, meaning there’s no risk of breaking existing features.&lt;/p&gt;

&lt;p&gt;Each payment type has its own class, and adding PayPal payment support, for example, doesn’t break the code. Now you can reply to your boss: &lt;em&gt;“Of course, I will add this feature in 5 minutes.”&lt;/em&gt; Your promotion is waiting for you to accept it.&lt;/p&gt;

&lt;p&gt;I share even more tips in my book &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;Clean Code Zero to One&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Modern Best Practices to Help You Write Clean Code: A Summary 🥷&lt;/p&gt;

&lt;p&gt;Now let me show you the best practices and summarise our 12 Clean Code design principles to help you write clean code for agile application development.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔎 Common Code Smells and How to Fix Them
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;💊 Duplication: If you're copying code, you’re creating more work for yourself. Extract it into a function, and do it right.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🛤️ Long methods: If your method needs a scroll bar, it's doing too much. Break it down, keep it focused.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;👑 King objects: No class should be doing everything. Simplify responsibilities, or your codebase will become messy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💬 Effective Commenting Practices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;💭 When to comment: Only comment if the code isn't clear. If it is, comments are just clutter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🫗 Clarity: Comments should tell why, not what. If your code needs explaining, it might be too complex.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🌴 Avoid redundancy: Don't comment what's obvious. If your function is addNumbers, don't comment it does that.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧼 Refactoring Techniques for Clean Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🏭 Extract methods: Big methods? Break them down. It's not just about cleanliness –– it's about control.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🫕Rename variables: If your variable names don’t shout their purpose, change and improve them. Precision in naming is precision in thought.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🍃 Simplify conditionals: If your conditionals look like algebra, simplify them. If a == true, just write if(a).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧪 Testing and Clean Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🧙 Unit tests: Test every piece of code like you're interrogating a suspect. No stone unturned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🏇TDD (Test Driven Development): Write tests first. It's not just about catching bugs, it's about knowing exactly what your code should do before you write it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🧽 Clean tests: Your tests should be as clean as your code. If they're messy, they’re not going to be helpful.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🐛 Error Handling and Clean Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;⁉️ Exceptions: Use them. They're not just for errors, they're also for keeping your code clean from error clutter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🖍️ Fail fast: If something's wrong, stop right there. Don't let errors add up. Deal with them immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🚨 Logging: Log like you're documenting a crime scene. Clear, precise, and only what's necessary.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🌱 Code Reviews and Clean Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;🚢 Process: Have a system. No cowboy coding. Review, critique, improve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🔪 Tools: Use tools that make reviews easy. They're not just for catching mistakes, they're also for teaching discipline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🧦 Culture: Cultivate a culture where feedback is gold. Help your team learn how to handle and receive critiques.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Automated Tools for Maintaining Clean Code ⚓
&lt;/h2&gt;

&lt;p&gt;Tools and automation techniques can be really helpful in writing clean code. If you’re not using the right tools and automating things to save yourself time, you’re missing out.&lt;/p&gt;

&lt;p&gt;You think you can "eyeball" your way through code quality? Guess again. Without automation, this is what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;👎 You miss obvious mistakes because you're "too busy."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🤕 Your code looks different in every file, making collaboration a headache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🪦 Deployment breaks because you skipped a critical test.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Successful developers use the right tools to automate code and get things done. Here are four strategies for maintaining clean code using modern tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ Static Analysis&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Static analysis is actually a code inspector that reads through your code and points out potential issues early on. The best part? It works &lt;strong&gt;before&lt;/strong&gt; runtime, catching errors that could otherwise lead to crashes, downtime, or embarrassing bugs.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;How does it work?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Syntax checking&lt;/strong&gt;: It looks at your code to analyze everything written in the correct syntax. If you misspell a variable or forget a closing bracket, it’ll call you out instantly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code quality rules&lt;/strong&gt;: Tools like ESLint enforce rules like consistent indentation, avoiding unused variables, and sticking to best practices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error prevention&lt;/strong&gt;: It identifies logic errors, such as using variables that haven’t been defined, or making comparisons that don’t make sense.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s how static analysis works in action:&lt;/p&gt;

&lt;h4&gt;
  
  
  🚨 Before static analysis:
&lt;/h4&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Typo, unnoticed until runtime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Problem&lt;/strong&gt;: The typo in &lt;code&gt;sume&lt;/code&gt; will only cause an error when the code runs, and that could lead to frustrating debugging sessions or worse — breaking the app in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🚑 After static analysis (using ESLint):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;codeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sume&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Solution&lt;/strong&gt;: &lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; immediately flags the typo before you even run the code. The error is caught early, saving you time and headaches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ Automated Code Formatting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before Formatting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculate&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;calculate &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&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;ul&gt;
&lt;li&gt;  &lt;strong&gt;Problem&lt;/strong&gt;: Inconsistent spacing and formatting make the code harder to read.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  After using Prettier:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Solution&lt;/strong&gt;: Clean, consistent, and professional formatting is applied automatically. No more nitpicking over spaces or alignment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pretty basic stuff though. I covered this in case you write code in notepad or something where IDE is not provided (for example, a job interview).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣ Continuous Integration (CI) Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;CI testing make sure every new change to your code is verified automatically. It’s like a safety net that catches bugs introduced during development. CI tools run your tests every time you push code, so nothing breaks after deployment.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;How Does CI Testing Work?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Triggers on change&lt;/strong&gt;: Each time code is committed, the CI tool (like &lt;a href="https://github.com/features/actions" rel="noopener noreferrer"&gt;GitHub Actions&lt;/a&gt;, &lt;a href="https://www.jenkins.io/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt;) runs automated tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feedback&lt;/strong&gt;: It gives you instant feedback if something fails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prevents broken code&lt;/strong&gt;: Commits only clean, and the working code gets merged into the main branch.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣ CI/CD pipelines&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We also use CI/CD pipelines as a continuous process that includes code building, testing, and deployment, while CI testing is a part of that process that focuses on automating the testing of code changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Differece between CI/CD pipelines vs CI testing:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CI/CD pipelines:&lt;/strong&gt; A CI/CD pipeline combines code building, testing, and deployment into a single process. This process make sure that all changes to the main branch code are releasable to production. CI/CD pipelines can reduce deployment time, decrease costs, and improve team collaboration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CI testing:&lt;/strong&gt; CI testing is the process of automatically testing code changes that are integrated into a central repository. CI testing focuses on making sure the codebase is stable and that integration issues are resolved. CI testing help developer build software that is stable, bug-free, and meets functional requirements&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚧 This is what CI testing CI/CD pipelines concepts are really about. Not as complex as it seems. So let me elaborate more on CI testing with GitHub Actions, as we usually run tests through automated tools nowadays.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;⚡ Continuous Integration (CI) Testing with GitHub Actions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As I said earlier, CI tools run automated tests every time you push code or open a pull request. This guarantees that only working, bug-free code gets merged into the main branch.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Set Up CI Testing with GitHub Actions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create Your Repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set up a GitHub repository for your project. Then, push your code to GitHub using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit for CI Testing"&lt;/span&gt;
git branch &lt;span class="nt"&gt;-M&lt;/span&gt; main
git remote add origin https://github.com/codewithshahan/codewithshahan.git
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main

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

&lt;/div&gt;



&lt;p&gt;Or you can create a new repo from your GitHub account without using the command. Just login to your GItHub account and visit dashboard. Here you will find a “New” button to create a brand new repo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwu4mnv92uvvbcyn95bo.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%2Fzwu4mnv92uvvbcyn95bo.png" alt="image of creating a new repo on github by Shahan" width="800" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Add a GitHub Actions Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate to your repository’s &lt;strong&gt;Actions&lt;/strong&gt; tab. To do this, first, you have to visit your repo on Github (you will find the link after creating your repo). In this case, I created a new repo called “codewithshahan”. Here, look for the &lt;strong&gt;Actions&lt;/strong&gt; tab on the right side of the navigation bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxs63er6prc63ph8c8vp0.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%2Fxs63er6prc63ph8c8vp0.png" alt="Image of github actions navigation tab by shahan" width="799" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After navigating the Actions tab, scroll down a little and you will find the &lt;strong&gt;continuous integration&lt;/strong&gt; section:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6je4zwug4js9khb27oxz.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%2F6je4zwug4js9khb27oxz.png" alt="Image of CI (Continuous Integration) testing on Github Actions Page by Shahan" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a setup workflow yourself. I will use Node.js for this project.&lt;/p&gt;

&lt;p&gt;After clicking the configure button, a &lt;code&gt;node.js.yml&lt;/code&gt; file will be created automatically, and you can adjust the code depending on your goals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxsxic171busrm0f4k44.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%2Foxsxic171busrm0f4k44.png" alt="Image of GitHub workflow snippet for automated testing by Shahan" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won’t go into detail about how should modify your &lt;code&gt;.yml&lt;/code&gt; file. It depends on your project goals and personal preference. Also, it is a whole different broader topic and as this article has already become quite long, so I’ll explain it in a future article. For now, just stick with this foundational knowledge.&lt;/p&gt;

&lt;p&gt;This CI Testing workflow is best for modern application development. Your app remains stable while incorporating key features including testing (e,g. Dark Mode), Building and deploying applications directly within your GitHub repository. This way, you can push your code confidently, knowing your code is always clean and ready for production.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Role of Documentation in Agile Software Development 🚣
&lt;/h2&gt;

&lt;p&gt;If you want your code to be top-notch, you need to understand how to write good documentation. If you think documentation is just about scribbling down how the code works, you’re wrong. It's about explaining &lt;strong&gt;why&lt;/strong&gt; it works, not just how it works. That’s where most people miss the mark.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. 🚡 Create &lt;strong&gt;Useful Docs (Explain Why, Not Just How)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you write documentation, you're not just throwing down some instructions for how to use the code. You're telling the next person (or even yourself in the future) why this piece of code exists in the first place. That’s the difference between good and bad documentation.&lt;/p&gt;

&lt;p&gt;Bad docs leave people scratching their heads. They’re too vague, too simple, and they don’t answer the big questions. If your documentation is unclear, that likely means your thinking is unclear. You’re basically saying, &lt;em&gt;"I don’t care if you understand this, it works, just use it."&lt;/em&gt; That’s not helpful.&lt;/p&gt;

&lt;p&gt;Great documentation answers the tough questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅ Why did you choose this approach over another?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Why does this function exist? What problem does it solve?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Why did you write this code the way you did?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your docs are just regurgitating how to use the code, you’re not being as helpful as you can be. Start thinking deeper and explaining the reasoning behind everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. ⏳ &lt;strong&gt;Keep the Docs Updated (Outdated Docs Are Worse Than No Docs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Outdated documentation is the worst. In fact, it can be worse than having no docs at all. When you leave documentation that’s out of sync with the code, you’re doing your future self — or whoever has to deal with it next — a huge disservice.&lt;/p&gt;

&lt;p&gt;Every time your code changes, your documentation needs to change too. It has to reflect the current state of things. Don’t mislead future developers (or yourself) by leaving outdated info that will only confuse them and waste their time. If something is no longer relevant, delete it. Outdated documentation is the equivalent of a cluttered mind — it holds you back.&lt;/p&gt;

&lt;p&gt;Make it a habit to check and update your documentation regularly. The minute a line of code changes, so should your documentation. Period.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. 🚆 &lt;strong&gt;Integrate Comments (Good Comments in Code Are Part of Documentation)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here’s the deal — comments in your code should &lt;strong&gt;integrate&lt;/strong&gt; with your documentation. Good comments aren’t just a crutch for developers who can’t explain their code elsewhere. They should improve your docs, not replace them.&lt;/p&gt;

&lt;p&gt;Comments are supplements to your documentation. You write clean, understandable code that needs minimal explanation, but when something isn’t crystal clear, throw in a comment. Remember the rule for comments in your code: explain the &lt;strong&gt;why&lt;/strong&gt;, not the &lt;strong&gt;how&lt;/strong&gt;. It’s the same here. Don’t repeat yourself. Let your code do the talking. Comments should complement the bigger picture of your documentation, not act as a band-aid for sloppy code.&lt;/p&gt;

&lt;p&gt;🪧 Great code should be self-explanatory. Fix the code, then add comments for clarification if necessary. Keep comments clean, short, and to the point.&lt;/p&gt;

&lt;p&gt;If you want to write clean, efficient, and maintainable code, documentation is key. Stop thinking of docs as an afterthought or something you do to fill space. It’s an extension of your code — your way of communicating clearly and effectively. It’s your roadmap for future developers, and it’s a reflection of your thought process.&lt;/p&gt;




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

&lt;p&gt;Clean code isn't a nice-to-have –– it's a must-have for those who aim to lead. It's about control, efficiency, and improvement over time in the long run. And ultimately, it’ll help you succeed in the game of agile software development. &lt;/p&gt;

&lt;p&gt;🪧 If you want to truly master your craftsmanship, write clean code, and let the efficiency speak for itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  Frequently Asked Questions About Clean Code 🧯
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What is clean code?&lt;/strong&gt; It's code that doesn't make you want to throw your laptop out the window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why is clean code important in Agile?&lt;/strong&gt; Because Agile is about speed and change, and you can't be quick with a mess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What are code smells?&lt;/strong&gt; Signs that you're about to lose control of your codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How can I improve commenting?&lt;/strong&gt; Only comment on what's necessary, and make sure each comment adds value, not noise.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you for being with me. You can visit my &lt;a href="https://x.com/shahancd" rel="noopener noreferrer"&gt;Twitter account&lt;/a&gt; or &lt;a href="https://www.codewithshahan.com" rel="noopener noreferrer"&gt;my website&lt;/a&gt; to read more posts about clean code and Agile application development. Until next time… keep improving your codebase.&lt;/p&gt;

&lt;p&gt;If you’re serious about mastering clean code and taking your programming career to the next level, then my book is for you: &lt;a href="https://codewithshahan.gumroad.com/l/cleancode-zero-to-one" rel="noopener noreferrer"&gt;&lt;strong&gt;Clean Code Zero to One&lt;/strong&gt;&lt;/a&gt;. This book is your full guide from zero to one in clean code, from messy code to masterpiece. I am offering a 50% discount using the code "earlybird" — only for the first 50 copies. Plus, there’s a 30-day money-back guarantee — no risk, all reward.&lt;/p&gt;




&lt;h2&gt;
  
  
  Other Trending Handbooks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/complete-guide-to-css-transform-functions-and-properties/" rel="noopener noreferrer"&gt;Learn CSS Transform&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/how-to-create-a-static-blog-with-lume/" rel="noopener noreferrer"&gt;Build a Static Blog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/how-to-build-an-ai-chatbot-with-redis-python-and-gpt/" rel="noopener noreferrer"&gt;Build an AI Chatbot&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/what-is-programming-tutorial-for-beginners/" rel="noopener noreferrer"&gt;What is Programming?&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/python-code-examples-sample-script-coding-tutorial-for-beginners/" rel="noopener noreferrer"&gt;Python Code Examples&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/a-practical-guide-to-start-opensource-contributions/" rel="noopener noreferrer"&gt;Open Source for Devs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/http-full-course/" rel="noopener noreferrer"&gt;HTTP Networking in JS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/how-to-write-unit-tests-in-react-redux/" rel="noopener noreferrer"&gt;Write React Unit Tests&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/introduction-to-algorithms-with-javascript-examples/" rel="noopener noreferrer"&gt;Learn Algorithms in JS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/how-to-write-clean-code/" rel="noopener noreferrer"&gt;How to Write Clean Code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/the-php-handbook/" rel="noopener noreferrer"&gt;Learn PHP&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/the-java-handbook/" rel="noopener noreferrer"&gt;Learn Java&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/the-swift-handbook/" rel="noopener noreferrer"&gt;Learn Swift&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/learn-golang-handbook/" rel="noopener noreferrer"&gt;Learn Golang&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/get-started-with-nodejs/" rel="noopener noreferrer"&gt;Learn Node.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/complete-guide-to-css-grid/" rel="noopener noreferrer"&gt;Learn CSS Grid&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/learn-solidity-handbook/" rel="noopener noreferrer"&gt;Learn Solidity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/the-express-handbook/" rel="noopener noreferrer"&gt;Learn Express.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/javascript-es-modules-and-module-bundlers/" rel="noopener noreferrer"&gt;Learn JS Modules&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/apache-kafka-handbook/" rel="noopener noreferrer"&gt;Learn Apache Kafka&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/rest-api-design-best-practices-build-a-rest-api/" rel="noopener noreferrer"&gt;REST API Best Practices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/front-end-javascript-development-react-angular-vue-compared/" rel="noopener noreferrer"&gt;Front-End JS Development&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/build-consume-and-document-a-rest-api/" rel="noopener noreferrer"&gt;Learn to Build REST APIs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/build-strongly-typed-polymorphic-components-with-react-and-typescript/" rel="noopener noreferrer"&gt;Intermediate TS and React&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/command-line-for-beginners/" rel="noopener noreferrer"&gt;Command Line for Beginners&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/an-introduction-to-operating-systems/" rel="noopener noreferrer"&gt;Intro to Operating Systems&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/building-consuming-and-documenting-a-graphql-api/" rel="noopener noreferrer"&gt;Learn to Build GraphQL APIs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/oss-security-best-practices/" rel="noopener noreferrer"&gt;OSS Security Best Practices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/design-patterns-for-distributed-systems/" rel="noopener noreferrer"&gt;Distributed Systems Patterns&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.freecodecamp.org/news/an-introduction-to-software-architecture-patterns/" rel="noopener noreferrer"&gt;Software Architecture Patterns&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
