<?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: Gift Egbonyi</title>
    <description>The latest articles on DEV Community by Gift Egbonyi (@giftysoftdev).</description>
    <link>https://dev.to/giftysoftdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3020154%2F9d419e48-1e3b-4caf-be76-cd010ac85dc9.png</url>
      <title>DEV Community: Gift Egbonyi</title>
      <link>https://dev.to/giftysoftdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/giftysoftdev"/>
    <language>en</language>
    <item>
      <title>Why most beginner portfolios don’t get interviews (and how to fix yours)</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Tue, 03 Feb 2026 17:40:44 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/why-most-beginner-portfolios-dont-get-interviews-and-how-to-fix-yours-2dc2</link>
      <guid>https://dev.to/giftysoftdev/why-most-beginner-portfolios-dont-get-interviews-and-how-to-fix-yours-2dc2</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends 👋🏾&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s be honest for a minute.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Most beginner portfolios don’t get interviews because the portfolio doesn’t communicate what recruiters actually want to see.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;NB: it doesn't mean that the developer is bad&lt;/p&gt;

&lt;p&gt;I’ve reviewed quite a few beginner portfolios and the same patterns keep showing up.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  &lt;strong&gt;1️⃣ Too many cliché tutorial projects&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If your portfolio is full of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Todo apps&lt;/li&gt;
&lt;li&gt;Weather apps&lt;/li&gt;
&lt;li&gt;Calculator apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…that’s not necessarily wrong.&lt;/p&gt;

&lt;p&gt;The problem is &lt;em&gt;everybody else has the same thing&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Recruiters have seen these projects hundreds of times. When they open your portfolio and see another cliché tutorial clone with no explanation, there’s nothing that makes you stand out.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to fix it
&lt;/h3&gt;

&lt;p&gt;You don’t need “unique” ideas. You need &lt;strong&gt;context&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For each project, answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why did you build this?&lt;/li&gt;
&lt;li&gt;What problem does it solve?&lt;/li&gt;
&lt;li&gt;What did &lt;em&gt;you&lt;/em&gt; learn while building it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;...a ready example is my &lt;a href="https://gift-egbonyi.onrender.com/#projects" rel="noopener noreferrer"&gt;portfolio section&lt;/a&gt; where I have some projects with case studies.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Even a simple app becomes interesting when you explain your thought process.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2️⃣ No explanation of decisions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Many portfolios show screenshots and links, but zero reasoning.&lt;/p&gt;

&lt;p&gt;Recruiters aren’t just looking at &lt;em&gt;what&lt;/em&gt; you built.&lt;br&gt;
They want to know &lt;strong&gt;how you think&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If I see a project and can’t tell:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;why you chose a certain stack&lt;/li&gt;
&lt;li&gt;how you structured the app&lt;/li&gt;
&lt;li&gt;what trade-offs you made&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…it’s hard to judge your skill level.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to fix it
&lt;/h3&gt;

&lt;p&gt;Add short write-ups:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why React and not something else?&lt;/li&gt;
&lt;li&gt;Why this database?&lt;/li&gt;
&lt;li&gt;What would you improve if you had more time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need an essay. A few honest paragraphs would do.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;3️⃣ No README (or a weak one)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This one hurts.&lt;/p&gt;

&lt;p&gt;A missing README feels like submitting an assignment without instructions.&lt;/p&gt;

&lt;p&gt;Or even worse, a README that says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This is a simple app built with React.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That tells me nothing.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to fix it
&lt;/h3&gt;

&lt;p&gt;Your README should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What the app does&lt;/li&gt;
&lt;li&gt;Who it’s for&lt;/li&gt;
&lt;li&gt;How to run it locally&lt;/li&gt;
&lt;li&gt;What features you’re proud of&lt;/li&gt;
&lt;li&gt;Any known limitations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as a short conversation with the recruiter.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;4️⃣ Projects are not live&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If I can’t click and try your app, that’s a missed opportunity.&lt;/p&gt;

&lt;p&gt;Most recruiters won’t clone your repo.&lt;br&gt;
If there’s no live link, they’ll move on.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to fix it
&lt;/h3&gt;

&lt;p&gt;Deploy your projects.&lt;br&gt;
Even basic hosting is fine.&lt;/p&gt;

&lt;p&gt;What matters is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The app runs&lt;/li&gt;
&lt;li&gt;It doesn’t crash immediately&lt;/li&gt;
&lt;li&gt;The core idea works&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Perfection is not required.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;5️⃣ No personality, no story&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is the mostly overlooked by a lot of beginners.&lt;/p&gt;

&lt;p&gt;A lot of portfolios feel robotic.&lt;br&gt;
No sense of who built them. No story. No voice.&lt;/p&gt;

&lt;p&gt;But hiring is still human.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to fix it
&lt;/h3&gt;

&lt;p&gt;Add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A short “About me” that sounds like &lt;em&gt;you&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Why you’re learning software engineering&lt;/li&gt;
&lt;li&gt;What kind of problems you enjoy solving&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need to overshare. Just be real.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;What you should takeaway&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A good beginner portfolio has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear thinking&lt;/li&gt;
&lt;li&gt;Honest communication&lt;/li&gt;
&lt;li&gt;Showing how you approach problems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Recruiters aren’t expecting senior-level code.&lt;br&gt;
They want to see how you think, not perfection.&lt;/p&gt;

&lt;p&gt;If your portfolio tells a clear story about how you think and learn, interviews will come.&lt;/p&gt;



&lt;p&gt;If you’re a beginner and this hit close to home, you’re not behind.&lt;br&gt;
You probably just need to &lt;strong&gt;reframe how you present your work&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If this helped, drop a 💬 or 🧡&lt;/p&gt;

&lt;p&gt;Connect with me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@giftegbonyi" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;I share short, practical dev lessons regularly.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reach out to me for your web development gigs:
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Email: &lt;a href="mailto:egbonyigiftvicky@gmail.com"&gt;egbonyigiftvicky@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next week! 🚀&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>remote</category>
      <category>career</category>
      <category>interview</category>
      <category>beginners</category>
    </item>
    <item>
      <title>dilemma!</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Thu, 22 Jan 2026 22:45:36 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/dilemma-4fp6</link>
      <guid>https://dev.to/giftysoftdev/dilemma-4fp6</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Heyy friends 👋🏽&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I’ve been in a bit of a dilemma lately.&lt;/p&gt;

&lt;p&gt;I can’t decide whether to keep doing tutorial-style posts like I’ve been doing, switch to more raw (unfiltered), real-life talks about my software engineering journey, or just mix both.&lt;/p&gt;

&lt;p&gt;If my content has helped you in any way before, I’d genuinely love to hear from you on what you think.&lt;/p&gt;

&lt;p&gt;I’m intentional about making the most of my time here. I want to share the unfiltered side of tech that people rarely talk about, while still breaking down complex concepts into something easy to grasp.&lt;/p&gt;

&lt;p&gt;The issue is, I feel like I’ve got a lot to offer, and I’m struggling to narrow it down.&lt;br&gt;
And honestly, what better way to decide than to hear directly from you?&lt;/p&gt;

&lt;p&gt;So please, let me know your thoughts.&lt;/p&gt;



&lt;p&gt;Connect with me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@giftegbonyi" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;I share short, practical dev lessons regularly.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reach out to me for your web development gigs:
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Email: &lt;a href="mailto:egbonyigiftvicky@gmail.com"&gt;egbonyigiftvicky@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next week! 🚀&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Don’t start with these databases as a beginner</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 14 Jan 2026 19:45:33 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/dont-start-with-these-databases-as-a-beginner-5750</link>
      <guid>https://dev.to/giftysoftdev/dont-start-with-these-databases-as-a-beginner-5750</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy New Year!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This year, we'll keep the momentum goin', so let's jump right into it!&lt;/p&gt;

&lt;p&gt;I see many beginners jump straight into databases that add &lt;strong&gt;unnecessary complexity&lt;/strong&gt; to their projects.&lt;br&gt;
It usually starts well, then turns into frustration when shipping to production.&lt;/p&gt;

&lt;p&gt;Let’s talk about two common ones.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ PostgreSQL&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;PostgreSQL is powerful. No debate there.&lt;br&gt;
But power comes with trade-offs that beginners often underestimate.&lt;/p&gt;

&lt;p&gt;What usually happens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hosting it in production is not straightforward&lt;/li&gt;
&lt;li&gt;Managing it without an ORM like Prisma can be stressful&lt;/li&gt;
&lt;li&gt;Even with tools like pgAdmin, the interface is hard to navigate&lt;/li&gt;
&lt;li&gt;Most hosting providers (Render, Railway, etc.) only offer short free periods&lt;/li&gt;
&lt;li&gt;Once the free tier ends, you either pay or risk losing your data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yes, Supabase exists.&lt;br&gt;
But that introduces another layer you now need to learn and maintain.&lt;/p&gt;

&lt;p&gt;For someone still learning backend basics, this is a lot.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ SQLite&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;SQLite is excellent... &lt;em&gt;&lt;strong&gt;locally&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It’s simple, fast and perfect for learning.&lt;/p&gt;

&lt;p&gt;But in production?&lt;br&gt;
It falls apart.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It’s not built for multiple concurrent users&lt;/li&gt;
&lt;li&gt;It doesn’t handle real-world traffic well&lt;/li&gt;
&lt;li&gt;It’s fine for demos and practice projects, not client-facing apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use SQLite to learn.&lt;br&gt;
Don’t ship it to production for real users.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;What beginners often overlook 👇🏽&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As a developer, your job isn’t just to write code.&lt;/p&gt;

&lt;p&gt;You evaluate &lt;strong&gt;cost, scale and trade-offs&lt;/strong&gt; before writing a single line.&lt;/p&gt;

&lt;p&gt;When you’re building for a client, ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is their budget?&lt;/li&gt;
&lt;li&gt;Who will maintain this later?&lt;/li&gt;
&lt;li&gt;What happens when the free tier ends?&lt;/li&gt;
&lt;li&gt;Is this tool solving the problem, or adding complexity?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Good developers don’t chase the latest tech.&lt;br&gt;
They make &lt;strong&gt;smart, sustainable technical decisions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s what clients actually pay for.&lt;/p&gt;


&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;If you’re a beginner, start simple.&lt;br&gt;
There’s no prize for making your life harder than it needs to be.&lt;/p&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If this helped you, leave a 💬 or 🧡&lt;br&gt;
I share short, practical dev lessons like this regularly.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reach out to me for your web development gigs:
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;br&gt;
Email: &lt;a href="mailto:egbonyigiftvicky@gmail.com"&gt;egbonyigiftvicky@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next week! 🚀&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>backend</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why == and === behave differently in JavaScript</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Fri, 12 Dec 2025 16:51:30 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/why-and-behave-differently-in-javascript-4b0g</link>
      <guid>https://dev.to/giftysoftdev/why-and-behave-differently-in-javascript-4b0g</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Hey friends! 👋&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you’ve ever compared two values and got an unexpected result, don’t worry, that happens lots of times with &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;. JavaScript comparisons can be behave strangely until you know what’s happening behind the scenes.&lt;/p&gt;

&lt;p&gt;I'm going to make this as simple as possible.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ &lt;code&gt;===&lt;/code&gt; → Strict equality&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;===&lt;/code&gt; checks two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Are the values the same?&lt;/li&gt;
&lt;li&gt;Are the &lt;em&gt;types&lt;/em&gt; the same?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both must match.&lt;/p&gt;

&lt;p&gt;Examples:&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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;        &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;      &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;     &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the types don’t match, JavaScript won’t even try. It just says “nope”.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ &lt;code&gt;==&lt;/code&gt; → Loose equality&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;==&lt;/code&gt; tries to be “helpful” by converting values &lt;em&gt;before&lt;/em&gt; comparing them.&lt;br&gt;
This is called &lt;strong&gt;type coercion&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Examples:&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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;       &lt;span class="c1"&gt;// true  (string → number)&lt;/span&gt;
&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;      &lt;span class="c1"&gt;// true  (boolean → number)&lt;/span&gt;
&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;     &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="c1"&gt;// true  (special case)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks helpful…&lt;br&gt;
but this “helpfulness” is what leads to weird behaviour 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="dl"&gt;""&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;        &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;       &lt;span class="c1"&gt;// true&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="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re not meant to memorise these.&lt;br&gt;
The rule is simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;==&lt;/code&gt; converts. &lt;code&gt;===&lt;/code&gt; doesn’t.&lt;/strong&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣ Why this happens&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;JavaScript tries to compare values with &lt;code&gt;==&lt;/code&gt; by making them the same type first.&lt;/p&gt;

&lt;p&gt;A few conversions that happen behind the scenes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strings → numbers&lt;/li&gt;
&lt;li&gt;booleans → numbers&lt;/li&gt;
&lt;li&gt;arrays → strings&lt;/li&gt;
&lt;li&gt;null and undefined → &lt;em&gt;only equal to each other&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It does all these steps automatically — which is why it gets confusing fast.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣ Which one should you use?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For beginners (and honestly, most cases), stick with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;===&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s predictable.&lt;br&gt;
It won’t surprise you.&lt;br&gt;
And it forces you to know what type you’re comparing.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;==&lt;/code&gt; only when you &lt;em&gt;fully&lt;/em&gt; understand the conversion rules — or when you specifically want:&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to be true.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5️⃣ A simple demo&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Try this in your console:&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="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// false&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;5&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// true&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;5&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll instantly see the difference.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6️⃣ Quick summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison&lt;/th&gt;
&lt;th&gt;Checks Type?&lt;/th&gt;
&lt;th&gt;Converts Values?&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;===&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"3" === 3&lt;/code&gt; → false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"3" == 3&lt;/code&gt; → true&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Short version:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;===&lt;/code&gt; is strict and honest.&lt;br&gt;
&lt;code&gt;==&lt;/code&gt; tries too hard.&lt;/strong&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;If JavaScript comparisons have ever confused you, it’s not your fault.&lt;br&gt;
The coercion rules behind &lt;code&gt;==&lt;/code&gt; are messy.&lt;br&gt;
Using &lt;code&gt;===&lt;/code&gt; gives you cleaner logic and fewer surprises.&lt;/p&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;hopefully, on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What happens when you type a URL into your browser?</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 26 Nov 2025 19:40:22 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/what-happens-when-you-type-a-url-into-your-browser-277l</link>
      <guid>https://dev.to/giftysoftdev/what-happens-when-you-type-a-url-into-your-browser-277l</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Hey friends! 👋&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s talk about something we all do every day:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typing a URL into your browser&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In case you don’t know what a URL is: URL stands for &lt;strong&gt;&lt;em&gt;Uniform Resource Locator&lt;/em&gt;&lt;/strong&gt;. It’s basically the address of a webpage, just like your home address tells people where you live, a URL tells the internet where a page is located.&lt;/p&gt;

&lt;p&gt;We type URLs so casually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://google.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…but a lot happens behind the scenes before that page appears on your screen.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ The browser checks the URL&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Your browser first checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is this a valid URL?&lt;/li&gt;
&lt;li&gt;is it HTTP or HTTPS?&lt;/li&gt;
&lt;li&gt;which domain are we visiting?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing is loaded yet, it's just making sure the link is valid.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ It looks in the cache&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Your browser asks itself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Have I seen this page before?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It checks cached files like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;images&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If it finds something fresh enough, it may skip some steps and load faster.&lt;br&gt;
If not, it moves on.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣ DNS: Finding the website’s address&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Computers don’t understand names like &lt;code&gt;google.com&lt;/code&gt;.&lt;br&gt;
They use IP addresses like:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;So the browser asks a DNS server:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What is the IP address for this domain?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the server knows, it replies with the correct address.&lt;br&gt;
Now your browser knows where on the internet to go.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣ Your browser says hello to the server&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once the IP address is known, the browser reaches out to the server hosting the site using HTTP or HTTPS.&lt;/p&gt;

&lt;p&gt;This is basically a digital handshake:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hi, can you send me the page for google.com?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With HTTPS, this handshake is encrypted to keep your data safe.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;5️⃣ The server sends the HTML back&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If everything is fine, the server responds with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML (the main file)&lt;/li&gt;
&lt;li&gt;links to CSS, images, scripts, fonts, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The browser now starts building the webpage.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;6️⃣ The browser builds the page step by step&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This part is called &lt;strong&gt;rendering&lt;/strong&gt;, and it happens in three simple steps:&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Builds the DOM
&lt;/h4&gt;

&lt;p&gt;Turns HTML into a tree of elements.&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Builds the CSSOM
&lt;/h4&gt;

&lt;p&gt;Applies your CSS rules.&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Renders everything visually
&lt;/h4&gt;

&lt;p&gt;Combines both trees to draw the page.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;layouts&lt;/li&gt;
&lt;li&gt;colours&lt;/li&gt;
&lt;li&gt;buttons&lt;/li&gt;
&lt;li&gt;text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;all appear where they should.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;7️⃣ JavaScript runs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After rendering starts, JavaScript files load.&lt;br&gt;
These files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fetch data&lt;/li&gt;
&lt;li&gt;handle clicks&lt;/li&gt;
&lt;li&gt;update the UI&lt;/li&gt;
&lt;li&gt;power animations&lt;/li&gt;
&lt;li&gt;run app logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is when the page becomes “interactive”.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;8️⃣ The page finally appears&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once everything above is done, you see the final webpage — and the browser keeps running scripts or fetching data as needed.&lt;/p&gt;

&lt;p&gt;All of this happens in a &lt;em&gt;&lt;em&gt;twinkle of an eye&lt;/em&gt;&lt;/em&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;So the next time you type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://gift-egbonyi.onrender.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember this little journey:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;URL → Cache → DNS → Server → HTML → DOM → CSS → Render → JavaScript → Page.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s a lot of steps, but browsers make it feel instant.&lt;/p&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;hopefully, on time like today!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>browser</category>
      <category>beginners</category>
      <category>behinddscenes</category>
      <category>dns</category>
    </item>
    <item>
      <title>Why you should stop writing long functions</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Thu, 20 Nov 2025 16:18:52 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/why-you-should-stop-writing-long-functions-1588</link>
      <guid>https://dev.to/giftysoftdev/why-you-should-stop-writing-long-functions-1588</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Hey friends! 👋&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s talk about something every beginner struggles with:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why you should stop writing long functions and how to break them into smaller ones&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Long functions feel "easy" when you're starting out.&lt;br&gt;
You want the code to work, and you don't understand how to break them into smaller functions, or in what order to call these small functions, so everything goes into one place.&lt;/p&gt;

&lt;p&gt;But over time, those &lt;em&gt;bulky&lt;/em&gt; functions turn into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;untraceable bugs&lt;/li&gt;
&lt;li&gt;code that’s hard to read&lt;/li&gt;
&lt;li&gt;features that are difficult to update&lt;/li&gt;
&lt;li&gt;unnecessary stress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Smaller functions make your code cleaner and easier to reason about.&lt;/p&gt;

&lt;p&gt;This is what I mean.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ Long functions hide mistakes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Take this 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;processUser&lt;/span&gt; &lt;span class="o"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Validate&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&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;@&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Format&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&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;name&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="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Save&lt;/span&gt;
  &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&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="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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&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;email&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

  &lt;span class="c1"&gt;// Notify&lt;/span&gt;
  &lt;span class="nf"&gt;alert&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 saved!&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;It works.&lt;br&gt;
But it mixes &lt;strong&gt;validation&lt;/strong&gt;, &lt;strong&gt;formatting&lt;/strong&gt;, &lt;strong&gt;saving&lt;/strong&gt; and &lt;strong&gt;notifications&lt;/strong&gt; features in one place.&lt;br&gt;
If something breaks, you probably mightn't spot the issue very fast.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ Smaller functions focus on one job&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, let’s split 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;validateUser&lt;/span&gt; &lt;span class="o"&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="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="o"&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;email&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;@&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid email&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;formatUser&lt;/span&gt; &lt;span class="o"&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="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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&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="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;email&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;email&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;saveUser&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&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="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;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;const&lt;/span&gt; &lt;span class="nx"&gt;notify&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="nf"&gt;alert&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 saved!&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;processUser&lt;/span&gt; &lt;span class="o"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;validateUser&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;formatUser&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;saveUser&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="nf"&gt;notify&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 you can see exactly what’s happening at a glance.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣ Smaller functions make testing easier&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Which one would you rather test?&lt;/p&gt;

&lt;p&gt;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="nf"&gt;processUser&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gift&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gift@gmail.com&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;or these?&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="nf"&gt;validateUser&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;formatUser&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="c1"&gt;// etc.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why experts like short functions that focus on one feature:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;let you test one idea at a time.&lt;/li&gt;
&lt;li&gt;spot bugs earlier.&lt;/li&gt;
&lt;li&gt;other developers can easily read your code,&lt;/li&gt;
&lt;li&gt;helpful when you use a JavaScript framework like React.js which is components based.&lt;/li&gt;
&lt;li&gt;helpful in next.js.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣ I promise, your future self will thank you!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Readable code isn’t for others alone.&lt;br&gt;
It’s for you in two months when you no longer remember what you wrote.&lt;/p&gt;

&lt;p&gt;Splitting functions forces you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;name things clearly&lt;/li&gt;
&lt;li&gt;structure your logic&lt;/li&gt;
&lt;li&gt;avoid hidden behaviours&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a habit that pays off quickly.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;How to break a long function into smaller pieces&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A simple approach:&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Step 1: Look for sections that do different jobs
&lt;/h4&gt;

&lt;p&gt;Validation, fetching, formatting, rendering and separate them.&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Step 2: Extract each section into its own function
&lt;/h4&gt;

&lt;p&gt;Give each one a short, clear name.&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Step 3: Keep each function focused
&lt;/h4&gt;

&lt;p&gt;One idea per function.&lt;br&gt;
If a function starts doing two things, break it again.&lt;/p&gt;
&lt;h4&gt;
  
  
  ✔️ Step 4: Call them in order
&lt;/h4&gt;

&lt;p&gt;Your main function becomes a clean “storyline”.&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;Quick before/after&lt;/strong&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ❌ Before
&lt;/h4&gt;

&lt;p&gt;One big block:&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;checkout&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="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// validate&lt;/span&gt;
  &lt;span class="c1"&gt;// calculate&lt;/span&gt;
  &lt;span class="c1"&gt;// update UI&lt;/span&gt;
  &lt;span class="c1"&gt;// save to server&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✔️ After
&lt;/h3&gt;

&lt;p&gt;Small clear steps:&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;validateCart&lt;/span&gt; &lt;span class="o"&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="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;calculateTotal&lt;/span&gt; &lt;span class="o"&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="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;updateUI&lt;/span&gt; &lt;span class="o"&gt;=&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="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;saveToServer&lt;/span&gt; &lt;span class="o"&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="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;checkout&lt;/span&gt; &lt;span class="o"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;validateCart&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="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="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;updateUI&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="nf"&gt;saveToServer&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much easier to maintain.&lt;/p&gt;




&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;Short functions make your code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cleaner&lt;/li&gt;
&lt;li&gt;easier to debug&lt;/li&gt;
&lt;li&gt;painless to update&lt;/li&gt;
&lt;li&gt;easier for other developers to read&lt;/li&gt;
&lt;li&gt;kinder on your future self&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start small. Refactor bit by bit.&lt;br&gt;
Your codebase and your future self will thank you.&lt;br&gt;
That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;hopefully, on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>performance</category>
    </item>
    <item>
      <title>What happens when you type console.log()?</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Fri, 14 Nov 2025 20:45:43 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/what-happens-when-you-type-consolelog-3k4p</link>
      <guid>https://dev.to/giftysoftdev/what-happens-when-you-type-consolelog-3k4p</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;Hey friends! 👋&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Two days late! I'm not nailing this &lt;em&gt;adulting&lt;/em&gt; as I should fr. I missed our usual Wednesday hangout, but with just reason ofcourse. I won't bore you with the details, so here’s a quick, light tutorial to make it up.&lt;/p&gt;

&lt;p&gt;We always 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="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;Hello world!&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;…but have you ever wondered &lt;strong&gt;what actually happens&lt;/strong&gt; when that line runs?&lt;/p&gt;

&lt;p&gt;Let’s break it down in a simple way.&lt;/p&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;What Happens When You Type &lt;code&gt;console.log()&lt;/code&gt;?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;JavaScript doesn’t magically push text onto the screen. A few things happen behind the scenes, fast enough that we don’t notice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s the journey.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1️⃣ Your code gets parsed&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before anything runs, the browser checks your code for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;valid syntax&lt;/li&gt;
&lt;li&gt;correct placement of parentheses&lt;/li&gt;
&lt;li&gt;missing commas&lt;/li&gt;
&lt;li&gt;stray characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If all is fine, it creates something called the &lt;strong&gt;execution context&lt;/strong&gt;.&lt;br&gt;
(Think of it as preparing the environment.)&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;2️⃣ JavaScript reaches the &lt;code&gt;.log()&lt;/code&gt; call&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When execution gets to your line:&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;Hello&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;JavaScript doesn’t print anything itself.&lt;br&gt;
Instead, it sees:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;console&lt;/code&gt; → an object provided by the browser&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;log&lt;/code&gt; → a method inside that object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"Hello"&lt;/code&gt; → the argument you’re sending&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;3️⃣ The browser steps in&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;console&lt;/code&gt; object isn’t part of JavaScript.&lt;br&gt;
It’s provided by your browser (Chrome, Firefox, Safari, etc.) through the &lt;strong&gt;Web APIs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you call:&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;Hello&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’re basically saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Browser, please take this value and show it in your developer tools.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4️⃣ The browser forwards the text to the DevTools console&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Your browser receives &lt;code&gt;"Hello"&lt;/code&gt; and pushes it into the DevTools output area.&lt;/p&gt;

&lt;p&gt;That’s why you can customise the console, clear it, filter logs, and change colours — it’s the browser doing the work, not JavaScript.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;5️⃣ The call completes&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;log()&lt;/code&gt; method finishes and returns &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
(That’s why running &lt;code&gt;console.log(console.log("Hi"))&lt;/code&gt; prints &lt;code&gt;Hi&lt;/code&gt; and then &lt;code&gt;undefined&lt;/code&gt;.)&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;Why do I even need this information?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Well, understanding this tiny journey helps beginners:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;see the difference between JavaScript and browser features&lt;/li&gt;
&lt;li&gt;understand why &lt;code&gt;console.log()&lt;/code&gt; behaves differently in Node.js&lt;/li&gt;
&lt;li&gt;avoid thinking the console is part of the core language&lt;/li&gt;
&lt;li&gt;debug smarter&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;Try this out&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Open your browser console and run:&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gift&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll notice you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;expand the object&lt;/li&gt;
&lt;li&gt;inspect properties&lt;/li&gt;
&lt;li&gt;view it in different formats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s the browser again not JavaScript.&lt;/p&gt;




&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;So the next time you type:&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;testing…&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’ll know the journey:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parse → Execute → Browser handles it → DevTools prints it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Small detail.&lt;br&gt;
But...&lt;br&gt;
Nice to know.&lt;/p&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;hopefully, on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>consolelog</category>
      <category>javascript</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding the `this` Keyword in JavaScript</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 05 Nov 2025 18:45:26 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/understanding-the-this-keyword-in-javascript-4ipi</link>
      <guid>https://dev.to/giftysoftdev/understanding-the-this-keyword-in-javascript-4ipi</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends! 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s another Wednesday, and yes, we’re still learning JavaScript together!&lt;/p&gt;

&lt;p&gt;Today’s topic is one that confuses &lt;em&gt;almost everyone&lt;/em&gt; when they first start out: the &lt;code&gt;this&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Let’s simplify it and see how it works using a live demo.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is &lt;code&gt;this&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; refers to &lt;strong&gt;the object that owns the code being executed&lt;/strong&gt;.&lt;br&gt;
But what that &lt;em&gt;means&lt;/em&gt; depends on &lt;strong&gt;how&lt;/strong&gt; and &lt;strong&gt;where&lt;/strong&gt; you use it.&lt;/p&gt;

&lt;p&gt;Let’s look at 4 common places you’ll see &lt;code&gt;this&lt;/code&gt; in action.&lt;/p&gt;


&lt;h3&gt;
  
  
  1️⃣ In the Global Scope
&lt;/h3&gt;

&lt;p&gt;In browsers, &lt;code&gt;this&lt;/code&gt; in the global scope refers to the &lt;code&gt;window&lt;/code&gt; object.&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// window&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2️⃣ Inside an Object Method
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;this&lt;/code&gt; is used inside a method, it refers to the object that owns the method.&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gifty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;greet&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;Hi, I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&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;name&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="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Hi, I'm Gifty"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3️⃣ Inside a Regular Function
&lt;/h3&gt;

&lt;p&gt;If you use &lt;code&gt;this&lt;/code&gt; inside a normal function (not part of an object),&lt;br&gt;
&lt;code&gt;this&lt;/code&gt; will be &lt;code&gt;undefined&lt;/code&gt; in strict mode — or &lt;code&gt;window&lt;/code&gt; in non-strict mode.&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;showThis&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;showThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// undefined (in strict mode)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4️⃣ Inside an Arrow Function
&lt;/h3&gt;

&lt;p&gt;Arrow functions don’t have their own &lt;code&gt;this&lt;/code&gt;.&lt;br&gt;
They &lt;em&gt;inherit&lt;/em&gt; &lt;code&gt;this&lt;/code&gt; from where they were created.&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GiftySoftDev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;arrow&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;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;this&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="c1"&gt;// undefined&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nf"&gt;regular&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="k"&gt;this&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="c1"&gt;// "GiftySoftDev"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;regular&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧑‍💻 CodePen Demo
&lt;/h2&gt;

&lt;p&gt;Play with &lt;code&gt;this&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We’ll build a mini visualiser that lets you click buttons to see what &lt;code&gt;this&lt;/code&gt; refers to in each context.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;HTML&lt;/strong&gt;
&lt;/h3&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;JavaScript "this" Visualiser&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Click the buttons below to see what &lt;span class="nt"&gt;&amp;lt;code&amp;gt;&lt;/span&gt;this&lt;span class="nt"&gt;&amp;lt;/code&amp;gt;&lt;/span&gt; refers to!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"globalBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Global Scope&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"methodBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Object Method&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"regularBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Regular Function&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"arrowBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Arrow Function&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"eventBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Event Listener&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"output"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"output"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click a button to see the result 👇&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;CSS&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;system-ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&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="nb"&gt;center&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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f7f7f7&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;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&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="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&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="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt; &lt;span class="m"&gt;14px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&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="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#4f46e5&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;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;14px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&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;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#4338ca&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.output&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;dashed&lt;/span&gt; &lt;span class="m"&gt;#ccc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fafafa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;monospace&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;JavaScript&lt;/strong&gt;
&lt;/h3&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;output&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;output&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;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;label&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;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&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;label&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;value&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;// Global scope&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;globalBtn&lt;/span&gt;&lt;span class="dl"&gt;"&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;click&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="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Global this&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;window&lt;/span&gt;&lt;span class="dl"&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="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Object method&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;methodBtn&lt;/span&gt;&lt;span class="dl"&gt;"&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;click&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="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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gifty&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Object Method&lt;/span&gt;&lt;span class="dl"&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;name&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="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Regular function&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;regularBtn&lt;/span&gt;&lt;span class="dl"&gt;"&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;click&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="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;showThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Regular Function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;window&lt;/span&gt;&lt;span class="dl"&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="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;showThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Arrow function&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;arrowBtn&lt;/span&gt;&lt;span class="dl"&gt;"&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;click&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="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;arrow&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="nf"&gt;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arrow Function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;window&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;arrow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Event listener&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;eventBtn&lt;/span&gt;&lt;span class="dl"&gt;"&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;click&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="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;logResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Event Listener&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`this is the button with text: "&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;textContent&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;h3&gt;
  
  
  How the Demo Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global Scope:&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt; → &lt;code&gt;window&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object Method:&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt; → the object (&lt;code&gt;user&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regular Function:&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt; → &lt;code&gt;undefined&lt;/code&gt; (in strict mode)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arrow Function:&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt; → the outer context (inherits)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Listener:&lt;/strong&gt; &lt;code&gt;this&lt;/code&gt; → the element that triggered the event&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 &lt;a href="https://codepen.io/GiftySoftDev/pen/RNrmGxo" rel="noopener noreferrer"&gt;Try it on CodePen&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; can be tricky — but once you understand how it’s set depending on &lt;em&gt;where&lt;/em&gt; and &lt;em&gt;how&lt;/em&gt; a function runs, it starts to make sense.&lt;/p&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Context&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;this&lt;/code&gt; refers to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Global scope&lt;/td&gt;
&lt;td&gt;&lt;code&gt;window&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Object method&lt;/td&gt;
&lt;td&gt;The object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Regular function&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;undefined&lt;/code&gt; (strict mode)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arrow function&lt;/td&gt;
&lt;td&gt;Inherits from outer scope&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Event listener&lt;/td&gt;
&lt;td&gt;The element clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/GifTeaze?s=09" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>this</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding JavaScript Closures</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Thu, 30 Oct 2025 14:16:49 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/understanding-javascript-closures-50ji</link>
      <guid>https://dev.to/giftysoftdev/understanding-javascript-closures-50ji</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends! 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I couldn't make it yesterday and I feel sad about that 😔. I lost a relative so I was at her wake. But I'm here today :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today is &lt;strong&gt;closures&lt;/strong&gt;, one of those concepts that seems a bit complex but actually very practical once you see it in action.&lt;/p&gt;

&lt;p&gt;Closures occur when a function &lt;strong&gt;remembers variables from its outer scope&lt;/strong&gt;, even after that outer function has finished running.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example 1: Basic Closure
&lt;/h2&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;greet&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello&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="kd"&gt;function&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;greeting&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;name&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Hello, Alice!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;greet('Alice')&lt;/code&gt; returns a function.&lt;/li&gt;
&lt;li&gt;That returned function &lt;strong&gt;remembers&lt;/strong&gt; the variables &lt;code&gt;greeting&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Even though &lt;code&gt;greet&lt;/code&gt; has finished executing, &lt;code&gt;sayHello()&lt;/code&gt; still works.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example 2: Counter with Closure
&lt;/h2&gt;

&lt;p&gt;Closures are perfect for keeping &lt;strong&gt;private variables&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;function&lt;/span&gt; &lt;span class="nf"&gt;createCounter&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;count&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="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&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;count&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 2&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;counter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; is private. You can’t access it directly from outside.&lt;/li&gt;
&lt;li&gt;Each call remembers the previous value.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example 3: Real-World Use Case
&lt;/h2&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;makeMultiplier&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;double&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;makeMultiplier&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;triple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;makeMultiplier&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="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;double&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="c1"&gt;// 10&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;triple&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="c1"&gt;// 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Closures let us create flexible and reusable functions.&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Here is a Challenge for You
&lt;/h3&gt;

&lt;p&gt;No codepen today but can you answer the question 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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;secretPassword&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="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;guess&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;guess&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Access granted&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;Access denied&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;checkPassword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;secretPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1234&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="nf"&gt;checkPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&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;checkPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1234&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;“Why does this work even though &lt;code&gt;secretPassword&lt;/code&gt; has finished running?”&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A closure is a function &lt;strong&gt;remembering its scope&lt;/strong&gt; even after execution.&lt;/li&gt;
&lt;li&gt;Useful for &lt;strong&gt;private data&lt;/strong&gt;, &lt;strong&gt;partial application&lt;/strong&gt;, and &lt;strong&gt;factory functions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Always think: &lt;em&gt;“Which variables does this function remember?”&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>closures</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding Time vs Space Complexity: Why You Can’t Always Optimise Both</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 22 Oct 2025 14:38:08 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/understanding-time-vs-space-complexity-why-you-cant-always-optimise-both-2k5i</link>
      <guid>https://dev.to/giftysoftdev/understanding-time-vs-space-complexity-why-you-cant-always-optimise-both-2k5i</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends! 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm excited to be on time for our date! I’ve been working on my time management lately, and one thing that helps is turning on &lt;strong&gt;Work Mode&lt;/strong&gt; on my iPhone. It keeps me focused on things like this. :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Last few Wednesdays, we looked at &lt;strong&gt;running time&lt;/strong&gt; and &lt;strong&gt;space complexity&lt;/strong&gt; separately.&lt;br&gt;
Today, let’s see how they interact.&lt;/p&gt;

&lt;p&gt;Sometimes, you can make your program &lt;strong&gt;faster&lt;/strong&gt; by using more memory.&lt;br&gt;
Other times, you can &lt;strong&gt;save memory&lt;/strong&gt;, but it’ll take longer to run.&lt;/p&gt;

&lt;p&gt;That’s the &lt;strong&gt;time–space trade-off&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚖️ Examples of the Trade-Off
&lt;/h2&gt;

&lt;p&gt;i. Faster at the cost of memory&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;// Precompute squares (uses more memory)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;squares&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="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Accessing a square is O(1)&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;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// super fast&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Time:&lt;/em&gt; &lt;strong&gt;O(1)&lt;/strong&gt; (instant lookup)&lt;br&gt;
&lt;em&gt;Space:&lt;/em&gt; &lt;strong&gt;O(n)&lt;/strong&gt; (stored 1000 numbers)&lt;/p&gt;



&lt;p&gt;ii. Less memory at the cost of time&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;// Compute squares on the fly (uses less memory)&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getSquare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;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;return&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;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="nf"&gt;getSquare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// slower for repeated lookups&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Time:&lt;/em&gt; &lt;strong&gt;O(1)&lt;/strong&gt; per calculation, but repeated calls take longer overall&lt;br&gt;
&lt;em&gt;Space:&lt;/em&gt; &lt;strong&gt;O(1)&lt;/strong&gt; (no array stored)&lt;/p&gt;


&lt;h3&gt;
  
  
  The takeaway
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There’s no perfect balance.&lt;/li&gt;
&lt;li&gt;Faster algorithms often use extra memory.&lt;/li&gt;
&lt;li&gt;Memory-efficient ones might run slower.&lt;/li&gt;
&lt;li&gt;Knowing both helps you make smarter design choices.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧑🏾‍💻 Visualise It: CodePen Demo
&lt;/h2&gt;

&lt;p&gt;We’ll build a simple &lt;strong&gt;chart&lt;/strong&gt; to show the trade-off:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Precomputed array → fast but memory-hungry&lt;/li&gt;
&lt;li&gt;On-the-fly computation → slower but light on memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Move the &lt;strong&gt;slider&lt;/strong&gt; to change the input size, and watch how the chart updates.&lt;br&gt;
Hit &lt;strong&gt;Reset&lt;/strong&gt; to start again.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://codepen.io/GiftySoftDev/pen/QwymMOz" rel="noopener noreferrer"&gt;Time vs Space Visualiser (CodePen)&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blue line:&lt;/strong&gt; Precomputed squares — fast, but memory increases with &lt;code&gt;n&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Green line:&lt;/strong&gt; On-the-fly — slower, minimal memory use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Yellow line:&lt;/strong&gt; Memory usage for the precomputed array.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  🙋🏾‍♀️ Wrap-Up
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Complexity&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Constant space&lt;/td&gt;
&lt;td&gt;Simple maths or fixed variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Grows with input&lt;/td&gt;
&lt;td&gt;Building an array or list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;Grows faster&lt;/td&gt;
&lt;td&gt;Nested loops creating data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
What should we talk about next Wednesday? Drop it below 👇&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Drop them in the 💬, I love feedback.&lt;/p&gt;



&lt;p&gt;I’m keeping these light, fun, and useful, one small project at a time.&lt;br&gt;
If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/p&gt;

&lt;p&gt;Follow me for more short, beginner-friendly JavaScript lessons every week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or full-time.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you next Wednesday 🚀, &lt;em&gt;on time!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Till then, write clean code and stay curious. 🦋&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>space</category>
      <category>time</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Space Complexity</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 15 Oct 2025 21:54:59 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/understanding-space-complexity-5fk2</link>
      <guid>https://dev.to/giftysoftdev/understanding-space-complexity-5fk2</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends! 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Better late than never right? :)&lt;/p&gt;

&lt;p&gt;Last week, we talked about &lt;em&gt;running time&lt;/em&gt; which is how fast your program runs.&lt;br&gt;
This week, let’s look at its quieter sibling: &lt;strong&gt;space complexity&lt;/strong&gt; which is &lt;strong&gt;how much memory your program uses&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you write code, it doesn’t just take time to run; it also takes &lt;strong&gt;memory&lt;/strong&gt; to store variables, data structures and temporary values.&lt;br&gt;
Sometimes your program runs fast but eats up too much memory. That’s where space complexity comes in.&lt;/p&gt;


&lt;h3&gt;
  
  
  What’s Space Complexity?
&lt;/h3&gt;

&lt;p&gt;It’s the total amount of memory a program needs to complete its work.&lt;br&gt;
That includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables and constants&lt;/li&gt;
&lt;li&gt;Function call stack&lt;/li&gt;
&lt;li&gt;Data structures like arrays, objects, or linked lists&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You’ll often see it written like &lt;strong&gt;O(n)&lt;/strong&gt;, just like time complexity but here, it means &lt;em&gt;memory grows with input size&lt;/em&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Example 1: Constant Space (O(1))
&lt;/h3&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;sum&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="c1"&gt;// only stores a, b, and result&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;No matter how big your input is, this function uses the same small amount of memory.&lt;/p&gt;


&lt;h3&gt;
  
  
  Example 2: Linear Space (O(n))
&lt;/h3&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;makeArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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;arr&lt;/span&gt; &lt;span class="o"&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;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;n&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;arr&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;i&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;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, memory grows with the array size.&lt;br&gt;
If &lt;code&gt;n = 10&lt;/code&gt;, it stores 10 numbers.&lt;br&gt;
If &lt;code&gt;n = 10,000&lt;/code&gt;, it stores 10,000 numbers. That’s &lt;strong&gt;O(n)&lt;/strong&gt; space.&lt;/p&gt;


&lt;h3&gt;
  
  
  Why It's Relevant
&lt;/h3&gt;

&lt;p&gt;Imagine running an app on a cheap phone.&lt;br&gt;
If your algorithm keeps duplicating arrays or creating new objects in loops, it might crash or slow down — even if it’s fast in theory.&lt;/p&gt;

&lt;p&gt;Understanding space complexity helps you write code that’s both &lt;strong&gt;efficient and scalable&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Try It Out Yourself
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select an algorithm type (O(1), O(n), or O(n²)).&lt;/li&gt;
&lt;li&gt;Click Run Test.&lt;/li&gt;
&lt;li&gt;The chart plots how “memory usage” grows as input size increases.
It’s a simulation — not real browser memory — but the pattern matches what happens in real programs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Try Tweaking It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the JavaScript panel, find:&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;sizes&lt;/span&gt; &lt;span class="o"&gt;=&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;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sizes&lt;/span&gt; &lt;span class="o"&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Run Test again and watch how the curve changes.&lt;br&gt;
The quadratic one will skyrocket.&lt;/p&gt;

&lt;p&gt;👉 CodePen link: &lt;a href="https://codepen.io/GiftySoftDev/pen/YPwEyar" rel="noopener noreferrer"&gt;Space Complexity Visualiser&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  🙋🏽‍♀️ Wrap up!
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Complexity&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;td&gt;Constant space&lt;/td&gt;
&lt;td&gt;Simple math or fixed variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;Grows with input&lt;/td&gt;
&lt;td&gt;Building an array or list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;O(n²)&lt;/td&gt;
&lt;td&gt;Grows faster&lt;/td&gt;
&lt;td&gt;Nested loops creating data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That’s it for today!&lt;br&gt;
Next Wednesday, we’ll look at how &lt;strong&gt;time and space complexity work together&lt;/strong&gt; and why you can’t always optimise both at once.&lt;/p&gt;

&lt;p&gt;Till then, write clean code and stay curious!&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Or any insight to help me write better tutorials? Let me know in the 💬!&lt;/p&gt;



&lt;p&gt;That’s it for today’s midweek mini tutorial!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’m keeping things light, fun and useful; one small project at a time.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;And if you’ve got an idea for something you'd like me to try out next Wednesday, drop it in the comments. 👇&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow me to see more straight-forward and short tutorials like this :)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or fulltime. 
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)

:-)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails&lt;/strong&gt;&lt;br&gt;
You can also find me here on &lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
or here &lt;a href="https://x.com/gifty_softdev?s=21" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✍🏾 I’m documenting my learning loudly every Wednesday. Follow along if you're learning JavaScript too!&lt;br&gt;
Let’s keep learning together!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you, &lt;del&gt;same time&lt;/del&gt;, next Wednesday🚀&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>space</category>
      <category>dsa</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
    <item>
      <title>🕒 Running Time Wednesday! Understanding Big O (Made Simple)</title>
      <dc:creator>Gift Egbonyi</dc:creator>
      <pubDate>Wed, 08 Oct 2025 17:53:01 +0000</pubDate>
      <link>https://dev.to/giftysoftdev/running-time-wednesday-understanding-big-o-made-simple-4jpg</link>
      <guid>https://dev.to/giftysoftdev/running-time-wednesday-understanding-big-o-made-simple-4jpg</guid>
      <description>&lt;p&gt;It’s Running Time Wednesday!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey friends 👋&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like I stated last week, today, we are learning something that every developer should understand — &lt;strong&gt;running time&lt;/strong&gt;, also known as &lt;strong&gt;Big O notation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It sounds fancy, but it’s just a way to measure how fast (or slow) your code runs as your input grows.&lt;/p&gt;

&lt;p&gt;Let’s break it down.&lt;/p&gt;




&lt;h2&gt;
  
  
  What’s Running Time?
&lt;/h2&gt;

&lt;p&gt;Running time tells you &lt;strong&gt;how the performance of your code changes as the amount of data increases&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, sorting 10 items is quick. Sorting 10, 000 items? That’s where efficiency comes into play.&lt;/p&gt;

&lt;p&gt;So, Big O helps you predict how your program behaves when things scale (up or down).&lt;/p&gt;




&lt;h2&gt;
  
  
  Why “Big O”?
&lt;/h2&gt;

&lt;p&gt;“Big O” describes the &lt;strong&gt;order of growth&lt;/strong&gt;, in essence, how the number of operations grows compared to the size of the input (&lt;code&gt;n&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;We’re not counting seconds; we’re counting &lt;strong&gt;how many steps&lt;/strong&gt; your algorithm takes as &lt;code&gt;n&lt;/code&gt; increases.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Big O Notations
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Notation&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(1)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Constant time&lt;/td&gt;
&lt;td&gt;Doesn’t depend on input size&lt;/td&gt;
&lt;td&gt;Accessing an element by index&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(log n)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Logarithmic&lt;/td&gt;
&lt;td&gt;Grows slowly as input increases&lt;/td&gt;
&lt;td&gt;Binary search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(n)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linear&lt;/td&gt;
&lt;td&gt;Grows directly with input&lt;/td&gt;
&lt;td&gt;Looping through an array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(n log n)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linearithmic&lt;/td&gt;
&lt;td&gt;Common in efficient sorting&lt;/td&gt;
&lt;td&gt;Merge sort, quicksort&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(n²)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Quadratic&lt;/td&gt;
&lt;td&gt;Grows fast with nested loops&lt;/td&gt;
&lt;td&gt;Comparing every pair in a list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(2ⁿ)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Exponential&lt;/td&gt;
&lt;td&gt;Doubles with every new element&lt;/td&gt;
&lt;td&gt;Recursive Fibonacci&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O(n!)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Factorial&lt;/td&gt;
&lt;td&gt;Blows up quickly&lt;/td&gt;
&lt;td&gt;Generating all permutations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Quick Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ O(1) — Constant
&lt;/h3&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;getFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;arr&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;// One step, no matter how big arr is&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2️⃣ O(n) — Linear
&lt;/h3&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;printAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;arr&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;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Takes more time as arr grows&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3️⃣ O(n²) — Quadratic
&lt;/h3&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;printPairs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;arr&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;j&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;arr&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;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;j&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;// For 10 items = 100 operations&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Visualising Growth
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;O(1)     → constant line
O(log n) → slow curve
O(n)     → steady climb
O(n²)    → sharp rise
O(2ⁿ)    → rocket 🚀
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don’t need maths to get it — just imagine how the number of steps go up for larger inputs.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try It Yourself in CodePen
&lt;/h2&gt;

&lt;p&gt;👉 &lt;a href="https://codepen.io/GiftySoftDev/pen/qEbmjOo" rel="noopener noreferrer"&gt;Play with Running Time Examples&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick a function type – O(1), O(n), or O(n²)&lt;/li&gt;
&lt;li&gt;Click “Run Test.” The chart shows how long each one takes for different array sizes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Constant time stays flat, linear grows steadily, and quadratic shoots up fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try tweaking it&lt;/strong&gt;&lt;br&gt;
In the JavaScript panel, find this line:&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;sizes&lt;/span&gt; &lt;span class="o"&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="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change it to something bigger:&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;sizes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then click Run again.&lt;br&gt;
You’ll see the chart climb faster — that’s how running time scales with data.&lt;/p&gt;


&lt;h3&gt;
  
  
  🙋🏽‍♀️ Wrap up!
&lt;/h3&gt;

&lt;p&gt;Here’s the takeaway:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running time = how your algorithm scales (go up or down).&lt;/li&gt;
&lt;li&gt;Think of Big O as a way to predict how an algorithm will handle a huge amount of data. It's about growth, not how fast it runs right now.&lt;/li&gt;
&lt;li&gt;Aim for &lt;strong&gt;O(1)&lt;/strong&gt; or &lt;strong&gt;O(log n)&lt;/strong&gt; when possible, but clarity comes first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next Wednesday, we’ll connect this to &lt;strong&gt;space complexity&lt;/strong&gt;, that is, how much memory your program uses.&lt;/p&gt;

&lt;p&gt;Till then, write clean code and stay curious!&lt;/p&gt;

&lt;p&gt;Connect with me on &lt;a href="https://github.com/GiftySoftDev" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Was this tutorial helpful? Got questions? Or any insight to help me write better tutorials? Let me know in the 💬!&lt;/p&gt;



&lt;p&gt;That’s it for today’s midweek mini tutorial!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’m keeping things light, fun and useful; one small project at a time.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you enjoyed this, leave a 💬 or 🧡 to let me know.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;And if you’ve got an idea for something you'd like me to try out next Wednesday, drop it in the comments. 👇&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow me to see more straight-forward and short tutorials like this :)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;I'm still hunting for full stack roles,
contract or fulltime. 
Please check out my &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Portfolio&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://gift-egbonyi.onrender.com&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://gift-egbonyi.onrender.com" rel="noopener noreferrer"&gt;Portfolio&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web trails&lt;/strong&gt;&lt;br&gt;
You can also find me here on &lt;a href="https://www.linkedin.com/in/gift-egbonyi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;
or here &lt;a href="https://x.com/gifty_softdev?s=09" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✍🏾 I’m documenting my learning loudly every Wednesday. Follow along if you're learning JavaScript too!&lt;br&gt;
Let’s keep learning together!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;See you, same time, next Wednesday🚀&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>dsa</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
