<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Byte-Sized News</title>
    <description>The latest articles on Forem by Byte-Sized News (@byte-sized-news).</description>
    <link>https://forem.com/byte-sized-news</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%2Forganization%2Fprofile_image%2F9690%2F4b9d56fe-a826-4a7e-9824-c769b77692f3.png</url>
      <title>Forem: Byte-Sized News</title>
      <link>https://forem.com/byte-sized-news</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/byte-sized-news"/>
    <language>en</language>
    <item>
      <title>The Scheduler API: Prioritising Work on the Main Thread</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Thu, 19 Mar 2026 21:22:22 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/the-scheduler-api-prioritising-work-on-the-main-thread-2m66</link>
      <guid>https://forem.com/byte-sized-news/the-scheduler-api-prioritising-work-on-the-main-thread-2m66</guid>
      <description>&lt;p&gt;Every performance problem in the browser eventually traces back to the same crime: something blocked the main thread for too long.&lt;/p&gt;

&lt;p&gt;The user clicked a button. The browser wanted to run the click handler, repaint the changed pixel, and move on. But before it could, your application decided this was a great time to parse a 4 MB JSON payload, diff a 3,000-node virtual DOM, and synchronously compute analytics. The animation dropped frames. The button felt broken. The user noticed.&lt;/p&gt;

&lt;p&gt;We have spent years routing around this problem. Debouncing, throttling, Web Workers, &lt;code&gt;requestIdleCallback&lt;/code&gt;, virtualizing long lists — all of them are, at their core, strategies to stop doing too much on the main thread at once.&lt;/p&gt;

&lt;p&gt;The Scheduler API takes a different angle. It doesn't tell you to do less work. It lets you tell the browser which work matters &lt;em&gt;right now&lt;/em&gt; and which can wait — and it actually enforces that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why The Old Solutions Fall Short
&lt;/h2&gt;

&lt;p&gt;Before reaching for anything new, it's worth being honest about the tools that already exist.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;setTimeout(fn, 0)&lt;/code&gt; — The Classic Lie
&lt;/h3&gt;

&lt;p&gt;The canonical trick for "yielding to the browser" is wrapping work in a &lt;code&gt;setTimeout&lt;/code&gt; with a zero-delay:&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;setTimeout&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;doExpensiveWork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defers &lt;code&gt;doExpensiveWork&lt;/code&gt; until after the current synchronous call stack clears, which buys the browser a slot to repaint. It works, in the same way a Band-Aid works on a broken leg. The problem is that &lt;code&gt;setTimeout&lt;/code&gt; callbacks are scheduled into a single, undifferentiated queue. Your deferred analytics code and your deferred critical rendering code are both "just callbacks." There is no concept of importance.&lt;/p&gt;

&lt;p&gt;There's also the historical floor: browsers clamp &lt;code&gt;setTimeout&lt;/code&gt; delays to a minimum of &lt;strong&gt;4ms&lt;/strong&gt; after five nested calls, meaning you can't even rely on the zero-delay to mean "as soon as possible."&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;requestIdleCallback&lt;/code&gt; — The Right Idea, Wrong API
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;requestIdleCallback&lt;/code&gt; was a genuine step forward. It lets you schedule low-priority work for browser idle periods:&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;requestIdleCallback&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;deadline&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;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;()()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get a &lt;code&gt;deadline&lt;/code&gt; object, you check how much time is left in the idle period, and you process work until it runs out. This prevents your background work from stealing time from user interactions.&lt;/p&gt;

&lt;p&gt;But it has two cardinal limitations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No priority system.&lt;/strong&gt; &lt;code&gt;requestIdleCallback&lt;/code&gt; is a binary: it's either "idle work" or "not idle work." There's no way to say "run this before &lt;em&gt;that&lt;/em&gt; idle task, because it matters more."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unreliable under load.&lt;/strong&gt; When the main thread is busy, idle periods shrink or disappear entirely. Critical deferred work might literally never run during a heavy interaction-driven session.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;requestAnimationFrame&lt;/code&gt; — The Wrong Abstraction
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;requestAnimationFrame&lt;/code&gt; is for animation. Specifically, it fires before each paint, giving you a reliable hook for writing to the DOM without causing layout thrash. Developers sometimes abuse it as a general "next-tick" mechanism.&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;// This works but it's wrong.&lt;/span&gt;
&lt;span class="c1"&gt;// rAF is not meant for non-visual work.&lt;/span&gt;
&lt;span class="nf"&gt;requestAnimationFrame&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;processBatchOfNonVisualData&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;Using &lt;code&gt;rAF&lt;/code&gt; for non-rendering work wastes the 16ms animation budget on things that have nothing to do with the frame. It can actually &lt;em&gt;cause&lt;/em&gt; jank by forcing non-visual computation into a time slot that was supposed to be reserved for drawing.&lt;/p&gt;




&lt;p&gt;The common failure mode is the same across all three: &lt;strong&gt;no shared, priority-aware queue&lt;/strong&gt;. Each of these APIs is its own island. The browser has no way to reason about relative importance across them.&lt;/p&gt;

&lt;p&gt;That's the gap the Scheduler API is filling.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Scheduler API
&lt;/h2&gt;

&lt;p&gt;The Scheduler API provides a first-class, priority-aware task queue built directly into the browser. Its primary interface is &lt;code&gt;scheduler.postTask()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;doSomeWork&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At its most basic level, this looks identical to &lt;code&gt;setTimeout(fn, 0)&lt;/code&gt;. The difference is what's happening underneath. The task is registered with a &lt;strong&gt;userspace scheduler&lt;/strong&gt; that understands priority levels, can abort tasks before they run, can have their priority changed after they're queued, and integrates correctly with the browser's own event loop priorities.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Browser support:&lt;/strong&gt; Chromium-based browsers have shipped the Scheduler API since Chrome 94. Firefox has it behind a flag. Safari does not support it yet. For production use today, you will need either feature detection with a graceful fallback (covered below) or the &lt;a href="https://github.com/nicolo-ribaudo/tc39-proposal-scheduler-polyfill" rel="noopener noreferrer"&gt;WICG scheduler polyfill&lt;/a&gt;. The API is stable and the cross-browser gap is narrowing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Priority Levels
&lt;/h2&gt;

&lt;p&gt;Every task submitted to &lt;code&gt;scheduler.postTask()&lt;/code&gt; has a priority. There are exactly three, and they map directly to the browser's own internal task prioritization:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Priority&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Roughly Equivalent To&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Highest&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'user-blocking'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Mouse/keyboard input handlers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'user-visible'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;setTimeout(fn, 0)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lowest&lt;/td&gt;
&lt;td&gt;&lt;code&gt;'background'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;requestIdleCallback&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// High priority — treat this like user input&lt;/span&gt;
&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;updateCriticalUI&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-blocking&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Default priority — non-urgent but visible work&lt;/span&gt;
&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;renderSecondaryContent&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-visible&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Low priority — this can wait until the browser is truly idle&lt;/span&gt;
&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;sendAnalyticsEvent&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser enforces this ordering. A &lt;code&gt;'background'&lt;/code&gt; task will not preempt a &lt;code&gt;'user-blocking'&lt;/code&gt; one. If a high-priority task arrives while a lower-priority one is still queued, the high-priority work goes first.&lt;/p&gt;

&lt;p&gt;That sounds like a table-stakes guarantee. But it's the first time the platform has given us an actual mechanism to express it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing the Right Priority
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;user-blocking&lt;/code&gt;&lt;/strong&gt; should be reserved for work whose absence is directly visible to the user as a broken interaction. Rendering the direct result of a click. Updating a focused form field. If the user has to wait for this and the wait is noticeable, use &lt;code&gt;user-blocking&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;user-visible&lt;/code&gt;&lt;/strong&gt; (the default) is for work that needs to happen soon, but can tolerate a single frame of delay. Data transformations that drive a chart update. Lazy populating a dropdown. Most of your "important but not critical" deferred work lives here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;background&lt;/code&gt;&lt;/strong&gt; is for work the user will never directly observe in the immediate moment. Telemetry, prefetching, warming caches, building search indexes, syncing non-visible state. If it's fine to run in idle time, it belongs here.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;scheduler.postTask()&lt;/code&gt; Returns a Promise
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;scheduler.postTask()&lt;/code&gt; returns a &lt;code&gt;Promise&lt;/code&gt; that resolves with whatever your callback returns. That changes the ergonomics a lot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;computeExpensiveValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;largeDataset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// The computed value, available when the task completes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means you can chain deferred work naturally, without deeply nested callbacks or manual coordination. You get the async/await model with the browser's scheduler underneath.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;buildReportData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Step 1: Parse — this is CPU heavy, keep it off the critical path&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;parseRawData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 2: Aggregate — still background, can run after parse&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;aggregated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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="nf"&gt;aggregateByDimension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;// Step 3: Render the result — now it's visible work&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;renderReport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aggregated&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-visible&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each step yields back to the browser between phases. User interactions that happen while the background processing is in flight still get priority. The report data will appear when the browser gets around to it, but it won't block a scroll or a click.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aborting Tasks with &lt;code&gt;TaskController&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Deferred work is sometimes invalidated before it runs. A user navigates away. A filter changes before the previous filter's result has been computed. A component unmounts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;postTask&lt;/code&gt; was designed for this. You pass a &lt;code&gt;signal&lt;/code&gt; derived from a &lt;code&gt;TaskController&lt;/code&gt;, and you call &lt;code&gt;.abort()&lt;/code&gt; when the work is no longer needed:&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;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TaskController&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;buildLargeIndex&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Later: the user's action has made this work irrelevant&lt;/span&gt;
&lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;.abort()&lt;/code&gt; is called, the promise returned by &lt;code&gt;postTask&lt;/code&gt; rejects with an &lt;code&gt;AbortError&lt;/code&gt;. You handle it the same way you would handle a cancelled &lt;code&gt;fetch&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;buildLargeIndex&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="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AbortError&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Task was cancelled. This is expected, not an error.&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This isn't just a nice-to-have. Without explicit cancellation you can end up with a stale-result race condition — an invalidated background task finishing &lt;em&gt;after&lt;/em&gt; a newer one and overwriting fresh data with stale results. It's the kind of bug that only appears under load and is miserable to track down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing Priority Dynamically
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;TaskController&lt;/code&gt; gives you another capability that other scheduling primitives simply don't have: you can change the priority of a queued task after it's been submitted.&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;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TaskController&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;preprocessSearchIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// User opens the search box — this work is now urgent&lt;/span&gt;
&lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setPriority&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-visible&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;Think about what this means. The task was sitting quietly in the background doing preprocessing. The user opens search — now that work is suddenly relevant to something imminent. You don't cancel it and resubmit. You promote it in place.&lt;/p&gt;

&lt;p&gt;The reverse works too. A task you thought mattered becomes irrelevant mid-flight. Demote it. Free up the headroom. The API was designed to support this kind of dynamic context, and it shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delaying Tasks
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;postTask&lt;/code&gt; also accepts a &lt;code&gt;delay&lt;/code&gt; option, which is a minimum delay in milliseconds before the task is eligible to 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;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;prefetchNextPageData&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Don't even consider this for 2 seconds&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is subtly different from &lt;code&gt;setTimeout&lt;/code&gt;. With &lt;code&gt;setTimeout&lt;/code&gt;, the callback fires after the delay, full stop. With &lt;code&gt;postTask&lt;/code&gt;, the &lt;code&gt;delay&lt;/code&gt; sets a floor on &lt;em&gt;when the task becomes eligible&lt;/em&gt;, but the actual execution still respects the priority queue. A &lt;code&gt;user-blocking&lt;/code&gt; task that arrives after the delay would still preempt this &lt;code&gt;background&lt;/code&gt; task.&lt;/p&gt;

&lt;p&gt;It's a minimum delay, not a scheduled time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Practical Pattern: The Task Queue with Chunking
&lt;/h2&gt;

&lt;p&gt;One of the most effective patterns with the Scheduler API is breaking a large synchronous loop into scheduled chunks. The naive version blocks the main thread for the duration of the loop:&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;// ❌ This processes 10,000 items synchronously.&lt;/span&gt;
&lt;span class="c1"&gt;// Nothing else can run until it's done.&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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;const&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;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;processItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;scheduler.yield()&lt;/code&gt; proposal (part of the same spec) is the cleanest answer here, but until it ships everywhere, you can approximate it with &lt;code&gt;postTask&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processInChunks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunks&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;chunks&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&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="nx"&gt;chunkSize&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;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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="k"&gt;for &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;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nf"&gt;processItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each chunk is a separate background task. Between chunks, the browser handles input, runs higher-priority work, and repaints. The total wall-clock time for all the processing is slightly longer than the synchronous version. But the &lt;strong&gt;interaction latency&lt;/strong&gt; — how long the user waits for a response after clicking — drops. That's the trade-off worth making, and with &lt;code&gt;postTask&lt;/code&gt; you can actually express it cleanly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composing with React
&lt;/h2&gt;

&lt;p&gt;If you're in a React codebase, this integrates cleanly with &lt;code&gt;useEffect&lt;/code&gt;. The pattern is nearly identical to how you'd cancel a &lt;code&gt;fetch&lt;/code&gt; inside an effect — a controller, a signal, and cleanup on return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useBackgroundProcessor&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&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;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;useEffect&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;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TaskController&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&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;cancelled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

        &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;run&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;chunkSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&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;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;

                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&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="nf"&gt;slice&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;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

                &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&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;chunk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="p"&gt;},&lt;/span&gt;
                        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;background&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AbortError&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="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nf"&gt;run&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; cleanup cancels in-flight tasks and prevents the processor from starting new chunks after unmount. If your component remounts before the previous run finishes, you get a fresh controller and a clean slate.&lt;/p&gt;

&lt;h2&gt;
  
  
  How This Relates to React's Concurrent Mode
&lt;/h2&gt;

&lt;p&gt;React 18 introduced concurrent rendering — the ability to interrupt and resume render work, deprioritize updates, and yield to more urgent interactions. React's internal scheduler is a userspace implementation of basically this same concept: priority lanes, preemption, interruptible work.&lt;/p&gt;

&lt;p&gt;So — are they redundant? No. The scope is different.&lt;/p&gt;

&lt;p&gt;React's scheduler only knows about React's own render work. The browser Scheduler API handles any JavaScript task you give it, React or not. Background data processing, analytics pipelines, search indexing — none of that passes through React's scheduler, but it can all go through &lt;code&gt;scheduler.postTask&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;They don't step on each other. React handles its own rendering priority internally. You reach for &lt;code&gt;scheduler.postTask&lt;/code&gt; for everything happening outside the render pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature Detection and Fallbacks
&lt;/h2&gt;

&lt;p&gt;For production use, you need a fallback strategy for browsers that haven't shipped the API yet. The simplest approach is feature-detecting at callsites:&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;scheduleTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scheduler&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;globalThis&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;postTask&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;scheduler&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;scheduler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Graceful degradation.&lt;/span&gt;
    &lt;span class="c1"&gt;// Background tasks become setTimeout; blocking tasks run synchronously.&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-visible&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user-blocking&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;callback&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&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;setTimeout&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&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;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not a perfect polyfill — &lt;code&gt;setTimeout&lt;/code&gt; doesn't respect the same priority ordering — but it's a reasonable approximation that degrades to the existing behavior rather than throwing. For a stricter cross-browser implementation, the &lt;a href="https://github.com/nicolo-ribaudo/tc39-proposal-scheduler-polyfill" rel="noopener noreferrer"&gt;WICG Polyfill&lt;/a&gt; is the reference implementation maintained alongside the spec.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Not to Reach For This
&lt;/h2&gt;

&lt;p&gt;A few places I've seen this misused — and at least one of them was in my own code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't reach for it when work genuinely needs to be synchronous.&lt;/strong&gt; If a click must produce an immediate, perceptible result, yielding to the event loop is the wrong move. You'll introduce a visible delay where there was none. Update the DOM synchronously, &lt;em&gt;then&lt;/em&gt; defer any secondary work that can wait.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's not a substitute for a Web Worker.&lt;/strong&gt; This one trips people up. Moving CPU-heavy work — image processing, parsing, cryptography — to a &lt;code&gt;background&lt;/code&gt; task defers &lt;em&gt;when&lt;/em&gt; it runs, but when it does run, it still blocks the main thread. A task that takes 200ms and is scheduled as &lt;code&gt;background&lt;/code&gt; will still drop frames when it fires. Off-thread is categorically different from low-priority.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't over-chunk.&lt;/strong&gt; &lt;code&gt;postTask&lt;/code&gt; has overhead. Splitting 10,000 items into 10,000 individual tasks costs more in coordination than it saves in responsiveness. 50–100 items per chunk, targeting the 4–8ms range per task, is a reasonable starting point. Measure your actual processing time — don't guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;The main thread isn't going anywhere. Web Workers are useful but they don't touch the DOM, and most UI work happens where the DOM lives. That's not changing.&lt;/p&gt;

&lt;p&gt;What we've always lacked is a way to be &lt;em&gt;precise&lt;/em&gt; about what matters when. &lt;code&gt;setTimeout(fn, 0)&lt;/code&gt; is a blunt instrument — it says "run this eventually." The Scheduler API gives you the ability to say "run this before that, but after those, and here's how to reach me if things change."&lt;/p&gt;

&lt;p&gt;That's not an incremental improvement. It's a different abstraction for expressing intent.&lt;/p&gt;

&lt;p&gt;The browser support situation means you'll need a fallback for now. But the API is stable, Chromium has shipped it for years, and the rest of the ecosystem is catching up. It's worth understanding before you need it — because when you do need it, you'll really need it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>performance</category>
      <category>architecture</category>
      <category>react</category>
    </item>
    <item>
      <title>What Actually Happens When You Type a URL in the Browser?</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Tue, 11 Nov 2025 20:25:07 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/what-actually-happens-when-you-type-a-url-in-the-browser-5b08</link>
      <guid>https://forem.com/byte-sized-news/what-actually-happens-when-you-type-a-url-in-the-browser-5b08</guid>
      <description>&lt;p&gt;Imagine you’re at your desk, maybe with a little mug of tea, and you open your browser. You type &lt;strong&gt;&lt;a href="http://www.google.com" rel="noopener noreferrer"&gt;www.google.com&lt;/a&gt;&lt;/strong&gt;, hit Enter, and in what feels like a heartbeat, you’re staring at the Google homepage.&lt;/p&gt;

&lt;p&gt;Simple, right?&lt;/p&gt;

&lt;p&gt;Here’s the thing: behind that one keystroke lies a &lt;em&gt;chain reaction&lt;/em&gt;, a series of machines, protocols, translations, negotiations, all secretly working together so you can see a web page. It’s less magic, more engineering, but still pretty magical when you think about it.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: The URL — Your Digital Address
&lt;/h3&gt;

&lt;p&gt;When you typed &lt;code&gt;https://www.google.com&lt;/code&gt;, you essentially said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Browser, take me to the house called &lt;em&gt;google.com&lt;/em&gt; using the secure road (HTTPS).”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Breaking it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Protocol&lt;/strong&gt;: &lt;code&gt;https://&lt;/code&gt; – tells the browser how to speak to the server (securely).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain name&lt;/strong&gt;: &lt;code&gt;www.google.com&lt;/code&gt; – tells it where to go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Path/query&lt;/strong&gt; (might be something like `/search?q=…” but not in our simple example) – tells it what exactly to fetch inside that domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you hit Enter, your browser thinks: “Okay, got the address. Now how do I get there?”&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: DNS – The Internet’s Phonebook
&lt;/h3&gt;

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

&lt;p&gt;Your browser doesn’t know “google.com” as a house, it knows numbers (IP addresses). So it uses the &lt;strong&gt;Domain Name System (DNS)&lt;/strong&gt; to translate the friendly name into an IP.&lt;br&gt;
Here’s a link diving into how DNS works: &lt;a href="https://www.cloudflare.com/learning/dns/what-is-dns/" rel="noopener noreferrer"&gt;What is DNS – Cloudflare&lt;/a&gt;&lt;br&gt;
And another good read: &lt;a href="https://www.freecodecamp.org/news/how-dns-works-the-internets-address-book/" rel="noopener noreferrer"&gt;How DNS works – freeCodeCamp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Roughly this happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser checks its cache to see if it already knows the IP.&lt;/li&gt;
&lt;li&gt;If not found, the OS checks its cache.&lt;/li&gt;
&lt;li&gt;If still no, the request goes to the ISP’s DNS resolver which starts querying the DNS hierarchy (root servers → TLD servers → authoritative name servers) to find the IP. (&lt;a href="https://www.geeksforgeeks.org/computer-networks/working-of-domain-name-system-dns-server/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GeeksforGeeks&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Once the IP is found, your browser has a destination.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Step 3: Establishing a Connection – TCP Handshake
&lt;/h3&gt;

&lt;p&gt;With the IP in hand, your browser knocks on the server’s door using TCP (Transmission Control Protocol). It’s a three-way handshake: browser says “hi,” server replies “hi,” browser says “let’s talk.” This establishes reliable communication.&lt;br&gt;
We often gloss over this, but the handshake ensures both sides are ready and synchronised.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4: Adding a Layer of Security – TLS Handshake
&lt;/h3&gt;

&lt;p&gt;Since we used &lt;code&gt;https://&lt;/code&gt;, there’s another handshake: the Transport Layer Security (TLS) handshake. This explains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The server presents a certificate to prove “I am who I say I am.”&lt;/li&gt;
&lt;li&gt;Browser and server agree on encryption keys so the data transfer is private and secure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once that’s done, your browser and the server can talk securely.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5: Making the Request – The HTTP Request
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99y57t6l6fxs9ovdv0l4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99y57t6l6fxs9ovdv0l4.png" alt="Image of the HTTP request" width="660" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we’re ready. Your browser says something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Server at the IP I found, please send me your homepage.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s an HTTP request (Hypertext Transfer Protocol). If you’re curious, check this link: &lt;a href="https://medium.com/%40S3Curiosity/http-requests-and-responses-a-beginners-guide-fc215b9ea741" rel="noopener noreferrer"&gt;HTTP Requests and Responses: A Beginner’s Guide&lt;/a&gt;&lt;br&gt;
And a more canonical source: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Messages" rel="noopener noreferrer"&gt;MDN – HTTP Messages&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The request includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Method (GET, POST, etc)&lt;/li&gt;
&lt;li&gt;Path (which page or resource)&lt;/li&gt;
&lt;li&gt;Headers (browser type, language, cookies)&lt;/li&gt;
&lt;li&gt;Possibly a body (for POST requests)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 6: Server Response – The HTML Arrives
&lt;/h3&gt;

&lt;p&gt;The server processes your request and sends back an HTTP response. It includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;status code&lt;/strong&gt; (200 = OK, 404 = Not Found, etc.)&lt;/li&gt;
&lt;li&gt;Response headers (type of content, caching rules, etc)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;body&lt;/strong&gt; (which, for our case, is the HTML of the Google homepage)
You can explore &lt;a href="https://www.w3schools.com/whatis/whatis_http.asp" rel="noopener noreferrer"&gt;What is HTTP? – W3Schools&lt;/a&gt; for details.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 7: Rendering – Painting the Page
&lt;/h3&gt;

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

&lt;p&gt;Your browser now has a blueprint (the HTML, CSS, JS, images…) and it starts building:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parse the HTML to build the DOM (Document Object Model).&lt;/li&gt;
&lt;li&gt;Parse CSS to figure out layout and styles.&lt;/li&gt;
&lt;li&gt;Run JS to add interactivity.&lt;/li&gt;
&lt;li&gt;Download images/fonts/videos as needed.&lt;/li&gt;
&lt;li&gt;Render all of this visually so you see the page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is where the magic of “appears instantly” happens.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 8: Optimization, Caching &amp;amp; the Background Work
&lt;/h3&gt;

&lt;p&gt;Even after you see the page, work continues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The browser caches resources (so next time it'll load faster).&lt;/li&gt;
&lt;li&gt;DNS entries may be kept in cache too.&lt;/li&gt;
&lt;li&gt;The server might have chosen a data-centre close to you (via load-balancing/CDNs) so the journey was short.
These optimisations are why websites feel snappy.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 9: Click, New URL, Repeat
&lt;/h3&gt;

&lt;p&gt;When you click a link or type another URL, the process essentially repeats — but thanks to caching and persistent connections, parts of it are faster now.&lt;/p&gt;




&lt;h3&gt;
  
  
  Final Thought
&lt;/h3&gt;

&lt;p&gt;Typing a URL is deceptively simple. Under the hood it triggers a global ballet of protocols, machines, translation services and security layers, so you can get your webpage, often within milliseconds. Next time a page loads with no hiccup, take a moment to appreciate how many invisible actors just did their job.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>learning</category>
    </item>
    <item>
      <title>Your SSR Isn’t Fast — Hydration Is Dragging It Down</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sun, 09 Nov 2025 20:32:25 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/your-ssr-isnt-fast-hydration-is-dragging-it-down-4437</link>
      <guid>https://forem.com/byte-sized-news/your-ssr-isnt-fast-hydration-is-dragging-it-down-4437</guid>
      <description>&lt;p&gt;Imagine you’re on a slow mobile network, scrolling through the news on your phone. The page loads instantly — text, images, layout all appear right away. Visually, it seems ready. You tap “Read more.”&lt;/p&gt;

&lt;p&gt;Nothing happens.&lt;/p&gt;

&lt;p&gt;A second tap. Still nothing. Then suddenly the page springs to life and behaves normally.&lt;/p&gt;

&lt;p&gt;What you just experienced is the hidden cost of hydration — the process modern frameworks use to “wake up” server-rendered HTML in the browser. It’s clever, it has served us well, but it’s far from lightweight.&lt;/p&gt;

&lt;p&gt;This article explores why hydration is computationally expensive and how partial hydration offers a more efficient path forward.&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding Hydration
&lt;/h2&gt;

&lt;p&gt;Server-side rendering (SSR) allows users to see the interface immediately by delivering HTML first. However, HTML on its own is static — it cannot handle clicks, form inputs, or interactive components.&lt;/p&gt;

&lt;p&gt;Hydration is the browser’s process of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Downloading the JavaScript bundle&lt;/li&gt;
&lt;li&gt;Parsing and executing it&lt;/li&gt;
&lt;li&gt;Rebuilding the UI tree in memory&lt;/li&gt;
&lt;li&gt;Matching it to the existing DOM&lt;/li&gt;
&lt;li&gt;Attaching event listeners and restoring state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In simple terms, the browser receives a fully-rendered page, but then re-renders the application internally to attach behavior. The UI looks complete, but it’s not truly functional until hydration finishes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Hydration Is Expensive
&lt;/h2&gt;

&lt;p&gt;Hydration introduces performance overhead because the browser ends up doing more work than necessary. It renders the UI twice — first on the server for visual output, then again on the client to attach interactivity — and that cost becomes noticeable as applications scale.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Large JavaScript Bundles
&lt;/h3&gt;

&lt;p&gt;Even though the HTML arrives fully rendered, hydration still requires sending down the entire JavaScript bundle responsible for building the UI.&lt;/p&gt;

&lt;p&gt;This includes framework code, component logic, routing, state management, and event handlers — essentially the same resources a client-side SPA would load.&lt;/p&gt;

&lt;p&gt;So instead of “SSR saves work,” you're shipping HTML &lt;em&gt;and&lt;/em&gt; a full client runtime.&lt;/p&gt;

&lt;p&gt;More JavaScript means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher network transfer impact (especially on slow or unstable networks)&lt;/li&gt;
&lt;li&gt;Longer download and decompression time&lt;/li&gt;
&lt;li&gt;More memory usage right after page load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SSR gets pixels on the screen faster, yes — but hydration delays when those pixels become useful.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Heavy CPU Work
&lt;/h3&gt;

&lt;p&gt;Once downloaded, the browser must parse, compile, and execute the JavaScript — and that’s where the CPU load hits.&lt;/p&gt;

&lt;p&gt;Parsing and executing JavaScript isn't free. It blocks the main thread, the same thread responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Animations&lt;/li&gt;
&lt;li&gt;Scrolling&lt;/li&gt;
&lt;li&gt;Input responsiveness&lt;/li&gt;
&lt;li&gt;Layout and paint operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On modern laptops, this cost may feel small. On mid-range Android phones or older devices, it's painful. A page that &lt;em&gt;looks&lt;/em&gt; ready turns sluggish simply because JavaScript hasn’t finished bootstrapping yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Duplicate Rendering Work
&lt;/h3&gt;

&lt;p&gt;SSR gives the browser a complete DOM tree. But hydration doesn’t reuse that DOM directly.&lt;br&gt;
The framework rebuilds its virtual component tree in JavaScript, reconciles it, and then attaches behaviors to the existing DOM nodes.&lt;/p&gt;

&lt;p&gt;It’s like assembling the same puzzle twice — once on the server and once inside the user's device — just to verify the pieces fit.&lt;/p&gt;

&lt;p&gt;That duplicated effort wastes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU cycles&lt;/li&gt;
&lt;li&gt;Memory&lt;/li&gt;
&lt;li&gt;Startup time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The UI is already there — the browser just has to re-understand it.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Hydrating Everything, Even Static Content
&lt;/h3&gt;

&lt;p&gt;Traditional hydration approaches treat every part of the page as potentially interactive. The framework walks through the entire DOM — even sections that will never change or respond to input.&lt;/p&gt;

&lt;p&gt;Static blocks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Article text&lt;/li&gt;
&lt;li&gt;Footer content&lt;/li&gt;
&lt;li&gt;Product descriptions&lt;/li&gt;
&lt;li&gt;Banner images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;all get swept into the hydration process simply because they live inside a component tree.&lt;/p&gt;

&lt;p&gt;This is equivalent to activating every circuit in a building even if most rooms won’t be used.&lt;/p&gt;

&lt;p&gt;Most pages don’t need to hydrate 100% of their UI, yet traditional hydration does exactly that.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Delayed Interactivity and Perceived Lag
&lt;/h3&gt;

&lt;p&gt;Until hydration completes, the interface is visually present but functionally incomplete. Buttons exist, but they may not respond. Input fields appear ready, but keystrokes don’t register immediately.&lt;/p&gt;

&lt;p&gt;This gap between &lt;em&gt;first paint&lt;/em&gt; and &lt;em&gt;usable interface&lt;/em&gt; damages user trust.&lt;/p&gt;

&lt;p&gt;Developers see it as a “hydration window.”&lt;br&gt;
Users see it as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“The site is slow”&lt;/li&gt;
&lt;li&gt;“This button doesn’t work”&lt;/li&gt;
&lt;li&gt;“Is my phone freezing?”&lt;/li&gt;
&lt;li&gt;“Why hasn’t the menu opened yet?”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It affects core metrics like Time to Interactive (TTI) and Interaction to Next Paint (INP), and ultimately shapes how users perceive your product.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Bottom Line
&lt;/h3&gt;

&lt;p&gt;Hydration solves an important problem — fast HTML rendering with rich interactivity — but it does so by making the browser redo work it already received from the server.&lt;/p&gt;

&lt;p&gt;The result: pages that arrive fast, but &lt;em&gt;become usable slowly&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Partial hydration and modern approaches aim to cut out this redundancy, enabling only the parts that truly need JavaScript to hydrate — and only when necessary.&lt;/p&gt;




&lt;h2&gt;
  
  
  Partial Hydration: A More Targeted Approach
&lt;/h2&gt;

&lt;p&gt;Partial hydration addresses this problem by only hydrating components that truly need interactivity.&lt;/p&gt;

&lt;p&gt;Instead of rehydrating the entire page, the browser focuses on smaller, isolated “islands” of interactive functionality — like navigation menus, search bars, or carousels — while leaving static content untouched.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Less JavaScript sent to the browser&lt;/li&gt;
&lt;li&gt;Reduced CPU usage and faster processing&lt;/li&gt;
&lt;li&gt;Faster time-to-interactive (TTI)&lt;/li&gt;
&lt;li&gt;Better performance on low-end devices&lt;/li&gt;
&lt;li&gt;A more efficient rendering pipeline overall&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, the browser hydrates only where necessary, rather than everywhere by default.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Adoption
&lt;/h2&gt;

&lt;p&gt;Many modern frameworks are embracing this model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Astro&lt;/strong&gt;: Islands architecture, zero-JS by default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Qwik&lt;/strong&gt;: Resumability — skips hydration entirely&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SvelteKit&lt;/strong&gt;: Compiles away much runtime overhead&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Next.js (App Router)&lt;/strong&gt;: Server components reduce hydration scope&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solid&lt;/strong&gt;: Extremely fine-grained, selective hydration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trend is clear: ship less JavaScript, hydrate less, and push more execution back to the server.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Shift in Frontend Thinking
&lt;/h2&gt;

&lt;p&gt;For years, the industry moved toward increasingly complex client-side JavaScript. We treated the browser as the primary execution environment.&lt;/p&gt;

&lt;p&gt;That tide is turning.&lt;/p&gt;

&lt;p&gt;The new direction emphasizes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimal client-side JavaScript&lt;/li&gt;
&lt;li&gt;Server-driven interfaces&lt;/li&gt;
&lt;li&gt;Progressive enhancement&lt;/li&gt;
&lt;li&gt;Distributed and selective interactivity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn’t to remove interactivity — it’s to be strategic about where it’s needed.&lt;/p&gt;




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

&lt;p&gt;Hydration was an essential stepping stone in modern web architecture. It allowed us to combine server-rendered speed with client-side richness. But as applications grow and devices vary widely in capability, we can no longer afford to hydrate everything by default.&lt;/p&gt;

&lt;p&gt;Partial hydration — and the evolution beyond it — reflects a smarter, more efficient approach:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Deliver the UI quickly.&lt;br&gt;
Hydrate only what the user interacts with.&lt;br&gt;
Avoid unnecessary work in the browser.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s a shift toward performance, practicality, and user-first engineering — a cleaner and more sustainable direction for the future of frontend development.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Real-Time Chart Updates: Using WebSockets To Build Live Dashboards</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sat, 08 Nov 2025 18:34:40 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/real-time-chart-updates-using-websockets-to-build-live-dashboards-3hml</link>
      <guid>https://forem.com/byte-sized-news/real-time-chart-updates-using-websockets-to-build-live-dashboards-3hml</guid>
      <description>&lt;p&gt;Imagine you're glued to your laptop, watching the final seconds of a live auction. Bids shoot up every second. You're sweating, hovering over the button, waiting for the latest price. But instead of seeing updates instantly, you keep smashing refresh like it's 2007. By the time the price changes, someone else has already won.&lt;/p&gt;

&lt;p&gt;That used to be the reality of real-time data on the web.&lt;/p&gt;

&lt;p&gt;Before WebSockets, the browser had one way to stay updated: keep asking the server every few seconds. Polling. It worked, but barely. It was wasteful, slow, and honestly, a little embarrassing for the modern web.&lt;/p&gt;

&lt;p&gt;Then WebSockets showed up in 2011 and flipped the script. A persistent connection. Two-way communication. Real-time data without spammy refresh loops. Suddenly the web could behave more like a trading terminal and less like a fax machine.&lt;/p&gt;

&lt;p&gt;If you're building dashboards, analytics tools, gaming UIs, IoT displays, or anything that needs to update the moment data changes, WebSockets become your best friend.&lt;/p&gt;

&lt;p&gt;Let’s walk through how this works and how you can get started.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Real-Time Matters
&lt;/h2&gt;

&lt;p&gt;A dashboard that updates once every 10 seconds isn’t a dashboard — it’s a slideshow.&lt;/p&gt;

&lt;p&gt;The modern expectation is instant feedback. Crypto charts moving by the millisecond. Social analytics ticking up in real time. Live order books, multiplayer game states, collaborative editors… the web feels alive now.&lt;/p&gt;

&lt;p&gt;To keep up, we need tech that streams information continuously, not drip-feeds it through constant HTTP requests.&lt;/p&gt;

&lt;p&gt;That’s where WebSockets shine. You open one connection and keep it open. No more “Hey server, any updates? No? Okay see you in 3 seconds.”&lt;/p&gt;

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




&lt;h2&gt;
  
  
  How WebSockets Actually Work
&lt;/h2&gt;

&lt;p&gt;The simplest way to explain it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser knocks on server’s door saying: “Let’s stay connected.”&lt;/li&gt;
&lt;li&gt;Server agrees.&lt;/li&gt;
&lt;li&gt;Now both can talk whenever they want — no repeated knocking.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s basically a WhatsApp call between client and server instead of sending texts every few seconds asking “You there?”&lt;/p&gt;




&lt;h2&gt;
  
  
  A Tiny Example
&lt;/h2&gt;

&lt;p&gt;Let's keep this simple and build the smallest real-time setup we can — no frameworks, no fancy tooling. Just a server sending numbers and a browser receiving them. Once you see the basic flow, scaling it up becomes way less intimidating.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backend (Node.js)
&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;WebSocket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ws&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;WebSocket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connection&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Client connected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;setInterval&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;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&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;price&lt;/span&gt; &lt;span class="p"&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Frontend
&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;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ws://localhost:8080&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;updateChart&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;price&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;Cool, so now we've got a data stream. Next question — what do we do with it? Most of the time, we’re not printing raw numbers to the console… we’re visualizing them.&lt;/p&gt;




&lt;h2&gt;
  
  
  Updating Charts in Real-Time
&lt;/h2&gt;

&lt;p&gt;Now comes the fun part — charts.&lt;/p&gt;

&lt;p&gt;Libraries like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chart.js&lt;/li&gt;
&lt;li&gt;Highcharts&lt;/li&gt;
&lt;li&gt;Plotly&lt;/li&gt;
&lt;li&gt;Recharts (if you're working in React)&lt;/li&gt;
&lt;li&gt;Apache ECharts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All support dynamic updates.&lt;/p&gt;

&lt;p&gt;Example using Chart.js:&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;updateChart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;myChart&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;labels&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="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
  &lt;span class="nx"&gt;myChart&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;datasets&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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myChart&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;labels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;myChart&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;labels&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;myChart&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;datasets&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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;myChart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;none&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;A couple of pro tips you’ll thank yourself for later:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trim old data — browsers don't love 10,000 live points sitting around.&lt;/li&gt;
&lt;li&gt;Skip animations for real-time speed.&lt;/li&gt;
&lt;li&gt;Sync with &lt;code&gt;requestAnimationFrame&lt;/code&gt; if updates are rapid.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  But What Happens When The Connection Drops?
&lt;/h2&gt;

&lt;p&gt;Because it &lt;strong&gt;will&lt;/strong&gt; drop. Networks aren't perfect, servers restart, people switch Wi-Fi.&lt;/p&gt;

&lt;p&gt;Reconnect logic saves you here:&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;connect&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;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ws://localhost:8080&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Disconnected. Reconnecting...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Silent recovery = happy users.&lt;/p&gt;




&lt;h2&gt;
  
  
  Security Matters Too
&lt;/h2&gt;

&lt;p&gt;A persistent connection means persistent risks if you're careless. Keep things safe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;wss://&lt;/code&gt; instead of &lt;code&gt;ws://&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Validate tokens before opening a socket&lt;/li&gt;
&lt;li&gt;Sanitize incoming messages (browser can receive data too!)&lt;/li&gt;
&lt;li&gt;Disconnect inactive or abusive clients&lt;/li&gt;
&lt;li&gt;Never trust client input — ever&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;WebSockets give power. Power attracts trouble.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optimizing Data Flow
&lt;/h2&gt;

&lt;p&gt;Real-time doesn’t mean “blast the browser 1000 times a second”. Be thoughtful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Send only changes, not entire data dumps&lt;/li&gt;
&lt;li&gt;Consider binary formats like Protocol Buffers, MessagePack, FlatBuffers&lt;/li&gt;
&lt;li&gt;Compress where it makes sense&lt;/li&gt;
&lt;li&gt;Batch updates if single-tick precision isn’t needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Real-time is more about perception than raw throughput.&lt;/p&gt;

&lt;p&gt;If a user can't tell the difference between 50 updates/second and 5 updates/second, choose 5.&lt;/p&gt;

&lt;p&gt;Less noise, more clarity.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;WebSockets took the web from “refresh to see updates” to “updates arrive before you blink”. With a small learning curve and a massive payoff, they're one of those tools every modern developer should have in their kit.&lt;/p&gt;

&lt;p&gt;The moment you see your first chart move in real time without a refresh, it's hard to go back.&lt;/p&gt;

&lt;p&gt;Build something live. Stream something. Turn data into motion. It's a little addictive — in a good way.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Creating Arrays of Arrays (Nested Arrays) in JavaScript: Common Pitfalls and Best Practices</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Fri, 01 Aug 2025 20:45:27 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/creating-arrays-of-arrays-nested-arrays-in-javascript-common-pitfalls-and-best-practices-20de</link>
      <guid>https://forem.com/byte-sized-news/creating-arrays-of-arrays-nested-arrays-in-javascript-common-pitfalls-and-best-practices-20de</guid>
      <description>&lt;p&gt;Working with arrays of arrays—often referred to as "nested arrays" or "2D arrays"—is a common requirement in JavaScript when dealing with matrices, grids, or tabular data. However, the way we initialize these structures can introduce subtle bugs if we’re not careful! In this post, we’ll walk through the right and wrong ways to create arrays of arrays in JavaScript, explain why certain pitfalls occur, and show you best practices for robust code.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Basic Case: Hardcoding Nested Arrays
&lt;/h2&gt;

&lt;p&gt;Suppose we want to create a simple nested array with two empty arrays:&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;arr&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works perfectly if you know the number of inner arrays in advance. Each sub-array is independent, and you can safely push data into one without affecting the other.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Dynamic Case: Creating a Random-Length Array of Arrays
&lt;/h2&gt;

&lt;p&gt;What if you don’t know ahead of time how many inner arrays you need? For example, suppose you want to create an array of &lt;code&gt;len&lt;/code&gt; empty arrays, where &lt;code&gt;len&lt;/code&gt; is determined at runtime.&lt;/p&gt;

&lt;p&gt;A common first attempt might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;len&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;// Suppose len is 5&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this seems reasonable: &lt;code&gt;new Array(len)&lt;/code&gt; creates an array with &lt;code&gt;len&lt;/code&gt; empty slots, and &lt;code&gt;.fill([])&lt;/code&gt; fills each slot with an empty array.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Hidden Trap: Shared References
&lt;/h2&gt;

&lt;p&gt;However, this approach can cause unexpected behavior! The problem is that &lt;code&gt;.fill([])&lt;/code&gt; fills every slot with &lt;strong&gt;the same array instance&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&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="nf"&gt;fill&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="mi"&gt;0&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [[1], [1], [1]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uh-oh! When you modify &lt;code&gt;arr[0]&lt;/code&gt;, you end up modifying every sub-array, because all elements of &lt;code&gt;arr&lt;/code&gt; point to the exact same array in memory.&lt;/p&gt;

&lt;p&gt;This happens because in JavaScript (and many other languages), arrays and objects are &lt;strong&gt;reference types&lt;/strong&gt;. The value &lt;code&gt;[]&lt;/code&gt; is a reference to a specific array object, and &lt;code&gt;fill([])&lt;/code&gt; copies that reference into every slot.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Solution: Create a New Array for Each Slot
&lt;/h2&gt;

&lt;p&gt;To avoid this, you should create a new empty array for each position. You can do this using &lt;code&gt;.map()&lt;/code&gt; or &lt;code&gt;.from()&lt;/code&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;Array.from()&lt;/code&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;len&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="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="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="nx"&gt;len&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the second argument to &lt;code&gt;Array.from&lt;/code&gt; is a mapping function that returns a new empty array for each slot, so each sub-array is unique.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;.map()&lt;/code&gt; (after &lt;code&gt;.fill()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Alternatively, you can chain &lt;code&gt;.map()&lt;/code&gt; after &lt;code&gt;.fill()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;len&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="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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;new Array(len).fill()&lt;/code&gt; creates an array of &lt;code&gt;len&lt;/code&gt; undefineds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.map(() =&amp;gt; [])&lt;/code&gt; replaces each &lt;code&gt;undefined&lt;/code&gt; with a new array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Demonstration
&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;arr&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;3&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;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="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="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;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [[1], [], []]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, each inner array is independent!&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Are sub-arrays independent?&lt;/th&gt;
&lt;th&gt;Example Output&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;
&lt;code&gt;[[1], []]&lt;/code&gt; (after &lt;code&gt;arr[0].push(1)&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new Array(len).fill([])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No (shared reference)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[[1], [1], [1]]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Array.from({length: len}, () =&amp;gt; [])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[[1], [], []]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new Array(len).fill().map(() =&amp;gt; [])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[[1], [], []]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Don’t use &lt;code&gt;.fill([])&lt;/code&gt;&lt;/strong&gt; to create nested arrays—you’ll end up with shared references!&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Array.from({ length: n }, () =&amp;gt; [])&lt;/code&gt; or &lt;code&gt;.map(() =&amp;gt; [])&lt;/code&gt; to ensure each sub-array is unique.&lt;/li&gt;
&lt;li&gt;Remember: objects and arrays in JavaScript are reference types. Assignment or &lt;code&gt;.fill()&lt;/code&gt; with an object/array copies the reference, not the value.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Example: Initializing a 2D Matrix
&lt;/h2&gt;

&lt;p&gt;Suppose you want a 5x5 grid of zeros:&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;size&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matrix&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="nx"&gt;size&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="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="nx"&gt;size&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="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;matrix&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each row and each cell is independent—perfect for grid-based algorithms, games, or spreadsheets!&lt;/p&gt;




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

&lt;p&gt;While it’s easy to create arrays of arrays in JavaScript, it’s just as easy to fall into the shared reference trap with &lt;code&gt;.fill([])&lt;/code&gt;. By understanding how references work and initializing each sub-array independently, you’ll write safer, more predictable code.&lt;/p&gt;

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

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Tiny Symbols That Can Break Your App: ^ vs ~ in package.json</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sun, 15 Jun 2025 13:44:52 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/the-tiny-symbols-that-can-break-your-app-vs-in-packagejson-cmp</link>
      <guid>https://forem.com/byte-sized-news/the-tiny-symbols-that-can-break-your-app-vs-in-packagejson-cmp</guid>
      <description>&lt;p&gt;If you've ever opened a &lt;code&gt;package.json&lt;/code&gt; file and wondered what those mysterious &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; symbols before version numbers mean, you're not alone. They might look innocent, but these tiny symbols can cause unexpected bugs, broken builds, and production headaches.&lt;/p&gt;

&lt;p&gt;Let’s understand the difference between &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt;, and uncover how they can become hidden traps in your JavaScript/TypeScript projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 The Basics: What Do &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; Mean?
&lt;/h2&gt;

&lt;p&gt;In a &lt;code&gt;package.json&lt;/code&gt;, these symbols are used for &lt;strong&gt;semantic versioning (semver)&lt;/strong&gt;, a way of defining compatible versions for dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ &lt;code&gt;^&lt;/code&gt; (Caret)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;"react": "^18.2.0"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Meaning&lt;/strong&gt;: Accept &lt;strong&gt;minor and patch updates&lt;/strong&gt;, but &lt;strong&gt;not major&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Range&lt;/strong&gt;: &lt;code&gt;&amp;gt;=18.2.0 &amp;lt;19.0.0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It updates your package to the latest version &lt;strong&gt;within the same major version&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ &lt;code&gt;~&lt;/code&gt; (Tilde)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;"react": "~18.2.0"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Meaning&lt;/strong&gt;: Accept &lt;strong&gt;patch updates only&lt;/strong&gt;, not minor or major.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Range&lt;/strong&gt;: &lt;code&gt;&amp;gt;=18.2.0 &amp;lt;18.3.0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚠️ Why It Matters: The Hidden Dev Trap
&lt;/h2&gt;

&lt;p&gt;Let’s say you’re working in a team, and your teammate installs a package with &lt;code&gt;^&lt;/code&gt;. A few weeks later, a new minor version is released; maybe with a breaking change (yes, that happens even when it shouldn’t). Now, your teammate’s environment works differently than yours, and your build breaks.&lt;/p&gt;

&lt;p&gt;This is what we call a &lt;strong&gt;"dependency drift."&lt;/strong&gt;&lt;br&gt;
You didn’t change the code, but it broke anyway. That’s the hidden trap.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 When to Use What
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&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;Rapid development / libraries&lt;/td&gt;
&lt;td&gt;Gets bug fixes &amp;amp; features&lt;/td&gt;
&lt;td&gt;Might introduce breaking bugs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Production apps&lt;/td&gt;
&lt;td&gt;Safer, more predictable&lt;/td&gt;
&lt;td&gt;Slower adoption of new features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;None (exact version)&lt;/td&gt;
&lt;td&gt;Mission-critical builds&lt;/td&gt;
&lt;td&gt;Fully stable&lt;/td&gt;
&lt;td&gt;No updates unless changed manually&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧰 Pro Tips
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use a lockfile (&lt;code&gt;package-lock.json&lt;/code&gt;, &lt;code&gt;yarn.lock&lt;/code&gt;, etc.)&lt;/strong&gt; – Always commit it to avoid version inconsistencies across environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;npm ci&lt;/code&gt; instead of &lt;code&gt;npm install&lt;/code&gt; in CI&lt;/strong&gt; – It strictly follows the lockfile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run regular audits&lt;/strong&gt; – Tools like &lt;code&gt;npm audit&lt;/code&gt; or &lt;code&gt;yarn audit&lt;/code&gt; help spot issues early.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consider &lt;code&gt;~&lt;/code&gt; for critical packages&lt;/strong&gt; like &lt;code&gt;react&lt;/code&gt;, &lt;code&gt;express&lt;/code&gt;, &lt;code&gt;nestjs&lt;/code&gt;, etc., where stability is more important than frequent updates.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🧪 A Real-World Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;package.json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"axios"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^1.4.0"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A week later, &lt;code&gt;1.5.0&lt;/code&gt; is released, and it slightly changes request behavior. Your staging build starts failing. If you'd used &lt;code&gt;~1.4.0&lt;/code&gt;, you’d have avoided this until explicitly updating.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧵 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Those tiny &lt;code&gt;^&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; symbols can make or break your app, literally. Don’t just copy-paste dependencies blindly. Understand them. Choose wisely based on your project type and stability needs.&lt;/p&gt;

&lt;p&gt;If you’ve ever been bitten by a surprise update, share your story. Let's make dependency management less of a minefield for everyone.&lt;/p&gt;




&lt;h2&gt;
  
  
  🙌 Found this helpful?
&lt;/h2&gt;

&lt;p&gt;If this saved you from future bugs, consider giving it a share or following me for more web dev tips.&lt;br&gt;
Have questions? Drop them in the comments, I’d love to hear your thoughts!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>npm</category>
    </item>
    <item>
      <title>ESLint is Dead, Long Live Biome?</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sun, 25 May 2025 08:14:05 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/eslint-is-dead-long-live-biome-31km</link>
      <guid>https://forem.com/byte-sized-news/eslint-is-dead-long-live-biome-31km</guid>
      <description>&lt;p&gt;In the world of JavaScript and TypeScript development, ESLint has long been the undisputed champion of linting. For over a decade, it has helped developers catch bugs, enforce style consistency, and ensure code quality across teams and open-source projects. But in 2025, a new contender is shaking the foundations of frontend tooling: &lt;strong&gt;Biome&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, is ESLint really dead? And what makes Biome worthy of replacing it?&lt;/p&gt;

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




&lt;h2&gt;
  
  
  What is Biome?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Biome&lt;/strong&gt; is an all-in-one toolkit for formatting, linting, and more. Developed by the same minds behind Rome (a now-discontinued full-stack JavaScript toolchain), Biome is laser-focused on performance, speed, and simplicity. It's written in Rust, making it blazing fast compared to its JavaScript-based counterparts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of Biome:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Built-in Formatter&lt;/strong&gt; (like Prettier)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Built-in Linter&lt;/strong&gt; (like ESLint)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero Config Setup&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rust-powered speed&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Typed lint rules with native TypeScript support&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Single binary, zero dependencies&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Are Devs Moving Away from ESLint?
&lt;/h2&gt;

&lt;p&gt;While ESLint is powerful and deeply entrenched in modern JS tooling, it's also become &lt;strong&gt;complex&lt;/strong&gt; and &lt;strong&gt;fragile&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Plugin Hell&lt;/strong&gt;: ESLint setups often depend on a forest of plugins and shared configs. Conflicts are common, especially with newer frameworks or language features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Written in JavaScript, ESLint can feel sluggish on large codebases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Toolchain Overload&lt;/strong&gt;: Many projects use ESLint for linting, Prettier for formatting, and TypeScript for type-checking — leading to redundant rules, duplicated effort, and slow CI pipelines.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  How Biome Solves These Problems
&lt;/h2&gt;

&lt;p&gt;Biome’s core philosophy is to &lt;strong&gt;reduce complexity&lt;/strong&gt; and &lt;strong&gt;boost performance&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No more plugin juggling — Biome ships with sensible defaults.&lt;/li&gt;
&lt;li&gt;The formatter and linter share a unified AST, avoiding conflicts.&lt;/li&gt;
&lt;li&gt;It processes both JS and TS natively, without needing separate configs.&lt;/li&gt;
&lt;li&gt;Being written in Rust, it's lightning-fast, even on large monorepos.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  In-Depth Cool Features of Biome:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Autofix on Save by Default&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Biome comes with powerful autofix capabilities that trigger automatically. No need to configure extra scripts — it just works.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Integrated Project Linting&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Biome is aware of your project context — meaning it can lint based on workspace rules, project structure, and TS config with minimal setup.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;High Parallelization&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Thanks to Rust’s concurrency model, Biome can lint and format files in parallel with blazing speed, outperforming JS-based tools even on multicore systems.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;JSON &amp;amp; TOML Support&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Beyond JS and TS, Biome also supports linting and formatting for JSON and TOML files, making it a true monorepo-friendly tool.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;Built-in CI Reporter&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Biome offers built-in CI-friendly output formats and summary flags to cleanly integrate with your pipeline logs without third-party tooling.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. &lt;strong&gt;No Need for Prettier&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Biome’s built-in formatter provides deterministic formatting without needing to pair it with Prettier — eliminating a major point of friction.&lt;/p&gt;

&lt;h4&gt;
  
  
  7. &lt;strong&gt;Actionable, Fixable Suggestions&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Biome doesn't just show you problems — it fixes them safely. Take this real-world example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;complexity/useFlatMap.js:2:1 lint/complexity/useFlatMap  FIXABLE

  ✖ The call chain .map().flat() can be replaced with a single .flatMap() call.

    1 │ const array = ["split", "the text", "into words"];
  &amp;gt; 2 │ array.map(sentence =&amp;gt; sentence.split(' ')).flat();
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    3 │

  ℹ Safe fix: Replace the chain with .flatMap().

    1  │ const array = ["split", "the text", "into words"];
    2  │ - array.map(sentence =&amp;gt; sentence.split(' ')).flat();
       │ + array.flatMap(sentence =&amp;gt; sentence.split(' '));
    3  │
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This level of feedback, combined with inline fix previews, makes Biome feel less like a linter and more like a coding assistant.&lt;/p&gt;




&lt;h2&gt;
  
  
  Biome vs ESLint + Prettier
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;ESLint + Prettier&lt;/th&gt;
&lt;th&gt;Biome&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Setup Time&lt;/td&gt;
&lt;td&gt;Moderate to High&lt;/td&gt;
&lt;td&gt;Very Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Config Complexity&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;High (Rust)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Plugin Dependency&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;None / Built-in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Formatting Support&lt;/td&gt;
&lt;td&gt;Separate tool (Prettier)&lt;/td&gt;
&lt;td&gt;Built-in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TS Integration&lt;/td&gt;
&lt;td&gt;Indirect (via parser)&lt;/td&gt;
&lt;td&gt;Native&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON/TOML Support&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;Built-in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fix Suggestions&lt;/td&gt;
&lt;td&gt;Varies&lt;/td&gt;
&lt;td&gt;Safe, Built-in, Inline&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Is It Ready for Production?
&lt;/h2&gt;

&lt;p&gt;As of mid-2025, &lt;strong&gt;Biome is stable&lt;/strong&gt; and production-ready for many use cases. Major projects are adopting it — especially those that value fast CI pipelines and simple developer onboarding. However, there are still some caveats:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ESLint still offers &lt;strong&gt;more mature plugin ecosystems&lt;/strong&gt;, especially for niche frameworks.&lt;/li&gt;
&lt;li&gt;If your team has heavy custom rule requirements, Biome might still be catching up.&lt;/li&gt;
&lt;li&gt;Migrating an existing ESLint setup may take some tweaking.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Should You Switch?
&lt;/h2&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Biome If...&lt;/th&gt;
&lt;th&gt;Stick with ESLint If...&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;You're starting a new project&lt;/td&gt;
&lt;td&gt;You rely on advanced, custom lint rules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You want a fast, single-tool setup&lt;/td&gt;
&lt;td&gt;You need specific ESLint plugins&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Your team prefers convention over config&lt;/td&gt;
&lt;td&gt;You have deeply integrated ESLint workflows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You’re working with JSON/TOML formats&lt;/td&gt;
&lt;td&gt;You rely heavily on ESLint plugin ecosystem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You want smart autofixes and reports&lt;/td&gt;
&lt;td&gt;Your team has invested heavily in ESLint&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Biome represents the next wave of frontend tooling — fast, unified, and zero-config. While ESLint isn’t dead (yet), it’s no longer the only serious player in the game. If Biome’s growth continues and its ecosystem expands, it could very well become the new standard in JavaScript linting.&lt;/p&gt;

&lt;p&gt;So, is ESLint dead?&lt;/p&gt;

&lt;p&gt;Not quite.&lt;/p&gt;

&lt;p&gt;But the future? It might just be Biome.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Have you tried Biome yet? Share your experience with the community — or tell us why you're still team ESLint.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>Prompt. Generate. Ship. The Rise of Vibe Coding in 2025</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Thu, 10 Apr 2025 21:12:13 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/prompt-generate-ship-the-rise-of-vibe-coding-in-2025-430e</link>
      <guid>https://forem.com/byte-sized-news/prompt-generate-ship-the-rise-of-vibe-coding-in-2025-430e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Describe what you want. The AI writes the code. You test and iterate.”&lt;br&gt;&lt;br&gt;
— Andrej Karpathy, 2025&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What if you could build full features by just describing them in natural language? That’s not the future — that’s &lt;em&gt;vibe coding&lt;/em&gt;, and it’s already reshaping how developers work.&lt;/p&gt;

&lt;p&gt;In this post, let’s unpack what vibe coding is, how it works, the tools behind it, and what it means for the future of software development.&lt;/p&gt;




&lt;h2&gt;
  
  
  🤔 What Is Vibe Coding?
&lt;/h2&gt;

&lt;p&gt;Coined by &lt;a href="https://en.wikipedia.org/wiki/Andrej_Karpathy" rel="noopener noreferrer"&gt;Andrej Karpathy&lt;/a&gt;, vibe coding refers to a new workflow where developers &lt;strong&gt;guide AI models to write code&lt;/strong&gt; through iterative prompting.&lt;/p&gt;

&lt;p&gt;It’s not just autocomplete. You describe what you want — UI components, APIs, logic — and the AI responds with working code. You then test it, adjust your prompt, and repeat until it clicks.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 How It Works
&lt;/h2&gt;

&lt;p&gt;Here’s what a typical vibe coding session might look like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You prompt:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
“Build a React component that displays a weather forecast using OpenWeatherMap API.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI responds:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Provides a full React component with fetch logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You iterate:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
“Add loading state. Now switch to Tailwind for styling.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI updates the code. You deploy. Done.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;It’s a mix of pair programming and creative direction — powered by AI.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🛠️ Tools That Enable Vibe Coding
&lt;/h2&gt;

&lt;p&gt;Here are some tools making vibe coding a daily habit for developers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cursor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A code editor like VS Code, with deep LLM integration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;ChatGPT / Gemini / Claude&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Prompt-based assistants for generating and explaining code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Replit Ghostwriter&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;In-browser coding with AI assistance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Continue.dev&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Open-source AI pair programmer for your local IDE&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  ✅ Why Devs Are Adopting It
&lt;/h2&gt;

&lt;p&gt;Vibe coding isn’t just a gimmick — it’s already boosting productivity and creativity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 &lt;strong&gt;Speed:&lt;/strong&gt; Quickly prototype features, components, or scripts&lt;/li&gt;
&lt;li&gt;🎨 &lt;strong&gt;Creativity:&lt;/strong&gt; Focus more on architecture and UX&lt;/li&gt;
&lt;li&gt;🧠 &lt;strong&gt;Learning:&lt;/strong&gt; Great for understanding new libraries or concepts&lt;/li&gt;
&lt;li&gt;🧼 &lt;strong&gt;Boilerplate relief:&lt;/strong&gt; No more writing repetitive code blocks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It turns your &lt;em&gt;thoughts&lt;/em&gt; into code — and makes programming feel less like manual labor and more like creative flow.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Caveats &amp;amp; Cautions
&lt;/h2&gt;

&lt;p&gt;Despite the hype, vibe coding has its pitfalls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧱 &lt;strong&gt;Brittle logic:&lt;/strong&gt; LLMs can hallucinate or use outdated APIs&lt;/li&gt;
&lt;li&gt;🕵️‍♂️ &lt;strong&gt;Trust issues:&lt;/strong&gt; You still need to read, test, and understand the code&lt;/li&gt;
&lt;li&gt;🔐 &lt;strong&gt;Security flaws:&lt;/strong&gt; LLMs might write insecure or inefficient implementations&lt;/li&gt;
&lt;li&gt;🧹 &lt;strong&gt;Debugging pain:&lt;/strong&gt; It’s harder to debug something you didn’t write from scratch&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Vibe responsibly: AI is your assistant, not your QA team.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧑‍💻 The Dev's Role Is Evolving
&lt;/h2&gt;

&lt;p&gt;In the world of vibe coding, the skillset of a developer is shifting:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Old World&lt;/th&gt;
&lt;th&gt;Vibe World&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Code everything yourself&lt;/td&gt;
&lt;td&gt;Prompt, review, refine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memorize syntax&lt;/td&gt;
&lt;td&gt;Understand concepts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debug boilerplate&lt;/td&gt;
&lt;td&gt;Curate and guide AI output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Write all tests&lt;/td&gt;
&lt;td&gt;Ask AI to help write them, then validate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You're no longer just a coder — you're a &lt;strong&gt;code director&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔮 Final Thoughts: Is Vibe Coding the Future?
&lt;/h2&gt;

&lt;p&gt;Absolutely — but it’s not a replacement for developers. It’s an augmentation.&lt;/p&gt;

&lt;p&gt;Vibe coding amplifies your productivity and creativity, but your fundamentals, judgment, and ability to reason through problems are still &lt;em&gt;irreplaceable&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This is not about coding less — it’s about coding &lt;em&gt;smarter&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The future isn’t typing faster — it’s thinking better.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  💬 What’s Your Take?
&lt;/h3&gt;

&lt;p&gt;Have you tried vibe coding yet? Are you using tools like Cursor, Replit, or ChatGPT to write actual production code? Share your experience in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>🚀 GitHub SSH &amp; "Repo Not Found": The Mistake That Took Me a Bit Too Long to Debug</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Fri, 04 Apr 2025 16:47:31 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/github-ssh-repo-not-found-the-mistake-that-took-me-a-bit-too-long-to-debug-1hon</link>
      <guid>https://forem.com/byte-sized-news/github-ssh-repo-not-found-the-mistake-that-took-me-a-bit-too-long-to-debug-1hon</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Hi ishan1! You've successfully authenticated, but GitHub does not provide shell access.”&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Sound familiar? It definitely did to me. 🙃&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧩 The Confusing Error
&lt;/h2&gt;

&lt;p&gt;So here I was, just trying to clone a private repository called &lt;code&gt;the-project&lt;/code&gt; from GitHub using SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github.com:some-org/the-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then this happened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ERROR: Repository not found.
fatal: Could not &lt;span class="nb"&gt;read &lt;/span&gt;from remote repository.

Please make sure you have the correct access rights
and the repository exists.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first, I thought:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maybe I typed the repo name wrong.&lt;/li&gt;
&lt;li&gt;Maybe it was deleted.&lt;/li&gt;
&lt;li&gt;Maybe I lost access?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But nope — everything was perfectly fine on GitHub.&lt;/p&gt;

&lt;p&gt;Just to be sure, I checked my SSH authentication:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-T&lt;/span&gt; git@github.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hi ishan1! You've successfully authenticated, but GitHub does not provide shell access.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait a second — &lt;em&gt;ishan1&lt;/em&gt;? I was expecting &lt;em&gt;ishan2&lt;/em&gt; (the account that actually had access to &lt;code&gt;the-project&lt;/code&gt;).&lt;/p&gt;




&lt;h2&gt;
  
  
  🤦 The Realization: SSH Was Using the Wrong GitHub Account
&lt;/h2&gt;

&lt;p&gt;Turns out, my machine was authenticating with the wrong SSH key — the one tied to &lt;code&gt;ishan1&lt;/code&gt;, my personal GitHub account, instead of &lt;code&gt;ishan2&lt;/code&gt;, which was the one invited to collaborate on the private repository &lt;code&gt;the-project&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So of course GitHub said “Repo not found” — from &lt;code&gt;ishan1&lt;/code&gt;'s perspective, it really didn’t exist!&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ The Fix: Use the Right SSH Key for the Right GitHub Account
&lt;/h2&gt;

&lt;p&gt;If you’re juggling multiple GitHub accounts like I am, here’s the fix that worked for me:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. 🔐 Generate a new SSH key for the correct GitHub account (&lt;code&gt;ishan2&lt;/code&gt;):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"ishan2@example.com"&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; ~/.ssh/id_ed25519_ishan2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. ➕ Add that key to your SSH agent:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
ssh-add ~/.ssh/id_ed25519_ishan2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. 📋 Add the public key to the &lt;code&gt;ishan2&lt;/code&gt; GitHub account:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/.ssh/id_ed25519_ishan2.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then go to GitHub → &lt;strong&gt;Settings&lt;/strong&gt; → &lt;strong&gt;SSH and GPG Keys&lt;/strong&gt; → &lt;strong&gt;New SSH Key&lt;/strong&gt;, and paste it there.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. 🧠 Set up a custom SSH host in &lt;code&gt;~/.ssh/config&lt;/code&gt;:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ssh"&gt;&lt;code&gt;&lt;span class="k"&gt;Host&lt;/span&gt; github-ishan2
    &lt;span class="k"&gt;HostName&lt;/span&gt; github.com
    &lt;span class="k"&gt;User&lt;/span&gt; git
    &lt;span class="k"&gt;IdentityFile&lt;/span&gt; ~/.ssh/id_ed25519_ishan2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. ✅ Clone the repo using the custom alias:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github-ishan2:some-org/the-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom 💥 — this time, the correct SSH key was used, the correct GitHub identity (&lt;code&gt;ishan2&lt;/code&gt;) was applied, and access to the private repo worked just like that.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Lesson Learned
&lt;/h2&gt;

&lt;p&gt;I used to treat SSH as a one-time setup. Turns out, if you're managing multiple GitHub identities (say, &lt;code&gt;ishan1&lt;/code&gt; for personal and &lt;code&gt;ishan2&lt;/code&gt; for work or freelance), your config needs to be smart about which key to use.&lt;/p&gt;

&lt;p&gt;If you get the "Repository not found" error while cloning a private repo, ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which GitHub user is this SSH key connected to?&lt;/li&gt;
&lt;li&gt;Is it the right one?&lt;/li&gt;
&lt;li&gt;Do I need a custom &lt;code&gt;~/.ssh/config&lt;/code&gt; setup?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✍️ Final Thoughts
&lt;/h2&gt;

&lt;p&gt;SSH is amazing… until it silently logs you in as the wrong person 😅&lt;/p&gt;

&lt;p&gt;If this post saves even one other developer from scratching their head for 30 minutes — it’s a win.&lt;/p&gt;

&lt;p&gt;Feel free to copy this setup and tweak the names for your own accounts. In my case, it was &lt;code&gt;ishan1&lt;/code&gt; vs &lt;code&gt;ishan2&lt;/code&gt;, and a private repo called &lt;code&gt;the-project&lt;/code&gt;. Yours might be different, but the fix remains the same.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Balancing Work and Learning: How to Keep Up With New Tech Without Overloading Yourself</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sun, 30 Mar 2025 18:25:54 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/balancing-work-and-learning-how-to-keep-up-with-new-tech-without-overloading-yourself-pjc</link>
      <guid>https://forem.com/byte-sized-news/balancing-work-and-learning-how-to-keep-up-with-new-tech-without-overloading-yourself-pjc</guid>
      <description>&lt;p&gt;The tech industry evolves at a breakneck speed, with new frameworks, languages, and best practices emerging constantly. As a developer, staying relevant requires continuous learning, but balancing this with work responsibilities (and a personal life) can feel overwhelming. So, how do you stay updated without burning out? Let's explore some practical strategies to manage both effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;strong&gt;Prioritize What to Learn&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With an endless sea of new technologies, the key is to &lt;strong&gt;prioritize&lt;/strong&gt; what is most relevant to your career and interests.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Assess Your Career Goals&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Are you aiming for a promotion, a job switch, or deeper expertise in your current role?&lt;/li&gt;
&lt;li&gt;Choose technologies that align with your goals rather than chasing every new trend.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Follow the 80/20 Rule&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Focus on the 20% of technologies that will give you 80% of the impact.&lt;/li&gt;
&lt;li&gt;If you’re a React developer, learning about performance optimization and server-side rendering might be more useful than dabbling in an entirely new framework.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Integrate Learning Into Your Work&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Rather than separating learning and work, blend them together for efficiency.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Work on Real Projects&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If your job allows, introduce new technologies into your current projects incrementally.&lt;/li&gt;
&lt;li&gt;Example: If you want to learn TypeScript, start integrating it into small components in an existing JavaScript codebase.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Contribute to Open Source&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Find an open-source project using the technology you want to learn and start contributing.&lt;/li&gt;
&lt;li&gt;This provides hands-on experience while collaborating with the community.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. &lt;strong&gt;Use Smart Learning Techniques&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Make the most of the limited time you have.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Learn in Small, Consistent Chunks&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Instead of trying to grasp an entire framework in a weekend, dedicate 30-60 minutes daily.&lt;/li&gt;
&lt;li&gt;Use techniques like spaced repetition and active recall for better retention.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Leverage Online Resources Wisely&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Follow high-quality newsletters, YouTube channels, and blogs.&lt;/li&gt;
&lt;li&gt;Use platforms like Frontend Masters, Pluralsight, or Udemy for structured learning.&lt;/li&gt;
&lt;li&gt;Podcasts are great for passive learning during commutes or workouts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. &lt;strong&gt;Avoid Burnout With a Structured Approach&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Overloading yourself with too much learning can lead to burnout. Keep it balanced.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Set Realistic Learning Goals&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Break down learning objectives into achievable steps.&lt;/li&gt;
&lt;li&gt;Example: "Learn the basics of Go in 4 weeks" rather than "Master Go as quickly as possible."&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Schedule Learning Sessions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Treat learning like an important meeting on your calendar.&lt;/li&gt;
&lt;li&gt;Even 3 focused sessions per week can lead to steady progress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Take Breaks &amp;amp; Unplug&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The brain needs time to process new information.&lt;/li&gt;
&lt;li&gt;Take breaks between learning sessions, and don’t feel guilty about taking days off from learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. &lt;strong&gt;Engage With the Developer Community&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Surrounding yourself with other learners and experienced developers can accelerate learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Join Developer Groups &amp;amp; Meetups&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Engage with local or online communities (Discord servers, Reddit, LinkedIn groups, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Teach What You Learn&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write blogs, create tutorials, or explain concepts to a colleague.&lt;/li&gt;
&lt;li&gt;Teaching reinforces learning and helps build credibility in the community.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. &lt;strong&gt;Use AI &amp;amp; Tools to Accelerate Learning&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;AI and automation can help reduce the time spent searching for solutions.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Use AI Assistants&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tools like ChatGPT, GitHub Copilot, and Tabnine can help you learn faster by suggesting code snippets and explanations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Automate Repetitive Tasks&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Free up time by automating repetitive coding or deployment processes.&lt;/li&gt;
&lt;li&gt;Example: Use CI/CD pipelines instead of manually deploying projects every time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. &lt;strong&gt;Find the Right Balance&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;At the end of the day, the goal is &lt;strong&gt;consistent progress, not perfection&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Recognize When to Slow Down&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If learning feels like a chore, take a step back and reassess your approach.&lt;/li&gt;
&lt;li&gt;It’s okay to pause and resume learning when you’re ready.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Celebrate Small Wins&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Completed a course? Solved a bug using a new concept? Celebrate those moments!&lt;/li&gt;
&lt;li&gt;Small wins keep motivation high and reinforce long-term learning habits.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Balancing work and continuous learning as a developer is challenging, but with the right approach, it’s absolutely manageable. Prioritize relevant skills, integrate learning into your work, pace yourself, and leverage the community. Most importantly, enjoy the process—because learning should feel exciting, not exhausting!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I Don’t Trust JavaScript. Here’s Why console.log("Hello") Returned undefined</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Mon, 24 Feb 2025 17:56:06 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/i-dont-trust-javascript-heres-why-consoleloghello-returned-undefined-3cam</link>
      <guid>https://forem.com/byte-sized-news/i-dont-trust-javascript-heres-why-consoleloghello-returned-undefined-3cam</guid>
      <description>&lt;p&gt;As a developer, I’ve seen some bizarre things, but nothing made me question reality more than 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="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;span class="c1"&gt;// Output: Hello&lt;/span&gt;
&lt;span class="c1"&gt;//         undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait… what? Why is JavaScript showing &lt;code&gt;undefined&lt;/code&gt; after logging &lt;code&gt;"Hello"&lt;/code&gt;? Did I break something? Is the universe glitching?  &lt;/p&gt;

&lt;p&gt;Turns out, &lt;strong&gt;JavaScript isn’t broken—it’s just JavaScript.&lt;/strong&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Does &lt;code&gt;console.log()&lt;/code&gt; Return &lt;code&gt;undefined&lt;/code&gt;?&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. &lt;code&gt;console.log()&lt;/code&gt; Prints but Doesn't Return Anything&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;console.log()&lt;/code&gt; &lt;strong&gt;outputs to the console but has no return value&lt;/strong&gt;—so it returns &lt;code&gt;undefined&lt;/code&gt; by default.  &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="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;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;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;"Hello"&lt;/code&gt; gets printed, but &lt;code&gt;console.log()&lt;/code&gt; itself doesn’t return anything useful—hence, &lt;code&gt;result&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. The Browser Console Reveals the Truth&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you type &lt;code&gt;console.log("Hello")&lt;/code&gt; &lt;strong&gt;directly in the browser console&lt;/strong&gt;, it prints &lt;code&gt;"Hello"&lt;/code&gt; and then shows &lt;code&gt;undefined&lt;/code&gt; as the return value:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;undefined&lt;/code&gt; isn’t part of &lt;code&gt;console.log()&lt;/code&gt;. It’s just the console displaying what the function returned.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. The "Return Trap" in Functions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you call &lt;code&gt;console.log()&lt;/code&gt; inside a function and log its output, you'll see the same behavior:&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;sayHello&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;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; 
&lt;span class="c1"&gt;// Logs: Hello&lt;/span&gt;
&lt;span class="c1"&gt;// Then: undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since &lt;code&gt;sayHello()&lt;/code&gt; doesn't return anything, &lt;code&gt;console.log(sayHello())&lt;/code&gt; first prints &lt;code&gt;"Hello"&lt;/code&gt; and then logs &lt;code&gt;undefined&lt;/code&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. When Things Get Weird: Overriding &lt;code&gt;console.log()&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For the truly paranoid, here’s how JavaScript can gaslight you:&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="nx"&gt;log&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="kc"&gt;undefined&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;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Nothing prints!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;console.log()&lt;/code&gt; is redefined (by accident or an evil teammate), it won’t even log anything. Now that’s a true nightmare!  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Final Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript didn’t lie—it just has some quirks that make you question your sanity. &lt;code&gt;console.log()&lt;/code&gt; is a tool for debugging, not for returning values. So next time you see &lt;code&gt;undefined&lt;/code&gt;, just remember: &lt;strong&gt;it’s not a bug, it’s a feature.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>Axios Cheat Sheet: A Quick Guide for Developers</title>
      <dc:creator>Ishan Bagchi</dc:creator>
      <pubDate>Sun, 23 Feb 2025 07:45:28 +0000</pubDate>
      <link>https://forem.com/byte-sized-news/axios-cheat-sheet-a-quick-guide-for-developers-3261</link>
      <guid>https://forem.com/byte-sized-news/axios-cheat-sheet-a-quick-guide-for-developers-3261</guid>
      <description>&lt;p&gt;Axios is a powerful and easy-to-use HTTP client for JavaScript, commonly used in frontend and backend applications for making HTTP requests. This cheat sheet covers the most commonly used features and best practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Installation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Install Axios using npm, yarn, or a CDN:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using npm&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;axios

&lt;span class="c"&gt;# Using yarn&lt;/span&gt;
yarn add axios

&lt;span class="c"&gt;# Using a CDN&lt;/span&gt;
&amp;lt;script &lt;span class="nv"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;2. Making GET Requests&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;3. Making POST Requests&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Axios Cheat Sheet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This is a sample post request.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;4. PUT and PATCH Requests&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PUT&lt;/strong&gt; replaces the entire resource:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Updated Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Updated body text.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PATCH&lt;/strong&gt; updates only specific fields:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Partially Updated Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;5. DELETE Requests&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Deleted successfully&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;6. Setting Headers&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&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;Bearer YOUR_ACCESS_TOKEN&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;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;7. Handling Query Parameters&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;8. Using Axios Instances&lt;/strong&gt;
&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;const&lt;/span&gt; &lt;span class="nx"&gt;apiClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;timeout&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="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&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;Bearer YOUR_ACCESS_TOKEN&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;apiClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;9. Handling Errors Gracefully&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/invalid&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server responded with:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;No response received:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error setting up request:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;10. Interceptors for Request and Response&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;interceptors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Request sent at:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;interceptors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Response received:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;11. Cancelling Requests&lt;/strong&gt;
&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;const&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbortController&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Cancel the request&lt;/span&gt;
&lt;span class="nx"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;12. Concurrent Requests&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts/2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;spread&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;post2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Post 1:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;post1&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;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="s1"&gt;Post 2:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;post2&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="p"&gt;}))&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Axios isn't just another HTTP client—it's your digital henchman, fetching data, sending payloads, and handling errors like a seasoned assassin. Whether you're on the frontend or backend battlefield, this cheat sheet arms you with the firepower to dominate API interactions. Keep it close, or risk drowning in a sea of failed requests and endless debugging nightmares.&lt;/p&gt;

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