<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saurabh Sharma</title>
    <description>The latest articles on DEV Community by Saurabh Sharma (@saurabh_sharma_7a9a61107d).</description>
    <link>https://dev.to/saurabh_sharma_7a9a61107d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3645391%2F9f1b1885-0e2a-4251-8a99-fe11981f7616.png</url>
      <title>DEV Community: Saurabh Sharma</title>
      <link>https://dev.to/saurabh_sharma_7a9a61107d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saurabh_sharma_7a9a61107d"/>
    <language>en</language>
    <item>
      <title>JavaScript told me to buy 8 bags of concrete. I needed 7.</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Thu, 26 Nov 2026 16:46:30 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/javascript-told-me-to-buy-8-bags-of-concrete-i-needed-7-5oh</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/javascript-told-me-to-buy-8-bags-of-concrete-i-needed-7-5oh</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz5xpoh40t5mmlsjk4gmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz5xpoh40t5mmlsjk4gmt.png" alt=" " width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open your browser console and paste 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="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.05&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;0.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a small pad for an AC unit. 4 ft by 3 ft, 4 inches thick, plus 5% extra for spillage, divided by 0.6 cubic feet (what one 80 lb bag of concrete mix makes). On paper the answer is 7. Exactly 7 bags.&lt;/p&gt;

&lt;p&gt;JavaScript says &lt;code&gt;7.000000000000001&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Every bag calculator rounds up, because nobody sells 0.4 of a bag. So you wrap it in &lt;code&gt;Math.ceil()&lt;/code&gt; and the page tells you to buy 8.&lt;/p&gt;

&lt;p&gt;One extra bag isn't a disaster. It's six bucks and 80 more pounds to drag across a parking lot. But I wanted to know how often it happens, so I brute-forced it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How often does this actually happen?
&lt;/h2&gt;

&lt;p&gt;I ran every slab from 1 x 1 ft up to 20 x 20 ft, at 2, 3, 4, 5 and 6 inches thick, with 0, 5, 10 and 15% waste, for 40, 60 and 80 lb bags. That's 12,600 combinations.&lt;/p&gt;

&lt;p&gt;2,179 of them work out to an exact whole number of bags. &lt;strong&gt;620 of those come out one bag high&lt;/strong&gt; with a plain &lt;code&gt;Math.ceil&lt;/code&gt;. That's 28% of the cases where the math is clean.&lt;/p&gt;

&lt;p&gt;These aren't weird edge cases either. 4 x 4 at 6 inches with 5% waste. 6 x 3 at 4 inches with 10%. The boring sizes people actually pour.&lt;/p&gt;

&lt;p&gt;Here's the script if you want to check me:&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;let&lt;/span&gt; &lt;span class="n"&gt;exact&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="n"&gt;wrong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bag&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 80, 60, 40 lb yields in cu ft&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="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;l&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="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;w&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;const&lt;/span&gt; &lt;span class="n"&gt;inches&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&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="n"&gt;waste&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inches&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;waste&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="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;bag&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bags&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bags&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;lt;&lt;/span&gt; &lt;span class="mf"&gt;1e-9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;exact&lt;/span&gt;&lt;span class="o"&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;wrong&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;exact&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wrong&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// { exact: 2179, wrong: 620 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The fix is four lines
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;EPSILON&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1e-9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;roundUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;snapped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&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;lt;&lt;/span&gt; &lt;span class="no"&gt;EPSILON&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;steps&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;snapped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the number is within a billionth of a whole number, treat it as that whole number. Then round up. &lt;code&gt;7.000000000000001&lt;/code&gt; becomes 7. &lt;code&gt;7.2&lt;/code&gt; still becomes 8, which is correct, because 7.2 bags means you need 8.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;step&lt;/code&gt; argument came later. A lot of ready-mix suppliers sell by the half yard, so &lt;code&gt;roundUp(2.1, 0.5)&lt;/code&gt; returns 2.5, which is what you'd actually order from the truck.&lt;/p&gt;

&lt;p&gt;Is 1e-9 the "right" epsilon? Honestly, it's just way bigger than float noise at these magnitudes and way smaller than any real fraction of a bag. Nobody is pouring a slab where a billionth of a bag matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug two: toFixed doesn't round like a human
&lt;/h2&gt;

&lt;p&gt;This one I knew about in theory and still walked into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.005&lt;/span&gt;&lt;span class="p"&gt;)&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="c1"&gt;// "1.00"&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;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.005&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="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.005 can't be stored exactly. It's really something like 1.00499999999999989..., so both methods round it down. Correct for the computer. Wrong for the person reading it.&lt;/p&gt;

&lt;p&gt;For money, that's a cent. For a calculator, it's worse than it sounds. While I was looking at existing concrete calculators before building mine, one of them showed &lt;strong&gt;1.536 cubic yards in the big headline number and 1.556 a few lines lower, on the same result card.&lt;/strong&gt; Same inputs. I don't know exactly how that happened on their end, but my guess is two parts of the page rounding the same value two different ways.&lt;/p&gt;

&lt;p&gt;If you're about to order concrete and the page disagrees with itself, which number do you trust? You don't. You close the tab.&lt;/p&gt;

&lt;p&gt;My fix was a small relative nudge before rounding:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;roundTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;decimals&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;scaled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;nudged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scaled&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scaled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scaled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1e-12&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nudged&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// roundTo(1.005, 2) === 1.01&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function matters less than the rule I made around it: &lt;strong&gt;there's exactly one rounding module.&lt;/strong&gt; The headline number, the little stat chips, the shopping list, the worked example in the article text, all of it calls the same functions. There's a test that asserts the headline equals the shopping list number for every tool. If two places can format a number differently, eventually they will, and it'll be in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug three: people type commas
&lt;/h2&gt;

&lt;p&gt;US users type &lt;code&gt;1,250&lt;/code&gt;. A lot of other people type &lt;code&gt;0,5&lt;/code&gt; and mean half. Both show up in the same input box.&lt;/p&gt;

&lt;p&gt;The rule I ended up with: a comma is a decimal point, unless the string looks like a properly grouped thousands number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;grouped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/^-?&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&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="n"&gt;d&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;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trimmed&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="n"&gt;normalised&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;grouped&lt;/span&gt;
  &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;trimmed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;trimmed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&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;Note the &lt;code&gt;[1-9]&lt;/code&gt; at the start. A leading zero never starts a thousands group, so &lt;code&gt;0,500&lt;/code&gt; reads as half, not five hundred. That one came from a real test case that failed, not from me being clever.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that wasn't a bug: my mulch page was shipping drywall prices
&lt;/h2&gt;

&lt;p&gt;The site is static &lt;a href="https://astro.build" rel="noopener noreferrer"&gt;Astro&lt;/a&gt; with Preact islands for the calculators. No framework runtime on the pages that don't need one.&lt;/p&gt;

&lt;p&gt;Even so, my first build shipped 61 to 64 KB of gzipped JS per tool page. The culprit was data. Every page bundled the full prices and materials files: every gravel density, every bag yield, every paint coverage rate, for every tool. The mulch page was carrying drywall prices around.&lt;/p&gt;

&lt;p&gt;The fix was more fun than I expected. At build time, each calculator gets driven like a bored visitor would drive it: every shape tab, both unit systems, every option in every dropdown, a second area, every waste chip, then a batch of random inputs. Every data entry the engine reads along the way gets recorded. Only those entries get written into the page.&lt;/p&gt;

&lt;p&gt;Then a separate test runs a bigger, differently seeded batch of random inputs against just that slice and checks the results match the full data. If the build-time walk missed something, a test fails instead of a visitor's calculator.&lt;/p&gt;

&lt;p&gt;Result: 36 to 38 KB per page, and Lighthouse mobile scores of 100 across the board on all 34 live pages. No Calculate button either. Results update as you type with a 150ms debounce, which felt obvious until I saw how many calculators still make you click.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building a calculator
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Never &lt;code&gt;Math.ceil&lt;/code&gt; a float that came out of a division.&lt;/strong&gt; Snap first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One rounding module.&lt;/strong&gt; Not a helper. The only place numbers become strings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the hand-checked examples first.&lt;/strong&gt; A 10 x 10 slab at 4 inches is 1.23 cubic yards, 56 bags of 80 lb mix, 75 bags of 60 lb. I worked those out on paper before the engine existed, and they're still in the test suite. It's at 1,775 tests now. Most of them are boring. That's kind of the point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show your sources.&lt;/strong&gt; Bag yields come off the manufacturer's data sheet. Gravel density varies by supplier and moisture, so the field is editable and the page says so. People trust a number more when they can see where it came from.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test at 390px wide.&lt;/strong&gt; That's someone standing in a hardware store aisle with one hand free. A few calculators I looked at hide the shape preview on mobile, which is exactly where you need it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Go try to break it
&lt;/h2&gt;

&lt;p&gt;All of this lives in &lt;a href="https://gravelcalculatorhq.com/" rel="noopener noreferrer"&gt;Gravel Calculator HQ&lt;/a&gt;, a free set of calculators for concrete, gravel, mulch, topsoil, drywall and paint. No sign-up, no pop-ups.&lt;/p&gt;

&lt;p&gt;If you want to poke at the bag rounding, the &lt;a href="https://gravelcalculatorhq.com/concrete-calculator/" rel="noopener noreferrer"&gt;concrete calculator&lt;/a&gt; has slab, footing, column, wall, steps, curb and circle tabs, and the share link puts your inputs in the URL so you can send me a bad result directly. The homepage is a &lt;a href="https://gravelcalculatorhq.com/" rel="noopener noreferrer"&gt;gravel calculator&lt;/a&gt; that turns length, width and depth into cubic yards and tons, which is where the whole project started: one too many trips back to the supply yard for half a yard I didn't measure for.&lt;/p&gt;

&lt;p&gt;If you can make any of them show &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;, or a shopping list that disagrees with the headline, tell me in the comments. I'll fix it and credit you.&lt;/p&gt;

&lt;p&gt;And I'm curious: &lt;strong&gt;what's the most expensive floating point bug you've shipped?&lt;/strong&gt; Mine cost one bag of concrete. Feels like I got off easy.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>astro</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I joined oral surgeon counts to income data for all 50 states. One gap had nothing in it.</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Sun, 22 Nov 2026 13:39:48 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/i-joined-oral-surgeon-counts-to-income-data-for-all-50-states-one-gap-had-nothing-in-it-4k9i</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/i-joined-oral-surgeon-counts-to-income-data-for-all-50-states-one-gap-had-nothing-in-it-4k9i</guid>
      <description>&lt;p&gt;I run a small &lt;a href="https://dentalimplantcalc.com/" rel="noopener noreferrer"&gt;dental implants cost&lt;/a&gt; calculator, and at some point I got curious about something the calculator can't show. Are implants harder to get in poorer states because they cost more there, or because there's nobody nearby to place them?&lt;/p&gt;

&lt;p&gt;So I pulled a few public datasets together and checked. The answer was mostly the second one. The more useful lesson was about a mistake I almost made along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The data
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Surgeons:&lt;/strong&gt; KFF publishes counts of professionally active oral and maxillofacial surgeons, based on an ADA data request (end of 2025). It's 7,482 nationally, or 2.19 per 100,000 people. I used Census Bureau Vintage 2025 estimates for population.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Income:&lt;/strong&gt; Census ACS. Median household income was $81,604 in 2024.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implant cost:&lt;/strong&gt; my own model. I use $4,259 for a single implant, which is 5.22% of that national median income.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The spread between states is big. New Hampshire has 3.25 surgeons per 100,000 and Wyoming has 1.19, which is about 2.7x.&lt;/p&gt;

&lt;h2&gt;
  
  
  Surgeons follow income
&lt;/h2&gt;

&lt;p&gt;Across the 50 states, surgeon density against median household income gives a Pearson r of +0.667. Surgeons against all dentists comes out at +0.645, so it isn't only a specialist thing. It looks like where dental supply generally ends up.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap
&lt;/h2&gt;

&lt;p&gt;I also correlated surgeon density with implant cost as a share of income. I got −0.384, and it looked like a finding for about ten minutes.&lt;/p&gt;

&lt;p&gt;Then I remembered that 45 of my 50 states share a single dollar cost figure. So "cost as a share of income" is basically just 1 divided by income. Of course it correlates with anything that tracks income. The relationship is built into the ratio, so it tells you nothing.&lt;/p&gt;

&lt;p&gt;The surgeon-supply axis comes from a separate source, which makes its link to income the real result. The cost axis is mostly income wearing a different label. If you build dashboards with ratio metrics, check what's actually varying in the denominator before you read anything into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 15-state "double bind"
&lt;/h2&gt;

&lt;p&gt;If you split states into "fewer surgeons per capita and a heavier cost burden" and "better on both," 15 states land in the bad group.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Double-bind (15)&lt;/th&gt;
&lt;th&gt;Better on both&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mean household income&lt;/td&gt;
&lt;td&gt;$68,950&lt;/td&gt;
&lt;td&gt;$89,839&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Surgeons per 100k&lt;/td&gt;
&lt;td&gt;1.69&lt;/td&gt;
&lt;td&gt;2.53&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The two groups don't overlap on income at all. Wyoming ($75,532) is the richest state in the bad group. South Dakota ($76,881) is the poorest state in the good one. That leaves a $1,349 gap with no state in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Doesn't Medicaid cover this?"
&lt;/h2&gt;

&lt;p&gt;Mostly no, and the reason is a bit dull. As of 31 Dec 2024, 11 states plus DC had an "extensive" adult dental benefit, up from 2 in 2020 (CareQuest / ADA HPI / CHCS rubric). But that rubric scores 14 service categories, and implants aren't one of them. Only one of the 15 double-bind states qualifies, compared with three of the better-off group.&lt;/p&gt;

&lt;p&gt;New York is the exception I found. Its manual (effective 31 January 2024) covers medically necessary implants, with published rates of $1,000 for the implant body, $400 for the abutment and $800 for the crown. That's $2,200, against the $4,259 I model for a private patient.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I left out
&lt;/h2&gt;

&lt;p&gt;I didn't build a composite "access index." Any version needs weights, and I'd be making them up. Also, this is correlation, 50 data points, and a cost model that is deliberately simple. I wrote out five limits on the page itself rather than burying them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use it if it helps
&lt;/h2&gt;

&lt;p&gt;The full 50-state table is on the &lt;a href="https://dentalimplantcalc.com/dental-implant-access-gap/" rel="noopener noreferrer"&gt;study page&lt;/a&gt;, along with the method and sources. The CSV and JSON are CC BY 4.0, so take them and do your own analysis. If you find a mistake in the joins, I'd like to hear about it.&lt;/p&gt;

&lt;p&gt;Has anyone dealt with the "ratio looks like a finding but is really just the denominator" problem in a messier setting? I'm curious how you caught it.&lt;/p&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Total overtime pay 3: the shortcut behind the new overtime deduction, and where it breaks</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Sun, 15 Nov 2026 08:22:12 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/total-overtime-pay-3-the-shortcut-behind-the-new-overtime-deduction-and-where-it-breaks-1fo4</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/total-overtime-pay-3-the-shortcut-behind-the-new-overtime-deduction-and-where-it-breaks-1fo4</guid>
      <description>&lt;p&gt;The new federal deduction for overtime (from the 2025 budget law, claimed on Schedule 1-A) doesn't cover your overtime pay. It covers the &lt;em&gt;premium&lt;/em&gt; part of it, the extra half in time-and-a-half. I'm building a free payroll calculator site, and getting that one distinction right turned into most of the work on the overtime page.&lt;/p&gt;

&lt;p&gt;Here's the part that's easy to code and easy to get wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The math is one line
&lt;/h2&gt;

&lt;p&gt;Say you earn $22 an hour and work 6 overtime hours a week for a full year, 312 hours.&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="c1"&gt;// the "half" only&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;qualifiedOvertimeFromHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;otHours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="nf"&gt;roundCurrency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;otHours&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// 0.5 * 22 * 312 = 3,432&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your total overtime pay for those hours is 1.5 × 22 × 312 = $10,296. Only $3,432 of that is deduction-eligible. The other $6,864 is your regular rate for those hours, which was never "overtime premium" in the first place.&lt;/p&gt;

&lt;p&gt;Plenty of people only have the total from a pay stub, so I added a second path:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;qualifiedOvertimeFromTotalPay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalOvertimePay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="nf"&gt;roundCurrency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalOvertimePay&lt;/span&gt; &lt;span class="o"&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="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// 10,296 / 3 = 3,432&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time-and-a-half is 1.5x, the premium is 0.5x, and 0.5 / 1.5 is a third. Same answer both ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where ÷3 quietly breaks
&lt;/h2&gt;

&lt;p&gt;It only works if every overtime hour was paid at exactly 1.5x. If you get double time, or your state has daily overtime (California does), the total is no longer 1.5x of anything, and dividing by three gives you a number that looks plausible and is wrong.&lt;/p&gt;

&lt;p&gt;The eligible amount is the overtime the federal wage law (FLSA) requires, which is 1.5x past 40 hours in a week. Anything extra your state or your employer adds on top doesn't count. So ten hours paid at 2x on a $22 rate is $440, ÷3 says $146.67, and the most that could qualify if all ten were past 40 in the week is 0.5 × 22 × 10 = $110. I labelled the total-pay path in the UI as assuming time-and-a-half, because that's the honest scope of the shortcut.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cap and the phase-out
&lt;/h2&gt;

&lt;p&gt;For 2026 the data file I'm working from says:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cap: $12,500 single or head of household, $25,000 married filing jointly. Married filing separately can't claim it.&lt;/li&gt;
&lt;li&gt;Phase-out starts at $150,000 MAGI (single) or $300,000 (joint). The cap drops by $100 for every $1,000 over.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The detail I almost got wrong is the rounding on that last line. The Schedule 1-A worksheet says to round the "per $1,000" figure &lt;em&gt;down&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;phaseOutReduction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;magi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ratePer1000&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="n"&gt;excess&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&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="n"&gt;magi&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;threshold&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="n"&gt;excess&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;excess&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;ratePer1000&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;$6,001 over the threshold counts as 6, not 7. A single filer at $156,500 MAGI loses $600 of cap, so the cap becomes $11,900.&lt;/p&gt;

&lt;p&gt;The car loan interest deduction, from the same law and the same form, rounds &lt;em&gt;up&lt;/em&gt; and uses $200 per $1,000. If you build both and copy one function for the other, one of them will be off by a step near every boundary. There's a comment in my code about it now, because I will forget.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a $3,432 deduction is worth
&lt;/h2&gt;

&lt;p&gt;I run the deduction through the actual bracket math instead of multiplying by a marginal rate. For a single filer with $56,056 in wages (the $22 job above, plus the overtime), 2026 standard deduction of $16,100, the deduction saves &lt;strong&gt;$411.84&lt;/strong&gt; in federal income tax. That's 12% of $3,432, because it all lands in the 12% bracket. Someone straddling a bracket edge would see something different, which is why a flat "deduction × your rate" shortcut is a bad idea.&lt;/p&gt;

&lt;p&gt;Social Security and Medicare still come out of the full amount. On the $3,432 premium alone that's $262.54. The deduction doesn't touch payroll tax, and it's claimed on your return, so don't expect a bigger paycheck.&lt;/p&gt;

&lt;h2&gt;
  
  
  Last thing: the W-2
&lt;/h2&gt;

&lt;p&gt;For 2026 the qualified overtime amount is meant to show up in Box 12 with code TT. Employers didn't have that for 2025 forms, so some of them stuffed the figure into Box 14 with their own label. If you're building anything that reads a W-2, don't assume one format.&lt;/p&gt;

&lt;p&gt;The calculator is at &lt;a href="https://paytimehub.com/no-tax-on-overtime-calculator/" rel="noopener noreferrer"&gt;paytimehub.com/no-tax-on-overtime-calculator&lt;/a&gt; if you want to poke at it. It's an Astro site, no backend, everything runs in the browser. If you spot a number that looks off, I'd rather hear about it.&lt;/p&gt;

</description>
      <category>astro</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>I built a GIF compressor that runs 100% in your browser (because Discord's file limits are the worst)</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Thu, 27 Aug 2026 08:33:26 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/i-built-a-gif-compressor-that-runs-100-in-your-browser-because-discords-file-limits-are-the-3m8j</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/i-built-a-gif-compressor-that-runs-100-in-your-browser-because-discords-file-limits-are-the-3m8j</guid>
      <description>&lt;p&gt;If you've ever tried to upload a GIF as a Discord emoji, you know the drill. Discord wants it under 256KB, your export is 4MB, and now you're bouncing between three different "free" online converters. One of them gates batch processing. Another caps how many files you can run per day. Another quietly uploads your file to a server you never agreed to.&lt;/p&gt;

&lt;p&gt;I got tired of that loop, so I built &lt;a href="https://compressgifs.com" rel="noopener noreferrer"&gt;CompressGIFs&lt;/a&gt;. It's a small GIF toolkit that runs entirely in your browser. No upload, no account, no daily cap.&lt;/p&gt;

&lt;p&gt;Here's what it does and why I built it this way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The actual problem
&lt;/h2&gt;

&lt;p&gt;"Compress a GIF" sounds like a solved problem. It isn't, once you look at what people actually need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discord emoji: 256KB, 128×128&lt;/li&gt;
&lt;li&gt;Discord stickers: their own size and format quirks&lt;/li&gt;
&lt;li&gt;Slack emoji, WhatsApp stickers, Telegram stickers: all different limits&lt;/li&gt;
&lt;li&gt;And the universal one: "just make this smaller, I don't care about the settings, I just need it to work"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every tool I tried made me guess. Drag a quality slider, export, check the file size, repeat until it's small enough. That's a bad experience for something that should be simple. I already know my target size. The tool should just get me there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's different here
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. You tell it the target size and it finds the settings for you.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of a lossy quality slider, you type "under 256KB" or pick a Discord, Slack, WhatsApp, or Telegram preset. The tool then runs a binary search across compression parameters until the output lands under your target:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Binary search gifsicle's --lossy value (1 to 200)&lt;/li&gt;
&lt;li&gt;Still too big? Binary search --colors (256 down to a floor)&lt;/li&gt;
&lt;li&gt;Still too big? Fall back to proportional downscaling, step by step&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This runs inside a Web Worker so the tab doesn't freeze while it's working. Some of these searches take a few seconds on bigger files, and you actually see live progress instead of a frozen screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. It's genuinely client-side.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The compression engine is &lt;code&gt;gifsicle&lt;/code&gt; compiled to WASM, running right in your browser. Your GIF never touches a server. That's not just a privacy checkbox I'm ticking. It's also the reason the next point is even possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Batch processing isn't a paywall.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I checked what the big converters actually offer on their free tiers. One well-known one caps you at 10 conversions a day and a 5-file batch limit. Batch processing is literally their paid upsell. That makes sense when you're paying for server compute per file. It doesn't make sense here, because there's no server doing the work. Your own machine is. So batch is just unlimited. Drop in a folder of 40 GIFs, walk away, come back to 40 compressed files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. A compliance checker, not just a compressor.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is honestly the tool I wanted most for myself. Upload a GIF, pick "Discord Sticker" or "Slack Emoji," and get a clear pass or fail on size, dimensions, and format all together, with a specific note on what to fix if it fails. If you moderate a Discord server, this is the kind of thing you pin in your assets channel so people stop asking why their upload keeps getting rejected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just build "one more compress gif page"
&lt;/h2&gt;

&lt;p&gt;Before writing any code, I looked at who actually ranks for these terms. The space is dominated by a 13 year old incumbent with hundreds of interlinked tool pages and real domain authority. That's not something a single new landing page beats just by looking nicer. So instead of chasing the generic "compress gif" term head on, I scoped this narrower and deeper. A full GIF workflow: compress, resize, convert, and validate against platform limits, with the Discord specific tools front and center, since that's the highest intent, most underserved corner of this whole space right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack, if you're curious
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Astro&lt;/strong&gt; (static, zero backend)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gifsicle-wasm-browser&lt;/strong&gt; for the actual compression, lazy loaded so it doesn't bloat the initial page weight&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web Workers&lt;/strong&gt; for the target size search loop&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare Pages&lt;/strong&gt; for hosting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No database, no API, no account system. Just static files and WASM running on your CPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://compressgifs.com" rel="noopener noreferrer"&gt;compressgifs.com&lt;/a&gt;. Free, no signup, nothing leaves your browser.&lt;/p&gt;

&lt;p&gt;If you run a Discord server, the &lt;a href="https://compressgifs.com/discord-sticker-checker/" rel="noopener noreferrer"&gt;Discord compliance checker&lt;/a&gt; is worth a look on its own. It's the tool I wish had existed before I spent an entire afternoon manually re-exporting stickers at four different sizes.&lt;/p&gt;

&lt;p&gt;Would genuinely love feedback from this crowd, especially if you hit an edge case where the target size search doesn't converge. That's the part I'm most paranoid about getting wrong.&lt;/p&gt;

</description>
      <category>web</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>What I Learned Building a Payroll Calculator Site Solo (Not Truly Solo 😅)</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Fri, 14 Aug 2026 07:54:02 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/what-i-learned-building-a-payroll-calculator-site-solo-not-truly-solo--59kn</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/what-i-learned-building-a-payroll-calculator-site-solo-not-truly-solo--59kn</guid>
      <description>&lt;p&gt;PayTimeHub started as one page - a paycheck withholding calculator - because I couldn't find one online that didn't bury the number under three popups and an email gate. It's since grown into a small family of calculators: paycheck withholding by state, a raise calculator, hourly-to-salary conversion, hours-to-decimal timesheet conversion, and time-and-a-half overtime. Nothing behind a signup, nothing sent to a server. A few things stood out along the way that I didn't expect going in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tax logic is the actual product
&lt;/h2&gt;

&lt;p&gt;I assumed the hard part would be the frontend. It wasn't. Federal withholding is a set of published brackets, but state withholding is fifty different rulebooks, several of which don't tax income at all, some of which have their own standard deduction schedules, and a couple that change their brackets more often than you'd think reasonable for a tax table. Getting &lt;code&gt;[state]-paycheck-calculator&lt;/code&gt; right per state meant the actual engineering effort lives in a tax engine, not in a component tree. The UI took a weekend. The tax logic is still the thing I go back and double-check.&lt;/p&gt;

&lt;p&gt;The lesson: for a "calculator" site, the calculator is the product. Everything else - layout, copy, SEO - is packaging around a number that has to be correct, because a wrong number here isn't a cosmetic bug, it's a wrong paycheck estimate someone might actually plan around.&lt;/p&gt;

&lt;h2&gt;
  
  
  Floating-point math will find you eventually
&lt;/h2&gt;

&lt;p&gt;Money math in JavaScript looks fine until it doesn't. &lt;code&gt;0.1 + 0.2&lt;/code&gt; not equaling &lt;code&gt;0.3&lt;/code&gt; is the famous example, but the version that actually bit me was subtler: a raise calculation that produced &lt;code&gt;$53,999.999999999996&lt;/code&gt; instead of a clean &lt;code&gt;$54,000&lt;/code&gt; on one specific input, not because of an obviously bad float, but because the multiplication itself introduced error just below a rounding boundary. I wrote about that one separately, but the broader takeaway was that every calculator that touches money needs to funnel through the exact same rounding function, or you end up with five slightly different &lt;code&gt;.toFixed(2)&lt;/code&gt; calls that quietly disagree with each other on the edges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Static-first is a feature, not a shortcut
&lt;/h2&gt;

&lt;p&gt;Astro was the right call, but not for the reason I expected going in. I picked it for the build output - static pages, minimal JS, fast Lighthouse scores. What turned out to matter more is that "no server, no data leaves the browser" isn't just a privacy pitch, it removes an entire category of things I don't have to build: no auth, no database, no rate limiting, no GDPR data-handling story. The calculators run entirely client-side. That constraint made the whole project smaller in a good way - there's less surface area for something to go wrong, and less to maintain six months from now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic routes make "fifty states" tractable
&lt;/h2&gt;

&lt;p&gt;Before I set up &lt;code&gt;[state]-paycheck-calculator&lt;/code&gt; and &lt;code&gt;[value]-salary-to-hourly&lt;/code&gt; as dynamic routes, I was mentally treating "add all 50 states" as fifty separate pages to hand-write. That's the wrong mental model for this kind of site. One template plus a data file per state is the actual shape of the problem, and it's the difference between a task that takes a weekend and one that never gets finished because it feels too big to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shipping something narrow beats shipping something broad
&lt;/h2&gt;

&lt;p&gt;Early on I was tempted to build a general "financial calculator suite" - retirement, mortgage, budgeting, the works. I'm glad I didn't. Payroll and pay math is a coherent enough niche that the calculators reinforce each other: someone converting hourly to salary is plausibly also the kind of person who wants to know their overtime rate or their raise in real terms. A broader suite would have diluted that, and I'd have shipped ten shallow tools instead of five that actually do their one job well.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;More state-specific accuracy passes, and probably a couple more calculators in the same vein - the goal isn't to cover every financial calculation that exists, just to keep doing pay and payroll math well. If you're curious, the whole thing is live at &lt;a href="https://paytimehub.com" rel="noopener noreferrer"&gt;paytimehub.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The rounding bug that almost shipped in a payroll calculator</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Fri, 14 Aug 2026 07:47:02 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/the-rounding-bug-that-almost-shipped-in-a-payroll-calculator-jm3</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/the-rounding-bug-that-almost-shipped-in-a-payroll-calculator-jm3</guid>
      <description>&lt;p&gt;I've been building &lt;a href="https://paytimehub.com" rel="noopener noreferrer"&gt;PayTimeHub&lt;/a&gt;, a set of free payroll and pay calculators - paycheck withholding, raise calculator, hours-to-decimal, time and a half. Money math looks trivial until you actually ship it, and one bug almost got through that's worth writing up.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Every calculator on the site takes a dollar amount, does some arithmetic on it, and shows the result back to the user. A raise calculator multiplies a salary by a percentage. An overtime calculator multiplies an hourly rate by 1.5. Simple stuff, until you remember that JavaScript does floating-point math.&lt;/p&gt;

&lt;p&gt;Try this in a console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;
&lt;span class="c1"&gt;// 0.30000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine that showing up on a page that's supposed to tell someone their new salary. A $52,000 salary with a 3.85% raise should read as a clean $54,000. Depending on how you chain the multiplication and division, you can end up with something like $53,999.999999999996, which then gets formatted and displayed as a genuinely wrong number - or worse, rounds inconsistently between two calculators that are supposed to agree with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Nothing exotic, just a single shared rounding function that every calculator on the site routes its output through before display:&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;roundCurrency&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EPSILON&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="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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Number.EPSILON&lt;/code&gt; nudge matters more than it looks like it should. Without it, plain &lt;code&gt;Math.round(amount * 100) / 100&lt;/code&gt; still misfires on specific inputs, because the multiplication itself can introduce a floating-point error just below a rounding boundary, so a value that should round up rounds down instead. Adding the smallest possible float before rounding pushes those edge cases back onto the correct side without changing any value that wasn't on the boundary to begin with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it's worth writing down
&lt;/h2&gt;

&lt;p&gt;The interesting part isn't the fix - it's that this exact class of bug is invisible in casual testing. Round numbers like $50,000 and 5% never trigger it. It shows up on the specific combinations that don't divide cleanly, the ones a user actually types in, not the ones a developer thinks to test.&lt;/p&gt;

&lt;p&gt;Every money-handling calculator on the site now funnels through one rounding function instead of each one doing its own &lt;code&gt;.toFixed(2)&lt;/code&gt; inline. Partly for consistency, but mostly so this bug only had one place it could hide.&lt;/p&gt;

&lt;p&gt;If you're building anything that does arithmetic on money in JavaScript and displays the result, it's worth checking whether you have one rounding function or five slightly different ones scattered across the codebase. It's an easy thing to get right once, and an easy thing to get subtly wrong five separate times.&lt;/p&gt;

&lt;p&gt;Built with Astro, if anyone's curious about the stack. The site itself is at &lt;a href="https://paytimehub.com" rel="noopener noreferrer"&gt;paytimehub.com&lt;/a&gt; if you want to see it in action — specifically the &lt;a href="https://paytimehub.com/pay-raise-calculator/" rel="noopener noreferrer"&gt;pay raise calculator&lt;/a&gt;, where this first came up.&lt;/p&gt;

</description>
      <category>astro</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>ai</category>
    </item>
    <item>
      <title>🧭 React Router Crash Course (Beginner Friendly)</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Thu, 04 Dec 2025 08:29:45 +0000</pubDate>
      <link>https://dev.to/saurabh_sharma_7a9a61107d/react-router-crash-course-beginner-friendly-1bck</link>
      <guid>https://dev.to/saurabh_sharma_7a9a61107d/react-router-crash-course-beginner-friendly-1bck</guid>
      <description>&lt;p&gt;&lt;em&gt;Learn what routing is, why it matters in React, and how to set it up step-by-step — with a mini React demo project.&lt;/em&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  🧐 What Is Routing in React?
&lt;/h2&gt;

&lt;p&gt;So, what the heck is &lt;strong&gt;routing&lt;/strong&gt;?  &lt;/p&gt;

&lt;p&gt;In simple terms, &lt;strong&gt;routing controls what your app shows when a user navigates to different pages&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;That’s it! When you click on something like “About” or “Contact,” routing decides &lt;em&gt;which component&lt;/em&gt; gets displayed on the screen.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 How Traditional Routing Works
&lt;/h2&gt;

&lt;p&gt;Before SPAs (Single Page Applications), websites used normal HTML navigation with the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Go to About Page&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every time you clicked on that link, the browser &lt;strong&gt;reloaded the page&lt;/strong&gt; from scratch. That means your app reset, and the DOM (Document Object Model) re-rendered completely — not very efficient!  &lt;/p&gt;




&lt;h2&gt;
  
  
  ⚛️ React: The Power of Single Page Applications (SPA)
&lt;/h2&gt;

&lt;p&gt;React builds &lt;strong&gt;Single Page Applications&lt;/strong&gt;, where everything runs inside one main HTML file: &lt;code&gt;index.html&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;When navigation happens, React simply &lt;strong&gt;replaces parts of the UI dynamically&lt;/strong&gt;, rather than reloading the entire page.  &lt;/p&gt;

&lt;p&gt;But to make that navigation magic happen, React needs help — that’s where &lt;strong&gt;&lt;code&gt;react-router-dom&lt;/code&gt;&lt;/strong&gt; comes in.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Installing React Router
&lt;/h2&gt;

&lt;p&gt;React itself doesn’t handle routing, so you’ll need to install a library for it. The most popular one is &lt;strong&gt;&lt;code&gt;react-router-dom&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Use your package manager of choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🏗️ Step 1: Setup &lt;code&gt;BrowserRouter&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;After installing, wrap your whole app with &lt;code&gt;BrowserRouter&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
This enables React Router throughout your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// main.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-dom/client'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;BrowserRouter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-router-dom'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./App.jsx'&lt;/span&gt;

&lt;span class="nc"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'root'&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;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&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;That’s your basic setup! Without this step, your app won’t understand routes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🗺️ Step 2: Define Routes with &lt;code&gt;&amp;lt;Routes&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now it’s time to tell React what to show on each URL path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-router-dom'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./pages/Home'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;About&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./pages/About'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Contact&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./pages/Contact'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;NotFound&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./pages/NotFound'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/about"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;About&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/contact"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Contact&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="cm"&gt;/* Catch all unknown routes */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NotFound&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/&lt;/code&gt; → &lt;strong&gt;Home Page&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/about&lt;/code&gt; → &lt;strong&gt;About Page&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/contact&lt;/code&gt; → &lt;strong&gt;Contact Page&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;*&lt;/code&gt; → &lt;strong&gt;Not Found / 404 Page&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 Step 3: Create Navigation with &lt;code&gt;Link&lt;/code&gt; and &lt;code&gt;NavLink&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Instead of using normal &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tags, React gives us special components: &lt;code&gt;Link&lt;/code&gt; and &lt;code&gt;NavLink&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
These navigate between pages &lt;em&gt;without&lt;/em&gt; reloading the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Navbar.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NavLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-router-dom'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Navbar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nav&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/about"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;About&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NavLink&lt;/span&gt;
        &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/contact"&lt;/span&gt;
        &lt;span class="n"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;isActive&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="n"&gt;isActive&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'active'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Contact&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;NavLink&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;nav&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;Navbar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;code&gt;Link&lt;/code&gt;: Basic navigation (no reload).&lt;br&gt;&lt;br&gt;
✅ &lt;code&gt;NavLink&lt;/code&gt;: Same as &lt;code&gt;Link&lt;/code&gt;, but automatically adds an “active” class to the current route — perfect for styling active menu items.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 Step 4: Nested Routes and &lt;code&gt;&amp;lt;Outlet /&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes you’ll want routes &lt;em&gt;inside routes&lt;/em&gt;, like for a dashboard that contains multiple sections (e.g., profile, settings).  &lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;nested routes&lt;/strong&gt; come in — and the &lt;code&gt;&amp;lt;Outlet /&amp;gt;&lt;/code&gt; component helps render them in the right place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/dashboard"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"profile"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Profile&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"settings"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Settings&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside &lt;code&gt;Dashboard.jsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Dashboard.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Outlet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-router-dom'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Child routes will render here */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Outlet&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;Dashboard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when visiting &lt;code&gt;/dashboard/profile&lt;/code&gt;, React automatically renders the &lt;strong&gt;Profile&lt;/strong&gt; component inside the &lt;strong&gt;Dashboard&lt;/strong&gt; layout!&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Mini React Demo Project: "My First Routed App"
&lt;/h2&gt;

&lt;p&gt;Let’s put it all together into a working mini project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File Structure:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
  ├── main.jsx
  ├── App.jsx
  ├── components/
  │     └── Navbar.jsx
  ├── pages/
  │     ├── Home.jsx
  │     ├── About.jsx
  │     ├── Contact.jsx
  │     └── NotFound.jsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// pages/Home.jsx&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nc"&gt;My&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;Home&lt;/span&gt;

&lt;span class="c1"&gt;// pages/About.jsx&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;About&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;About&lt;/span&gt; &lt;span class="nc"&gt;This&lt;/span&gt; &lt;span class="nc"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;About&lt;/span&gt;

&lt;span class="c1"&gt;// pages/Contact.jsx&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Contact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Contact&lt;/span&gt; &lt;span class="nc"&gt;Me&lt;/span&gt; &lt;span class="nc"&gt;Anytime&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;Contact&lt;/span&gt;

&lt;span class="c1"&gt;// pages/NotFound.jsx&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt; — &lt;span class="nc"&gt;Page&lt;/span&gt; &lt;span class="nc"&gt;Not&lt;/span&gt; &lt;span class="nc"&gt;Found&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nc"&gt;NotFound&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add the Navbar:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Navbar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./components/Navbar'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/about"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;About&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/contact"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Contact&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NotFound&lt;/span&gt; &lt;span class="o"&gt;/&amp;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="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you’ve got a complete, simple React app with modern routing — no page reloads, smooth navigation, and clean URLs.  &lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ Bonus: Things to Explore Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactrouter.com/en/main" rel="noopener noreferrer"&gt;React Router Docs&lt;/a&gt; — Learn about advanced features like &lt;code&gt;useNavigate&lt;/code&gt;, loaders, lazy loading, and route transitions.
&lt;/li&gt;
&lt;li&gt;Try adding a &lt;strong&gt;404 redirect&lt;/strong&gt; or a &lt;strong&gt;Protected Route&lt;/strong&gt; for authenticated sections.
&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;NavLink&lt;/code&gt; styling to highlight the active page.
&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;You just learned how to set up &lt;strong&gt;React Router&lt;/strong&gt; from scratch — including how to install it, define routes, use navigation components, and manage nested routes cleanly.  &lt;/p&gt;

&lt;p&gt;Now, whenever you start a new React project, you’ll know exactly how to make it multi-page while keeping it fast and smooth.&lt;/p&gt;

&lt;p&gt;Keep building! 💪  &lt;/p&gt;




</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
