<?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: Kai Mercer</title>
    <description>The latest articles on DEV Community by Kai Mercer (@mercerk17).</description>
    <link>https://dev.to/mercerk17</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%2F4175326%2F59d344aa-a402-44a1-8d3f-c99a392fe74e.png</url>
      <title>DEV Community: Kai Mercer</title>
      <link>https://dev.to/mercerk17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mercerk17"/>
    <language>en</language>
    <item>
      <title>Show DEV: a single-file WCAG contrast checker, generated in one shot and verified by execution</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Sun, 08 Nov 2026 23:19:47 +0000</pubDate>
      <link>https://dev.to/mercerk17/show-dev-a-single-file-wcag-contrast-checker-generated-in-one-shot-and-verified-by-execution-3147</link>
      <guid>https://dev.to/mercerk17/show-dev-a-single-file-wcag-contrast-checker-generated-in-one-shot-and-verified-by-execution-3147</guid>
      <description>&lt;p&gt;I do marketing for HelloAI (&lt;a href="https://tryhello.app" rel="noopener noreferrer"&gt;https://tryhello.app&lt;/a&gt;), the app in this test. Insider test, not a neutral review. My earlier posts here were documents it wrote; this time I asked for a runnable thing: a WCAG color contrast checker as one self-contained HTML file. It produced the whole file in a single response. Below is that exact file, unchanged, plus everything I did to check it before publishing. Repairs from me: zero.&lt;/p&gt;

&lt;p&gt;I picked a contrast checker deliberately: the correct answer is exact math, so a generated one can be verified instead of trusted.&lt;/p&gt;

&lt;h2&gt;
  
  
  The prompt
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Build me a single-file HTML page (inline CSS and JS, no external libraries) that checks WCAG color contrast. Two hex color inputs (foreground and background), a live text preview in those colors, the contrast ratio rounded to 2 decimals, and pass/fail badges for AA normal text, AA large text, AAA normal, and AAA large. Add four preset color pairs I can click to load. Keep it compact, under 200 lines. Give me the complete file as code I can save and open.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The file
&lt;/h2&gt;

&lt;p&gt;Save as &lt;code&gt;contrast.html&lt;/code&gt; and open it in a browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width,initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;WCAG Contrast Checker&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.5&lt;/span&gt; &lt;span class="n"&gt;system-ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#17202a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#f2f4f7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;540px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;22px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;#d9dee5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.35rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.hint&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#586575&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;.9rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.inputs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1fr&lt;/span&gt; &lt;span class="m"&gt;1fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;label&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;650&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;#b8c1cc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.preview&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;92px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;#d9dee5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.preview&lt;/span&gt; &lt;span class="nt"&gt;strong&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.ratio&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.08rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.badges&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1fr&lt;/span&gt; &lt;span class="m"&gt;1fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.badge&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#f2f4f7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.pass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#146c3a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.fail&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#a12622&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;h2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nc"&gt;.presets&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7px&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;#b8c1cc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;#edf1f5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;420px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;.inputs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1fr&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="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;WCAG Contrast Checker&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hint"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter 3- or 6-digit hex colors, with or without #.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"inputs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"fg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Foreground
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"fg"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"#1A1A1A"&lt;/span&gt; &lt;span class="na"&gt;autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"off"&lt;/span&gt; &lt;span class="na"&gt;spellcheck=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"bg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Background
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"bg"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"#FFFFFF"&lt;/span&gt; &lt;span class="na"&gt;autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"off"&lt;/span&gt; &lt;span class="na"&gt;spellcheck=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"preview"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"preview"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;strong&amp;gt;&lt;/span&gt;Live text preview&lt;span class="nt"&gt;&amp;lt;/strong&amp;gt;&lt;/span&gt;
    Normal text sample · Large text sample
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"ratio"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ratio"&lt;/span&gt; &lt;span class="na"&gt;aria-live=&lt;/span&gt;&lt;span class="s"&gt;"polite"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"results"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"badges"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Presets&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"presets"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"presets"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#fg&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;bg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#bg&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;preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#preview&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;ratio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#ratio&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;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#results&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;pairs&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Black on white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#000000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#FFFFFF&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;White on navy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#FFFFFF&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#1D3557&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yellow on black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#FFFF00&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#000000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Gray on white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#777777&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#FFFFFF&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^#/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;0-9a-f&lt;/span&gt;&lt;span class="se"&gt;]{3}&lt;/span&gt;&lt;span class="sr"&gt;$/i&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="nx"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;0-9a-f&lt;/span&gt;&lt;span class="se"&gt;]{6}&lt;/span&gt;&lt;span class="sr"&gt;$/i&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="nx"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&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="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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hex&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rgb&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;channels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&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;v&lt;/span&gt; &lt;span class="o"&gt;/=&lt;/span&gt; &lt;span class="mi"&gt;255&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;v&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;0.04045&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;12.92&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.055&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.055&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mf"&gt;2.4&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="mf"&gt;0.2126&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.7152&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.0722&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;channels&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;update&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;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aria-invalid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aria-invalid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter valid hex colors to see the preview.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;ratio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please enter valid 3- or 6-digit hex colors.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foreground&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;background&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;strong&amp;gt;Live text preview&amp;lt;/strong&amp;gt;Normal text sample · Large text sample&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foreground&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;background&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;l1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;l2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&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;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;l1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;l2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.05&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;l1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;l2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;ratio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Contrast ratio: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="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="s2"&gt;:1`&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;checks&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AA normal text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.5&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="s2"&gt;AA large text&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AAA normal text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&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="s2"&gt;AAA large text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(([&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;threshold&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;passes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;div class="badge"&amp;gt;&amp;lt;span&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/span&amp;gt;&amp;lt;span class="&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;passes&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pass&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fail&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;passes&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PASS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;FAIL&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="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;fg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bg&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;input&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;pairs&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;foreground&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;background&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;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="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;fg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foreground&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;background&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="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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;);&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="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How I checked it
&lt;/h2&gt;

&lt;p&gt;I did not want to publish math I had not run:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I pulled its &lt;code&gt;parseHex&lt;/code&gt; and &lt;code&gt;luminance&lt;/code&gt; functions out verbatim and ran 12 color pairs through them, and through a second implementation I wrote myself from the WCAG 2.x formula. All 12 matched, including the boundary pair that matters most: &lt;code&gt;#777777&lt;/code&gt; on white (4.48, fails AA normal) versus &lt;code&gt;#767676&lt;/code&gt; on white (4.54, passes AA normal). A checker that gets the 4.5 line wrong is worse than no checker.&lt;/li&gt;
&lt;li&gt;Three-digit expansion and missing-&lt;code&gt;#&lt;/code&gt; inputs behaved (&lt;code&gt;#777&lt;/code&gt; equals &lt;code&gt;#777777&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Six invalid inputs (a named color, a 4-digit value, junk, an empty field) were all rejected with a clear message. No crash, no stale badges.&lt;/li&gt;
&lt;li&gt;I loaded the actual file in a browser and clicked through it: presets load, the badges show the exact expected FAIL/PASS pattern on the boundary gray, and invalid input clears the results.&lt;/li&gt;
&lt;li&gt;Cross-check against an outside oracle: WebAIM's contrast checker API on 5 of the pairs. The pass/fail calls agreed on all 5. The displayed ratio can differ in the last digit (this shows 4.48 where WebAIM shows 4.47 on &lt;code&gt;#777777&lt;/code&gt;) because this tool rounds and WebAIM truncates. The decisions are unaffected: both compare the unrounded value against the threshold.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Honest limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Hex input only. No named colors, &lt;code&gt;rgb()&lt;/code&gt;, &lt;code&gt;hsl()&lt;/code&gt;, or transparency. Named colors are rejected, not resolved.&lt;/li&gt;
&lt;li&gt;The preview text says "Normal text sample · Large text sample" but renders both at the same size. Cosmetic, but split them if you ship this.&lt;/li&gt;
&lt;li&gt;It implements the WCAG 2.x luminance math, which is what current conformance targets use (2.1 and 2.2 carry the same 4.5 / 3 / 7 / 4.5 thresholds; I checked both specs). APCA, the candidate approach for WCAG 3, is different math and this is not it.&lt;/li&gt;
&lt;li&gt;A passing ratio is a floor, not a readability guarantee. Font, weight, size and context still matter.&lt;/li&gt;
&lt;li&gt;One prompt, one run. The file above is exactly what it produced this time; the next prompt could produce something worse. Verify before you ship, whoever wrote the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The app: &lt;a href="https://tryhello.app" rel="noopener noreferrer"&gt;https://tryhello.app&lt;/a&gt; (free plan, no card)&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>a11y</category>
      <category>ai</category>
    </item>
    <item>
      <title>I asked a chat app for a CSS specificity cheat sheet, then checked every row against MDN</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Sun, 08 Nov 2026 23:10:33 +0000</pubDate>
      <link>https://dev.to/mercerk17/i-asked-a-chat-app-for-a-css-specificity-cheat-sheet-then-checked-every-row-against-mdn-198a</link>
      <guid>https://dev.to/mercerk17/i-asked-a-chat-app-for-a-css-specificity-cheat-sheet-then-checked-every-row-against-mdn-198a</guid>
      <description>&lt;p&gt;I do marketing for HelloAI (&lt;a href="https://tryhello.app" rel="noopener noreferrer"&gt;https://tryhello.app&lt;/a&gt;), the app in this test. Insider test, not a neutral review. Short version: I asked for a CSS specificity cheat sheet, it produced an editable document, and every claim in it survived a check against MDN. Here is exactly what it gave me, and the check.&lt;/p&gt;

&lt;h2&gt;
  
  
  The prompt
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Make me a CSS specificity cheat sheet with about 10 worked examples. For each example selector, show its specificity as a-b-c (ID, class, type) and one line on why. Include at least: a plain element selector, a class, an ID, an attribute selector, a pseudo-class like :hover, a :not() with an argument, a descendant selector, a combined selector like ul#nav li.active, an inline style case, and an !important case. End with a short "who wins" section for three conflicts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The output
&lt;/h2&gt;

&lt;p&gt;It opened an editable document (they call it Canvas) with this table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Selector or case&lt;/th&gt;
&lt;th&gt;Specificity&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;p&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-0-1&lt;/td&gt;
&lt;td&gt;One type selector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.note&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-1-0&lt;/td&gt;
&lt;td&gt;One class selector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;#header&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1-0-0&lt;/td&gt;
&lt;td&gt;One ID selector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[type="text"]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-1-0&lt;/td&gt;
&lt;td&gt;Attribute selectors count like classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;a:hover&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-1-1&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;:hover&lt;/code&gt; counts like a class, and &lt;code&gt;a&lt;/code&gt; is a type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;p:not(.muted)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-1-1&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;:not()&lt;/code&gt; itself adds nothing; its &lt;code&gt;.muted&lt;/code&gt; argument counts, along with &lt;code&gt;p&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;main p&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-0-2&lt;/td&gt;
&lt;td&gt;The descendant combinator adds nothing; the two type selectors count&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ul#nav li.active&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1-1-2&lt;/td&gt;
&lt;td&gt;One ID, one class, and two type selectors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;button.primary:hover&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0-2-1&lt;/td&gt;
&lt;td&gt;Two class-level selectors plus one type selector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inline &lt;code&gt;style="color: red"&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;outside the a-b-c score&lt;/td&gt;
&lt;td&gt;Inline styles outrank normal author stylesheet rules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.notice { color: red !important; }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;selector is 0-1-0, plus important&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;!important&lt;/code&gt; is not specificity; it changes cascade priority and beats normal declarations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Then three "who wins" conflicts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;p { color: blue }&lt;/code&gt; vs &lt;code&gt;.note { color: green }&lt;/code&gt; - &lt;code&gt;.note&lt;/code&gt; wins (0-1-0 beats 0-0-1)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;#nav li&lt;/code&gt; vs &lt;code&gt;ul#nav li.active&lt;/code&gt; - &lt;code&gt;ul#nav li.active&lt;/code&gt; wins (1-1-2 beats 1-0-1)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;p { color: blue !important }&lt;/code&gt; vs &lt;code&gt;#main p { color: red }&lt;/code&gt; - the &lt;code&gt;!important&lt;/code&gt; declaration wins despite the lower selector score&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The MDN check
&lt;/h2&gt;

&lt;p&gt;I verified each row against MDN's specificity page:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The column rules match: an ID column, a class column (classes, attribute selectors, pseudo-classes), and a type column (elements and pseudo-elements).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[type="text"]&lt;/code&gt; at 0-1-0: MDN uses &lt;code&gt;[type="password"]&lt;/code&gt; as its own 0-1-0 example.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a:hover&lt;/code&gt; at 0-1-1: same shape as MDN's &lt;code&gt;input:focus&lt;/code&gt; example.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;:not()&lt;/code&gt; row: &lt;code&gt;:not()&lt;/code&gt; itself adds nothing; only its argument counts. Correct here.&lt;/li&gt;
&lt;li&gt;The descendant combinator adds nothing. Correct.&lt;/li&gt;
&lt;li&gt;The tie-break ("if specificity ties, the later rule wins, assuming the same cascade origin and importance") matches.&lt;/li&gt;
&lt;li&gt;On inline styles, MDN also describes them as a hypothetical 1-0-0-0 when it extends the notation. The sheet kept them outside the a-b-c score instead and said why. Different presentation, same rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wrong rows in this run: zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest limits
&lt;/h2&gt;

&lt;p&gt;One run of one prompt, free plan, about 300 words of output. It says nothing about the next prompt or a harder one. The document is editable, which matters more than it sounds: I could have fixed a wrong row in place instead of re-prompting. This time there was nothing to fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I check generated references at all
&lt;/h2&gt;

&lt;p&gt;Specificity is a topic where an almost-right cheat sheet quietly costs you an afternoon. Whatever tool you use, verify a reference before you trust it. This one happened to survive.&lt;/p&gt;

&lt;p&gt;The app: &lt;a href="https://tryhello.app" rel="noopener noreferrer"&gt;https://tryhello.app&lt;/a&gt; (free plan, no card)&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>ai</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Same incident notes, two prompts: one draft kept my mistakes, the other flagged them</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Thu, 05 Nov 2026 23:06:27 +0000</pubDate>
      <link>https://dev.to/mercerk17/same-incident-notes-two-prompts-one-draft-kept-my-mistakes-the-other-flagged-them-1b0d</link>
      <guid>https://dev.to/mercerk17/same-incident-notes-two-prompts-one-draft-kept-my-mistakes-the-other-flagged-them-1b0d</guid>
      <description>&lt;p&gt;Quick note first: I do marketing for HelloAI (tryhello.app), and this is a test I ran on its free plan. Everything below is fictional incident data I wrote, so treat the output as a draft that needs a human review, not a real postmortem.&lt;/p&gt;

&lt;p&gt;Writing a postmortem from messy notes is a chore most teams know. So I gave a chat app a set of rough notes and asked for a blameless postmortem. I ran it twice, with two different prompts, and I'll show both in order.&lt;/p&gt;

&lt;h2&gt;
  
  
  The notes (fictional)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Tue 14:02 deploy of v2.3 went out. 14:10 error rate on checkout jumped to 12%. 14:18 on-call paged (alert fired 8 min late because threshold was set to 15%). 14:31 rolled back, errors dropped by 14:35. Cause: new config flag defaulted to off in prod but on in staging, so a null payment-provider timeout was used. 37 minutes of impact, about 210 failed checkouts. Fixes: add prod/staging config diff check to CI, lower alert threshold to 5%, add a canary step.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I wrote these quickly. Looking at them afterwards, two things don't hold up: 14:02 to 14:35 is 33 minutes (and 14:10 to 14:35 is 25), not 37, and a 12% error rate is below a 15% alert threshold, so "fired late because the threshold was 15%" doesn't explain much.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run 1: "just write it"
&lt;/h2&gt;

&lt;p&gt;Prompt: "Turn these messy notes into a blameless incident postmortem I can paste into a doc." plus the notes, plus a list of sections (summary, impact, timeline table, root cause, what went well, what went badly, action items with owners TBD) and "Do not invent any facts beyond the notes."&lt;/p&gt;

&lt;p&gt;In about 15 seconds I got an editable document, around 260 words, with every section I asked for. Times, percentages, the 210 count and the three fixes were carried over correctly, and it added no new facts. Owners were left as TBD.&lt;/p&gt;

&lt;p&gt;But it repeated "37 minutes" without comment, and it wrote that the 15% threshold meant the alert fired late after a 12% jump, which glosses over the inconsistency above. I hadn't asked it to check, so that is a fair result, but it's the kind of thing a draft can quietly hide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run 2: "check the notes first"
&lt;/h2&gt;

&lt;p&gt;New chat, same notes, different prompt: "Before writing anything, check these incident notes for inconsistencies or unsupported numbers and list them. Then write a blameless postmortem draft that does not paper over them." (plus "Owners TBD. Do not invent facts.")&lt;/p&gt;

&lt;p&gt;It listed these, and the first two are the ones I found myself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The 37 minutes doesn't match any interval in the notes: 14:02 to 14:35 is 33, 14:10 to 14:35 is 25.&lt;/li&gt;
&lt;li&gt;A 12% error rate is below a 15% threshold, and the notes don't say what the threshold measured or how the alert fired.&lt;/li&gt;
&lt;li&gt;"Lower alert threshold to 5%" doesn't name a metric or a duration condition.&lt;/li&gt;
&lt;li&gt;"About 210" failed checkouts has no stated basis.&lt;/li&gt;
&lt;li&gt;It isn't explained how the flag state led to a null payment-provider timeout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The draft that followed carried these as open questions ("What interval does the reported 37-minute impact duration cover?") instead of smoothing them over.&lt;/p&gt;

&lt;p&gt;One thing I'd flag: in the action items it changed my note "lower alert threshold to 5%" into "review and adjust the alert threshold, including the metric and any duration condition". That's reasonable given its own concern, but it is a change to a fix I had stated, so you'd want to restore the original wording if that was the decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I take from it
&lt;/h2&gt;

&lt;p&gt;Same notes, same free plan: the plain "write it" prompt gave a clean draft that kept my mistakes, and the "check first" prompt surfaced them and wrote around them. That is two runs, one set of notes I wrote, so it says nothing about how reliable this is in general. I'd still read any generated postmortem against the real timeline before sharing it.&lt;/p&gt;

&lt;p&gt;If you try something similar, ask for the inconsistency check explicitly and keep your original notes next to the draft.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>productivity</category>
      <category>ai</category>
    </item>
    <item>
      <title>A 10-minute SQL window functions lesson from a chat app, and I re-ran its queries</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Wed, 04 Nov 2026 11:09:26 +0000</pubDate>
      <link>https://dev.to/mercerk17/a-10-minute-sql-window-functions-lesson-from-a-chat-app-and-i-re-ran-its-queries-4di5</link>
      <guid>https://dev.to/mercerk17/a-10-minute-sql-window-functions-lesson-from-a-chat-app-and-i-re-ran-its-queries-4di5</guid>
      <description>&lt;p&gt;Quick note first: I do marketing for HelloAI (tryhello.app), and this is a test I ran on its free plan. I'll show the prompt, what it gave me, and how I checked it.&lt;/p&gt;

&lt;p&gt;The prompt, word for word:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Teach me SQL window functions in 10 minutes. Use this table: sales(rep, month, amount) with rows (Ana,Jan,100),(Ana,Feb,150),(Ana,Mar,120),(Ben,Jan,90),(Ben,Feb,200),(Ben,Mar,110). Show a running total per rep and a rank of reps by amount within each month, give the exact result tables, then 3 practice questions with answers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It came back in about ten seconds as an editable document, roughly 430 words. Here is the useful part.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea it opened with
&lt;/h2&gt;

&lt;p&gt;A window function calculates a value over a set of related rows while keeping each original row. Unlike &lt;code&gt;GROUP BY&lt;/code&gt;, it doesn't collapse rows. &lt;code&gt;PARTITION BY&lt;/code&gt; splits rows into groups, &lt;code&gt;ORDER BY&lt;/code&gt; sets the order inside each group.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running total per rep
&lt;/h2&gt;

&lt;p&gt;Month names are text, so it spelled out the calendar order and the frame instead of leaning on defaults:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;month&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="k"&gt;SUM&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="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;rep&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;CASE&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Jan'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Feb'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Mar'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;END&lt;/span&gt;
    &lt;span class="k"&gt;ROWS&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="n"&gt;UNBOUNDED&lt;/span&gt; &lt;span class="k"&gt;PRECEDING&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;CURRENT&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;running_total&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;CASE&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Jan'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Feb'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Mar'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;rep&lt;/th&gt;
&lt;th&gt;month&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;th&gt;running_total&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Jan&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Feb&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;250&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Mar&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;370&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Jan&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Feb&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;290&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Mar&lt;/td&gt;
&lt;td&gt;110&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Rank reps within each month
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;rep&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;month&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="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;month_rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;CASE&lt;/span&gt; &lt;span class="k"&gt;month&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Jan'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Feb'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="s1"&gt;'Mar'&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;month_rank&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;rep&lt;/th&gt;
&lt;th&gt;month&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;th&gt;month_rank&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Jan&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Jan&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Feb&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Feb&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ana&lt;/td&gt;
&lt;td&gt;Mar&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;Mar&lt;/td&gt;
&lt;td&gt;110&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It also noted that with this data there are no ties, so &lt;code&gt;RANK()&lt;/code&gt;, &lt;code&gt;ROW_NUMBER()&lt;/code&gt; and &lt;code&gt;DENSE_RANK()&lt;/code&gt; agree here, and that &lt;code&gt;RANK()&lt;/code&gt; leaves gaps after a tie while &lt;code&gt;DENSE_RANK()&lt;/code&gt; doesn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice questions it wrote
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is Ana's running total in March? (370)&lt;/li&gt;
&lt;li&gt;What is Ben's rank in February? (1, his 200 is the highest that month)&lt;/li&gt;
&lt;li&gt;What does &lt;code&gt;PARTITION BY rep&lt;/code&gt; do in the running-total query? (Each rep's rows get their own window, so the total restarts for Ben.)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How I checked it
&lt;/h2&gt;

&lt;p&gt;I loaded the same six rows into SQLite 3.37.2 and ran both queries exactly as written. Both result tables matched what it showed, row for row. That covers this sample and these two queries, nothing more. The three practice answers also hold against that data.&lt;/p&gt;

&lt;p&gt;Small nits: the document header and footer disagreed on the word count (523 vs 427), and the last sentence of question 3's answer reads a bit awkwardly. Nothing that changed the SQL or the numbers.&lt;/p&gt;

&lt;p&gt;What I liked: it gave me runnable queries, exact tables and practice questions in one pass, and I could edit the document afterwards. It also offered to turn the same topic into a guided tutor lesson, which I haven't tried.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>beginners</category>
      <category>database</category>
      <category>ai</category>
    </item>
    <item>
      <title>I asked a chat app for a caching diagram. It drew the 304 as a 204.</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Tue, 03 Nov 2026 23:08:43 +0000</pubDate>
      <link>https://dev.to/mercerk17/i-asked-a-chat-app-for-a-caching-diagram-it-drew-the-304-as-a-204-iec</link>
      <guid>https://dev.to/mercerk17/i-asked-a-chat-app-for-a-caching-diagram-it-drew-the-304-as-a-204-iec</guid>
      <description>&lt;p&gt;Quick note first: I do marketing for HelloAI (tryhello.app), and this is a test I ran on its free plan. I'll show the prompt, the picture it gave me, and where it slipped.&lt;/p&gt;

&lt;p&gt;The prompt, word for word:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make an image: a simple sequence diagram of HTTP conditional caching. Two lanes only: Browser and Server. Four numbered arrows with SHORT labels: 1 GET /logo.png, 2 200 OK + ETag, 3 GET with If-None-Match, 4 304 Not Modified (no body). Large legible text, minimal words, flat style.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It took about a minute and returned one image (1536x1024):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff05n1st15tt1txkd3w0p.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%2Ff05n1st15tt1txkd3w0p.png" alt="Sequence diagram with Browser and Server lanes and four arrows: GET /logo.png, 200 OK with ETag, GET with If-None-Match, and a response labelled 204 Not Modified, no body" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is right
&lt;/h2&gt;

&lt;p&gt;The flow is the standard revalidation round trip. The browser asks for a file, the server answers 200 with an ETag, the browser asks again with &lt;code&gt;If-None-Match&lt;/code&gt;, and the server answers 304 with no body. MDN's 304 page describes exactly this: it is sent for a conditional GET or HEAD with &lt;code&gt;If-None-Match&lt;/code&gt; or &lt;code&gt;If-Modified-Since&lt;/code&gt; when the condition is false, and it must not contain a body. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304" rel="noopener noreferrer"&gt;MDN 304&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The arrow directions are right, the lanes are right, and the text is large and readable, which was not a given. A different prompt I tried yesterday (a water cycle infographic) came back with garbled labels in the part I could see, so I asked for fewer words this time on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  What slipped
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Step 2 reads "2-200 Ok" instead of "2  200 OK". The number and the code ran together with a hyphen.&lt;/li&gt;
&lt;li&gt;Step 4 lost its brackets and reads "204 Not Modified Ino body". Also look closely: it says &lt;strong&gt;204&lt;/strong&gt;, not &lt;strong&gt;304&lt;/strong&gt;. I asked for 304. That is a real error, and a nasty one, because 204 No Content is a different status (success, nothing to return) and a reader skimming the picture would learn the wrong code.&lt;/li&gt;
&lt;li&gt;Step 3 does not show what goes in &lt;code&gt;If-None-Match&lt;/code&gt; (the ETag value from step 2). I did not ask for that, so I will not count it against the output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I only caught the 204 because I compared the picture with my own prompt. If you generate diagrams like this, check every label.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I am posting it anyway
&lt;/h2&gt;

&lt;p&gt;A diagram you can see and fix is a better starting point than a paragraph, and the clean layout is the part that worked. But the one wrong status code in the middle is exactly the kind of error a pretty picture hides. One prompt, one run, nothing cherry-picked: this is the only image I made for this post.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>http</category>
      <category>api</category>
      <category>ai</category>
    </item>
    <item>
      <title>I asked a chat app for an HTTP status code cheat sheet, then checked all 14 rows against MDN</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Mon, 02 Nov 2026 23:12:30 +0000</pubDate>
      <link>https://dev.to/mercerk17/i-asked-a-chat-app-for-an-http-status-code-cheat-sheet-then-checked-all-14-rows-against-mdn-232i</link>
      <guid>https://dev.to/mercerk17/i-asked-a-chat-app-for-an-http-status-code-cheat-sheet-then-checked-all-14-rows-against-mdn-232i</guid>
      <description>&lt;p&gt;Disclosure up front: I do marketing for HelloAI (tryhello.app), a chat app that can hand back editable documents and files. So this is a vendor-adjacent test, and I am showing the checking so you can judge it yourself.&lt;/p&gt;

&lt;p&gt;I used a free HelloAI account (Free plan) and gave it one practical prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Write me a one-page cheat sheet document I can keep: a table of 14 common HTTP status codes (200, 201, 204, 301, 302, 304, 400, 401, 403, 404, 409, 429, 500, 503) with columns: code, name, when an API should return it, and the most common misuse. Keep it tight.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It came back in about a minute as an editable document (it opens in a side editor, 443 words per the chat card, with a real table, not pasted text) instead of a chat reply. Then I read every row against the MDN pages for each code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What matched MDN
&lt;/h2&gt;

&lt;p&gt;All 14 rows were consistent with what MDN says. A few that are easy to get wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;204&lt;/strong&gt;: the sheet's misuse is "sending a response body". MDN says a 204 must not include content. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/204" rel="noopener noreferrer"&gt;MDN 204&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;304&lt;/strong&gt;: the sheet's misuse is returning it without a conditional request, or with a body. MDN: it answers a conditional GET/HEAD and must not contain a body. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304" rel="noopener noreferrer"&gt;MDN 304&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;401 vs 403&lt;/strong&gt;: the sheet says use 403 for an authenticated user without permission, and 401 for missing or invalid credentials. That matches MDN's description of both. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401" rel="noopener noreferrer"&gt;MDN 401&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403" rel="noopener noreferrer"&gt;MDN 403&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404&lt;/strong&gt;: "or the API chooses not to reveal it" matches MDN's note that servers may send 404 instead of 403 to hide a resource. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403" rel="noopener noreferrer"&gt;MDN 403&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;409&lt;/strong&gt;: conflict with the current state of the target resource. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/409" rel="noopener noreferrer"&gt;MDN 409&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;429&lt;/strong&gt; and &lt;strong&gt;503&lt;/strong&gt;: the sheet says to include retry guidance for 429 and that 503 is for temporary conditions. MDN agrees, and mentions the &lt;code&gt;Retry-After&lt;/code&gt; header for both. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/429" rel="noopener noreferrer"&gt;MDN 429&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/503" rel="noopener noreferrer"&gt;MDN 503&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I would add (gaps, not errors)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;401&lt;/strong&gt; has no mention that the response is sent with a &lt;code&gt;WWW-Authenticate&lt;/code&gt; header. MDN says it is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;301 and 302&lt;/strong&gt; do not mention 308 and 307. MDN notes that user agents may switch POST to GET after a 301 or 302, and that 308 and 307 forbid changing the method. The sheet hints at this in the 302 row but does not name the fix.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404&lt;/strong&gt; does not mention 410 for resources that are permanently gone. MDN recommends it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;503&lt;/strong&gt; does not name &lt;code&gt;Retry-After&lt;/code&gt; in the row text.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How far this goes
&lt;/h2&gt;

&lt;p&gt;This is one prompt, one run, and I checked it against MDN, not against RFC 9110 line by line. I did not test whether the document exports cleanly to other formats. A table of well-known facts is also the easy case for any chat model, so the useful part for me was the format: a document with a table I could edit, rather than a wall of chat text. If you try it, run your own prompt and check it.&lt;/p&gt;

&lt;p&gt;If you want to try the same prompt, HelloAI has a free plan (image generation is limited to 2 a day on it).&lt;/p&gt;

</description>
      <category>http</category>
      <category>api</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
    <item>
      <title>structuredClone vs JSON.parse(JSON.stringify()): what each does to a Date, a Map and a class</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Sun, 01 Nov 2026 23:06:50 +0000</pubDate>
      <link>https://dev.to/mercerk17/structuredclone-vs-jsonparsejsonstringify-what-each-does-to-a-date-a-map-and-a-class-4oo1</link>
      <guid>https://dev.to/mercerk17/structuredclone-vs-jsonparsejsonstringify-what-each-does-to-a-date-a-map-and-a-class-4oo1</guid>
      <description>&lt;p&gt;&lt;code&gt;JSON.parse(JSON.stringify(x))&lt;/code&gt; and &lt;code&gt;structuredClone(x)&lt;/code&gt; are both used to deep copy an object. They do not copy the same things. I ran both on one object in Node v22.23.4 and wrote down the differences.&lt;/p&gt;

&lt;h2&gt;
  
  
  One object, two copies
&lt;/h2&gt;

&lt;p&gt;Test object: a Date, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;, a Map, a Set, a RegExp, &lt;code&gt;-0&lt;/code&gt;, and an array with a hole (&lt;code&gt;[1, , 3]&lt;/code&gt;).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;After JSON round trip&lt;/th&gt;
&lt;th&gt;After structuredClone&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new Date(0)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the string &lt;code&gt;'1970-01-01T00:00:00.000Z'&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;a Date&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;undefined&lt;/code&gt; property&lt;/td&gt;
&lt;td&gt;key is gone&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;undefined&lt;/code&gt;, key kept&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new Map([[1, 2]])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a Map with 1 =&amp;gt; 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new Set([1])&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a Set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/a/gi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/a/gi&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[1, , 3]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[1, null, 3]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[1, &amp;lt;1 empty item&amp;gt;, 3]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;10n&lt;/code&gt; (BigInt)&lt;/td&gt;
&lt;td&gt;throws &lt;code&gt;TypeError&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10n&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So the JSON route silently turns a Map into &lt;code&gt;{}&lt;/code&gt; and a Date into a string. No error, wrong data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where structuredClone throws
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nf"&gt;f&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;// DataCloneError: f(){} could not be cloned.&lt;/span&gt;
&lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x&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;// DataCloneError: Symbol(x) could not be cloned.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A function or a symbol value makes it throw. JSON just drops those keys. If your object has a callback on it, &lt;code&gt;structuredClone&lt;/code&gt; fails loudly and JSON hides it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classes lose their prototype
&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;class&lt;/span&gt; &lt;span class="nc"&gt;P&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&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="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&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;P&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;// { a: 1 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The copy is a plain object. Methods and getters from the class are gone. JSON does the same, so neither route gives you back an instance. If you need one, rebuild it from the plain data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared references and cycles
&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;a&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="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two properties still point at the same array in the copy. After a JSON round trip they are two separate arrays (&lt;code&gt;c.x === c.y&lt;/code&gt; was &lt;code&gt;false&lt;/code&gt;). A circular object (&lt;code&gt;o.self = o&lt;/code&gt;) clones fine with &lt;code&gt;structuredClone&lt;/code&gt; and keeps &lt;code&gt;c.self === c&lt;/code&gt;. &lt;code&gt;JSON.stringify&lt;/code&gt; throws a &lt;code&gt;TypeError&lt;/code&gt; on a cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getters become plain values
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;structuredClone({ get g() { return 5 } })&lt;/code&gt; gave a property with &lt;code&gt;value: 5&lt;/code&gt; that is writable, enumerable and configurable. The getter ran once and its result was copied.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I did not test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Behavior in browsers. All of the above is Node v22.23.4 only.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lastIndex&lt;/code&gt; on a RegExp, DOM nodes, and the full list of supported types. For those, MDN's "Structured clone algorithm" page says functions and DOM nodes throw &lt;code&gt;DataCloneError&lt;/code&gt;, &lt;code&gt;lastIndex&lt;/code&gt; is not preserved, property descriptors, setters and getters are not duplicated, and the prototype chain is not walked.&lt;/li&gt;
&lt;li&gt;Performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which one to use
&lt;/h2&gt;

&lt;p&gt;If the data has Dates, Maps, Sets, BigInts, &lt;code&gt;NaN&lt;/code&gt; or shared references, use &lt;code&gt;structuredClone&lt;/code&gt;. If you need a JSON string to send or store, JSON is the right tool, but expect the table above. If the object has functions or class instances, neither route is a clean copy, so write the copy yourself.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why sort() puts 100 before 2, and Eclair after zebra</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Sat, 31 Oct 2026 23:05:38 +0000</pubDate>
      <link>https://dev.to/mercerk17/why-sort-puts-100-before-2-and-eclair-after-zebra-4i3k</link>
      <guid>https://dev.to/mercerk17/why-sort-puts-100-before-2-and-eclair-after-zebra-4i3k</guid>
      <description>&lt;p&gt;&lt;code&gt;[10, 9, 1, 100, 25, 2].sort()&lt;/code&gt; does not give you 1, 2, 9, 10, 25, 100. I ran the usual ways to sort numbers and names in Node v22.23.4 (V8) and wrote down what each one does, so you can pick on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Call&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.sort()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[1, 10, 100, 2, 25, 9]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.sort((a, b) =&amp;gt; a - b)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[1, 2, 9, 10, 25, 100]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;.sort((a, b) =&amp;gt; a - b)&lt;/code&gt; on &lt;code&gt;[3, NaN, 1, 2]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;[3, NaN, 1, 2]&lt;/code&gt; (not sorted)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;MDN says the default sort converts elements to strings and compares UTF-16 code units, so "100" sorts before "2". The &lt;code&gt;a - b&lt;/code&gt; comparator fixes numbers, but MDN notes it only works if the array has no &lt;code&gt;NaN&lt;/code&gt;. My run shows what that looks like: nothing throws, the array just comes back in an order that is not sorted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Names and file names
&lt;/h2&gt;

&lt;p&gt;Input: &lt;code&gt;["Zoë", "zebra", "Éclair", "apple", "Apple", "eclair", "Zoe", "10 files", "2 files", "file 10", "file 2"]&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;default &lt;code&gt;.sort()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;10 files, 2 files, Apple, Zoe, Zoë, apple, eclair, file 10, file 2, zebra, &lt;strong&gt;Éclair&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;localeCompare(b, "en")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;10 files, 2 files, apple, Apple, eclair, Éclair, file 10, file 2, zebra, Zoe, Zoë&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Intl.Collator("en", {numeric: true})&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2 files, 10 files, apple, Apple, eclair, Éclair, file 2, file 10, zebra, Zoe, Zoë&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things to see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The default puts every capital letter before every lowercase one, and "Éclair" lands after "zebra", because the comparison is by code unit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;localeCompare&lt;/code&gt; gives the order people expect for letters, but "file 10" still sorts before "file 2" and "10 files" before "2 files".&lt;/li&gt;
&lt;li&gt;Adding &lt;code&gt;numeric: true&lt;/code&gt; to a collator is what makes "2 files" come before "10 files". MDN lists &lt;code&gt;numeric&lt;/code&gt; as off by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Equal or not: &lt;code&gt;sensitivity&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;sensitivity: "base"&lt;/code&gt;, my run gave &lt;code&gt;compare("Zoe", "Zoë") === 0&lt;/code&gt;, &lt;code&gt;compare("a", "A") === 0&lt;/code&gt; and &lt;code&gt;compare("e", "é") === 0&lt;/code&gt;. That is what you want for search-as-you-type, and the wrong choice for a list where Zoe and Zoë are different people. MDN describes &lt;code&gt;base&lt;/code&gt; as differing only in base letters, and says the default for sorting is &lt;code&gt;variant&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The locale is part of the answer
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;["z", "ä", "a"]&lt;/code&gt; sorted with &lt;code&gt;Intl.Collator("de")&lt;/code&gt; gave &lt;code&gt;a, ä, z&lt;/code&gt;. With &lt;code&gt;Intl.Collator("sv")&lt;/code&gt; it gave &lt;code&gt;a, z, ä&lt;/code&gt;. Same data, same code, different order, because the locale decides where ä goes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Holes and undefined
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;[3, undefined, 1, , 2].sort()&lt;/code&gt; gave &lt;code&gt;[1, 2, 3, undefined, &amp;lt;empty&amp;gt;]&lt;/code&gt;: the length stayed 5, &lt;code&gt;undefined&lt;/code&gt; went to the end, and the empty slot after it (MDN documents both rules). The comparator is never called for &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For numbers, always pass a comparator, and filter out &lt;code&gt;NaN&lt;/code&gt; first if it can occur.&lt;/li&gt;
&lt;li&gt;For text a person will read, use one &lt;code&gt;Intl.Collator&lt;/code&gt; with the user's locale and &lt;code&gt;numeric: true&lt;/code&gt; for names with numbers in them. Create it once and pass &lt;code&gt;collator.compare&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;toSorted()&lt;/code&gt; when you do not want the original array changed (my run: &lt;code&gt;[3, 1, 2]&lt;/code&gt; stayed as it was).&lt;/li&gt;
&lt;li&gt;Write one test with "Éclair", "file 2" and "file 10".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Not tested
&lt;/h2&gt;

&lt;p&gt;Browsers (Node only), Safari and Firefox collation differences, locales other than en, de and sv, very large arrays, and sort stability. Collation depends on the engine's locale data, so check your target runtime.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://dev.to/mercerk17/one-number-three-roundings-tofixed-mathround-and-intlnumberformat-disagree-on-1005-46e6"&gt;One number, three roundings&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>One number, three roundings: toFixed, Math.round and Intl.NumberFormat disagree on 1.005</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Fri, 30 Oct 2026 23:05:26 +0000</pubDate>
      <link>https://dev.to/mercerk17/one-number-three-roundings-tofixed-mathround-and-intlnumberformat-disagree-on-1005-46e6</link>
      <guid>https://dev.to/mercerk17/one-number-three-roundings-tofixed-mathround-and-intlnumberformat-disagree-on-1005-46e6</guid>
      <description>&lt;p&gt;Round 1.005 to two decimals and you can get 1.00, 1.01 or 1 depending on which JavaScript tool you reach for. I ran the common options in Node v22.23.4 (V8) on a set of "half-cent" values and compared them with the exact stored value of each number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;For each value: &lt;code&gt;toFixed(2)&lt;/code&gt;, &lt;code&gt;Math.round(v * 100) / 100&lt;/code&gt;, &lt;code&gt;Intl.NumberFormat("en-US", {minimumFractionDigits: 2, maximumFractionDigits: 2})&lt;/code&gt; with the default rounding, the same with &lt;code&gt;roundingMode: "halfEven"&lt;/code&gt;, and &lt;code&gt;v.toPrecision(20)&lt;/code&gt; to see what the double really holds.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;exact stored value&lt;/th&gt;
&lt;th&gt;toFixed(2)&lt;/th&gt;
&lt;th&gt;Math.round(v*100)/100&lt;/th&gt;
&lt;th&gt;Intl default&lt;/th&gt;
&lt;th&gt;Intl halfEven&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.005&lt;/td&gt;
&lt;td&gt;1.00499999999999989&lt;/td&gt;
&lt;td&gt;1.00&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.01&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.675&lt;/td&gt;
&lt;td&gt;2.67499999999999982&lt;/td&gt;
&lt;td&gt;2.67&lt;/td&gt;
&lt;td&gt;2.68&lt;/td&gt;
&lt;td&gt;2.68&lt;/td&gt;
&lt;td&gt;2.68&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8.345&lt;/td&gt;
&lt;td&gt;8.34500000000000064&lt;/td&gt;
&lt;td&gt;8.35&lt;/td&gt;
&lt;td&gt;8.35&lt;/td&gt;
&lt;td&gt;8.35&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;8.34&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.255&lt;/td&gt;
&lt;td&gt;1.25499999999999989&lt;/td&gt;
&lt;td&gt;1.25&lt;/td&gt;
&lt;td&gt;1.25&lt;/td&gt;
&lt;td&gt;1.26&lt;/td&gt;
&lt;td&gt;1.26&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.615&lt;/td&gt;
&lt;td&gt;0.61499999999999999&lt;/td&gt;
&lt;td&gt;0.61&lt;/td&gt;
&lt;td&gt;0.62&lt;/td&gt;
&lt;td&gt;0.62&lt;/td&gt;
&lt;td&gt;0.62&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10.235&lt;/td&gt;
&lt;td&gt;10.23499999999999943&lt;/td&gt;
&lt;td&gt;10.23&lt;/td&gt;
&lt;td&gt;10.24&lt;/td&gt;
&lt;td&gt;10.24&lt;/td&gt;
&lt;td&gt;10.24&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-1.005&lt;/td&gt;
&lt;td&gt;-1.00499999999999989&lt;/td&gt;
&lt;td&gt;-1.00&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;-1.01&lt;/td&gt;
&lt;td&gt;-1.00&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What I see
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The three methods disagree on the same input.&lt;/strong&gt; For 1.005, &lt;code&gt;toFixed&lt;/code&gt; follows the stored value (just under 1.005) and gives 1.00. &lt;code&gt;Math.round(v * 100)&lt;/code&gt; gives 1 because &lt;code&gt;1.005 * 100&lt;/code&gt; is &lt;code&gt;100.49999999999999&lt;/code&gt;. &lt;code&gt;Intl.NumberFormat&lt;/code&gt; gave 1.01, which is what a person expects, even though the stored value is below the half. I did not look into why. I only report that it differs from &lt;code&gt;toFixed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Math.round&lt;/code&gt; is not the same as the others either.&lt;/strong&gt; For 2.675 and 0.615 it rounds up while &lt;code&gt;toFixed&lt;/code&gt; rounds down, because the multiplication &lt;code&gt;v * 100&lt;/code&gt; lands on a different double than the one you started with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rounding mode changes the answer even when the number is exact.&lt;/strong&gt; 8.345 is stored just above the half, so &lt;code&gt;halfEven&lt;/code&gt; gave 8.34 while default gave 8.35. The whole numbers show it more clearly: &lt;code&gt;Math.round(2.5)&lt;/code&gt; is 3 and &lt;code&gt;halfEven&lt;/code&gt; gives 2. &lt;code&gt;Math.round(-0.5)&lt;/code&gt; returns &lt;code&gt;-0&lt;/code&gt;, while &lt;code&gt;Intl&lt;/code&gt; default gave &lt;code&gt;-1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;MDN documents the rest: &lt;code&gt;toFixed&lt;/code&gt; can look wrong because decimal fractions are not exact in floating point, and &lt;code&gt;Intl.NumberFormat&lt;/code&gt; rounds half away from zero by default (&lt;code&gt;halfExpand&lt;/code&gt;), with &lt;code&gt;halfEven&lt;/code&gt; and other modes available through &lt;code&gt;roundingMode&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do for money
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Keep amounts as integer cents, and round once, at the end, with a rule you write down.&lt;/li&gt;
&lt;li&gt;Pick the rule on purpose: half away from zero (what most people expect) or half even (what some ledgers use).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Intl.NumberFormat&lt;/code&gt; for display only. Do not parse its output back into a number to do maths.&lt;/li&gt;
&lt;li&gt;Add test rows for 1.005, 2.675 and a negative value. They are the ones that split the methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Not tested
&lt;/h2&gt;

&lt;p&gt;Browsers (Node only), other locales, currencies with different digit counts, and any money library. Check your target runtime, since &lt;code&gt;roundingMode&lt;/code&gt; needs a recent engine.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://dev.to/mercerk17/split-a-bill-three-ways-without-losing-a-cent-2mb7"&gt;Split a bill three ways without losing a cent&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What JSON.parse does to a 20-digit integer, and how to keep the digits</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Thu, 29 Oct 2026 23:05:03 +0000</pubDate>
      <link>https://dev.to/mercerk17/what-jsonparse-does-to-a-20-digit-integer-and-how-to-keep-the-digits-420j</link>
      <guid>https://dev.to/mercerk17/what-jsonparse-does-to-a-20-digit-integer-and-how-to-keep-the-digits-420j</guid>
      <description>&lt;p&gt;If an API sends you &lt;code&gt;12345678901234567890&lt;/code&gt; as a JSON number, what does &lt;code&gt;JSON.parse&lt;/code&gt; give you? I ran a few cases in Node v22.23.4 (V8) to see exactly where the digits go, and what the newer &lt;code&gt;context.source&lt;/code&gt; and &lt;code&gt;JSON.rawJSON&lt;/code&gt; options do about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What parse and stringify do to big integers
&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;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"id":12345678901234567890,"small":9007199254740993,"safe":9007199254740991,"price":0.1,"f":1.0}&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;o&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;s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field in the JSON text&lt;/th&gt;
&lt;th&gt;After &lt;code&gt;JSON.parse&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;&lt;code&gt;Number.isSafeInteger&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;12345678901234567890&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;12345678901234567000&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;9007199254740993&lt;/code&gt; (2^53 + 1)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;9007199254740992&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;9007199254740991&lt;/code&gt; (2^53 - 1)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;9007199254740991&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1&lt;/code&gt; after a round trip&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;9007199254740992 === 9007199254740993&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; in the same run, so two different ids can collapse into one. Nothing throws and nothing warns. The value is just a different number, and &lt;code&gt;JSON.stringify(o)&lt;/code&gt; writes the changed digits back out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the original digits: reviver &lt;code&gt;context.source&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The reviver gets a third argument. For primitives it has a &lt;code&gt;source&lt;/code&gt; field with the original text. I used it to turn unsafe integers into BigInt:&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;r&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;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&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;typeof&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="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="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result in Node 22: &lt;code&gt;id&lt;/code&gt; is a bigint printing &lt;code&gt;12345678901234567890&lt;/code&gt;, &lt;code&gt;small&lt;/code&gt; is a bigint printing &lt;code&gt;9007199254740993&lt;/code&gt;, and &lt;code&gt;price&lt;/code&gt; stays the number &lt;code&gt;0.1&lt;/code&gt;. The digits survive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing them back: two traps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;JSON.stringify(r)&lt;/code&gt; on that object throws &lt;code&gt;TypeError: Do not know how to serialize a BigInt&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JSON.rawJSON("12345678901234567890")&lt;/code&gt; is how you write an exact number literal. &lt;code&gt;JSON.stringify({ id: JSON.rawJSON("12345678901234567890") })&lt;/code&gt; gave &lt;code&gt;{"id":12345678901234567890}&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;MDN documents both: &lt;code&gt;context.source&lt;/code&gt; on the &lt;code&gt;JSON.parse&lt;/code&gt; page, and &lt;code&gt;JSON.rawJSON()&lt;/code&gt; as "Baseline 2025, newly available". MDN's own note on the reviver says it runs after the value is parsed, so a plain reviver value has already lost precision. That matches what I saw.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If an id is a big integer, ask the API to send it as a string. This works everywhere.&lt;/li&gt;
&lt;li&gt;If you cannot change the API, read it with &lt;code&gt;context.source&lt;/code&gt; on a runtime that has it, and keep it as a string or BigInt, not a number.&lt;/li&gt;
&lt;li&gt;Do not do arithmetic on ids. Compare them as strings.&lt;/li&gt;
&lt;li&gt;Add a test with &lt;code&gt;9007199254740993&lt;/code&gt;. It is the smallest value that fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Not tested
&lt;/h2&gt;

&lt;p&gt;Browsers (I ran Node only), older runtimes without &lt;code&gt;context.source&lt;/code&gt; or &lt;code&gt;rawJSON&lt;/code&gt;, other JSON libraries, and large decimals like &lt;code&gt;0.1000000000000000055511151231257827&lt;/code&gt;. Check your own target runtime before relying on the reviver option.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://dev.to/mercerk17/what-an-input-typenumber-really-accepts-a-quick-test-1h5n"&gt;What an input type=number really accepts&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>json</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Days between dates in America/Los_Angeles: when one day becomes zero</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Wed, 28 Oct 2026 23:04:46 +0000</pubDate>
      <link>https://dev.to/mercerk17/days-between-dates-in-americalosangeles-when-one-day-becomes-zero-4n7e</link>
      <guid>https://dev.to/mercerk17/days-between-dates-in-americalosangeles-when-one-day-becomes-zero-4n7e</guid>
      <description>&lt;p&gt;A reader suggested running my days-between-dates check with a timezone behind UTC, such as America/Los_Angeles. I had only tested the calculator logic in one zone. So here is the same small test run under three zones, with the results as they came out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt; Node v22 (V8, the engine behind Chrome), run as &lt;code&gt;TZ=&amp;lt;zone&amp;gt; node test.js&lt;/code&gt;. Not a browser, and no UI. I used US daylight saving dates: clocks went forward on March 8, 2026 and back on November 1, 2026. Three ways to get days between two &lt;code&gt;YYYY-MM-DD&lt;/code&gt; strings:&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;ms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;86400000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// 1. parse the strings directly&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="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// 2. build local midnight from the parts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&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="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="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&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;local&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;local&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// 3. build UTC midnight from the parts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;utc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&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;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&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;utc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;Mar 7 to Mar 9, 2026 (expected 2):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;UTC&lt;/th&gt;
&lt;th&gt;America/Los_Angeles&lt;/th&gt;
&lt;th&gt;Australia/Adelaide&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. parse strings&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. local midnight&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1.9583&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. UTC parts&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Mar 8 to Mar 9, 2026 (expected 1), method 2 only: UTC 1, Los Angeles 0.9583, Adelaide 1. Nov 1 to Nov 2, 2026 (expected 1), method 2 in Los Angeles: 1.0417.&lt;/p&gt;

&lt;p&gt;So local midnight is the one that breaks. A 23-hour day gives 0.9583, and &lt;code&gt;Math.floor&lt;/code&gt; turns that into &lt;strong&gt;0&lt;/strong&gt;: one day apart reported as zero days. &lt;code&gt;Math.round&lt;/code&gt; would hide it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A second trap: parsing a date-only string
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;new Date("2026-03-08")&lt;/code&gt; is read as UTC midnight. In Los Angeles that prints as Sat Mar 07 2026 16:00 local, and &lt;code&gt;.getDate()&lt;/code&gt; returns &lt;strong&gt;7&lt;/strong&gt;, not 8. In UTC and Adelaide it returns 8. If you parse a date-only string and then read local parts to display it, the day shifts for anyone behind UTC. &lt;code&gt;new Date("2026-03-08T00:00")&lt;/code&gt; (no zone suffix) is local time and returned 8 in all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For whole days between calendar dates, use method 3. It never touches local time, so DST cannot move it.&lt;/li&gt;
&lt;li&gt;Do not &lt;code&gt;floor&lt;/code&gt; a millisecond difference of local dates. If you must, &lt;code&gt;Math.round&lt;/code&gt; it, and know why.&lt;/li&gt;
&lt;li&gt;If you display a parsed date-only string, format it in UTC or build it from parts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Not tested
&lt;/h2&gt;

&lt;p&gt;Browsers other than the V8 runtime above, Safari's date parsing, zones that skip a whole day, and any specific calculator's source. This is about the arithmetic, not a particular app.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://dev.to/mercerk17/i-asked-a-chat-based-app-builder-for-a-days-between-dates-calculator-and-checked-seven-cases-75e"&gt;the days-between-dates article this came from&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>datetime</category>
    </item>
    <item>
      <title>Typed vs set from script: a number input gives different answers</title>
      <dc:creator>Kai Mercer</dc:creator>
      <pubDate>Wed, 28 Oct 2026 03:14:42 +0000</pubDate>
      <link>https://dev.to/mercerk17/typed-vs-set-from-script-a-number-input-gives-different-answers-3hf1</link>
      <guid>https://dev.to/mercerk17/typed-vs-set-from-script-a-number-input-gives-different-answers-3hf1</guid>
      <description>&lt;p&gt;Last time I tested what a number input accepts. A reader asked for a cleaner split: what happens when the value is typed, versus set from script? This is that test, in one browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup:&lt;/strong&gt; Chrome 155, a plain &lt;code&gt;&amp;lt;input type="number" step="any"&amp;gt;&lt;/code&gt;. "Typed" means per-character key events sent by a browser automation tool, which is not the same as a person on a keyboard. "Set" means &lt;code&gt;input.value = "..."&lt;/code&gt; from script. For each case I read four properties: &lt;code&gt;value&lt;/code&gt;, &lt;code&gt;valueAsNumber&lt;/code&gt;, &lt;code&gt;validity.badInput&lt;/code&gt; and &lt;code&gt;checkValidity()&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;String&lt;/th&gt;
&lt;th&gt;Typed&lt;/th&gt;
&lt;th&gt;Set from script&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1e3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"1e3", 1000, badInput false, valid&lt;/td&gt;
&lt;td&gt;same&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;".5", 0.5, false, valid&lt;/td&gt;
&lt;td&gt;same&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;abc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;td&gt;same&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1e&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"", null, &lt;strong&gt;badInput true, invalid&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"", null, &lt;strong&gt;true, invalid&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1e400&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"", null, &lt;strong&gt;true, invalid&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1,5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"15", 15, false, valid&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"5", 5, false, valid&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;5.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"5", 5, false, valid&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0x10&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"010", 10, false, valid&lt;/td&gt;
&lt;td&gt;"", null, false, valid&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What stands out
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;An empty &lt;code&gt;value&lt;/code&gt; can mean two things.&lt;/strong&gt; Typed &lt;code&gt;1e&lt;/code&gt; and set &lt;code&gt;1e&lt;/code&gt; both leave &lt;code&gt;value&lt;/code&gt; as an empty string. Only the typed one sets &lt;code&gt;badInput&lt;/code&gt; and fails &lt;code&gt;checkValidity()&lt;/code&gt;. If your code only checks &lt;code&gt;value === ""&lt;/code&gt;, it cannot tell "the user typed nothing" from "the user typed something the control could not parse".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting from script skips the typing filter.&lt;/strong&gt; When keys are typed, the browser dropped the comma in &lt;code&gt;1,5&lt;/code&gt; and the &lt;code&gt;x&lt;/code&gt; in &lt;code&gt;0x10&lt;/code&gt;, so the field ended up holding &lt;code&gt;15&lt;/code&gt; and &lt;code&gt;010&lt;/code&gt;. A scripted &lt;code&gt;value&lt;/code&gt; just rejects the whole string. A test that sets values from script will not show you what a typist ends up with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typed &lt;code&gt;abc&lt;/code&gt; was valid and empty.&lt;/strong&gt; The letters never entered the field, so there was nothing to flag.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do with this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Check &lt;code&gt;validity.badInput&lt;/code&gt; as well as &lt;code&gt;value&lt;/code&gt; when you need to tell empty from unparseable.&lt;/li&gt;
&lt;li&gt;If you write tests, type the input through your test runner instead of assigning &lt;code&gt;value&lt;/code&gt;, at least for the cases you care about.&lt;/li&gt;
&lt;li&gt;Keep the control's parsing separate from your own business rule. &lt;code&gt;1e3&lt;/code&gt; is a valid number to the control, and you may not want it in an order quantity field.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Not tested
&lt;/h2&gt;

&lt;p&gt;Firefox and Safari, mobile keyboards, real human typing, pasted text, and locale settings. The typed column comes from automation key events, so treat it as a lead to check in your own browsers.&lt;/p&gt;

&lt;p&gt;Related: the first test, &lt;a href="https://dev.to/mercerk17/what-an-input-typenumber-really-accepts-a-quick-test-1h5n"&gt;What an input type=number really accepts&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
