<?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: JSLab</title>
    <description>The latest articles on DEV Community by JSLab (@jslab).</description>
    <link>https://dev.to/jslab</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%2F4197125%2Faef89c26-9d02-4c49-918d-c1eadb90d1c7.png</url>
      <title>DEV Community: JSLab</title>
      <link>https://dev.to/jslab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jslab"/>
    <language>en</language>
    <item>
      <title>Ask AI about your JavaScript, locally: Ollama in JSLab, no API key</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Tue, 01 Dec 2026 16:01:43 +0000</pubDate>
      <link>https://dev.to/jslab/ask-ai-about-your-javascript-locally-ollama-in-jslab-no-api-key-3a7m</link>
      <guid>https://dev.to/jslab/ask-ai-about-your-javascript-locally-ollama-in-jslab-no-api-key-3a7m</guid>
      <description>&lt;p&gt;Every JavaScript developer gets bitten by &lt;code&gt;.sort()&lt;/code&gt; exactly once.&lt;/p&gt;

&lt;p&gt;This is a walkthrough of &lt;strong&gt;Ask AI&lt;/strong&gt; in JSLab, our JavaScript and TypeScript scratchpad for macOS, running against a model on your own Mac with Ollama. No API key, no account, and with Ollama at its standard local address, your code never leaves the machine. We'll go from setup to the first fix you review as an inline diff.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;JSLab on an Apple Silicon Mac (macOS 14 or later).&lt;/li&gt;
&lt;li&gt;Ollama, a separate, free program that runs models locally.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Install Ollama and pull a model
&lt;/h2&gt;

&lt;p&gt;Install Ollama with its Mac app from Ollama's site, or with Homebrew:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install ollama
ollama serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then pull the model JSLab uses for Ollama by default:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ollama pull qwen2.5:7b-instruct
ollama list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Ollama listens on &lt;code&gt;http://localhost:11434&lt;/code&gt;, which is exactly where JSLab looks. If you'd rather use another model you've pulled, that works too; you'll pick it in the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Point JSLab at Ollama
&lt;/h2&gt;

&lt;p&gt;Open &lt;strong&gt;Settings → AI&lt;/strong&gt; and set &lt;strong&gt;Provider&lt;/strong&gt; to &lt;strong&gt;Ollama (Local)&lt;/strong&gt;. It needs no key.&lt;/p&gt;

&lt;p&gt;Leave &lt;strong&gt;Ollama Model&lt;/strong&gt; blank to use the default (&lt;code&gt;qwen2.5:7b-instruct&lt;/code&gt; in this version), or open the field: it lists the models you've installed. &lt;strong&gt;Refresh&lt;/strong&gt; fetches the list again.&lt;/p&gt;

&lt;p&gt;If Ollama runs on another machine, put its address in &lt;strong&gt;Ollama Base URL&lt;/strong&gt;. Otherwise leave it blank.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Write something slightly wrong
&lt;/h2&gt;

&lt;p&gt;Open a tab and paste this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const scores = [10, 9, 2, 1, 100];
const top3 = scores.sort().reverse().slice(0, 3);
console.log(top3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;JSLab runs it a moment after you stop typing, and the output panel shows the result beside line 3:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 9, 2, 100 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's not the top three. &lt;code&gt;.sort()&lt;/code&gt; with no compare function sorts the values as strings, so &lt;code&gt;100&lt;/code&gt; lands between &lt;code&gt;10&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt;. It also sorts &lt;code&gt;scores&lt;/code&gt; in place, so the original array is changed too.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Ask
&lt;/h2&gt;

&lt;p&gt;Open AI Chat with &lt;strong&gt;⌃⌘I&lt;/strong&gt; (or &lt;strong&gt;Tools → AI Chat…&lt;/strong&gt;). The header shows the provider and model. Each tab keeps its own conversation.&lt;/p&gt;

&lt;p&gt;You don't paste your code. JSLab sends the tab's code with every message, plus the most recent run's output when &lt;strong&gt;Send Recent Output&lt;/strong&gt; is on (it is by default). So you can just ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why isn't top3 [100, 10, 9]? Fix it without changing scores.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or skip typing: right-click the &lt;code&gt;[ 9, 2, 100 ]&lt;/code&gt; row in the output and choose &lt;strong&gt;Explain Result&lt;/strong&gt;. JSLab opens AI Chat and asks why that line produces that result.&lt;/p&gt;

&lt;p&gt;The wording of the reply depends on the model. The fix it should land on looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const scores = [10, 9, 2, 1, 100];
const top3 = [...scores].sort((a, b) =&amp;gt; b - a).slice(0, 3);
console.log(top3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  5. Review it as a diff
&lt;/h2&gt;

&lt;p&gt;Every finished code block in a reply has four buttons: &lt;strong&gt;Copy&lt;/strong&gt;, &lt;strong&gt;Insert at Cursor&lt;/strong&gt;, &lt;strong&gt;Replace Editor&lt;/strong&gt; and &lt;strong&gt;Preview Changes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Preview Changes&lt;/strong&gt;. The diff shows up inline, in your editor: the old line is marked as removed and the new one appears in place. Nothing changes until you decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Apply&lt;/strong&gt; accepts one change and leaves the rest on screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply all&lt;/strong&gt; accepts every change and closes the preview.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discard&lt;/strong&gt; closes the preview and leaves your code as it was.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apply it, and the output reruns:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 100, 10, 9 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Accepted changes land as minimal edits, so ⌘Z takes them back if you change your mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  If something goes wrong
&lt;/h2&gt;

&lt;p&gt;The panel says what failed and offers &lt;strong&gt;Retry&lt;/strong&gt;. The two you're most likely to see with Ollama:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Couldn't reach the provider.&lt;/strong&gt; Ollama isn't running. Start it (&lt;code&gt;ollama serve&lt;/code&gt;, or open the app).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The provider has no such model.&lt;/strong&gt; The name in &lt;strong&gt;Ollama Model&lt;/strong&gt; isn't one you've pulled. Check &lt;code&gt;ollama list&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prefer a hosted model?
&lt;/h2&gt;

&lt;p&gt;Ask AI also works with &lt;strong&gt;OpenAI&lt;/strong&gt;, &lt;strong&gt;Anthropic&lt;/strong&gt; and &lt;strong&gt;Google Gemini&lt;/strong&gt;, with your own API key. Get a key from the provider, paste it into its field under &lt;strong&gt;API Keys&lt;/strong&gt; in &lt;strong&gt;Settings → AI&lt;/strong&gt;, and click &lt;strong&gt;Save&lt;/strong&gt;. The key is stored in your macOS Keychain, never in a settings file, and requests go straight from your Mac to the provider.&lt;/p&gt;

&lt;p&gt;JSLab doesn't include AI credits of its own: it's Ollama on your Mac, or your own key with the provider you choose.&lt;/p&gt;

&lt;h2&gt;
  
  
  What gets sent, exactly
&lt;/h2&gt;

&lt;p&gt;Each message carries JSLab's instructions to the assistant, your tab's code (up to 100 KB), the latest output (up to 20 KB, if Send Recent Output is on), the conversation so far, and your message. Nothing else from your Mac. With Ollama on &lt;code&gt;localhost&lt;/code&gt;, none of it leaves the machine.&lt;/p&gt;

&lt;p&gt;The full reference, including proposed file changes for tabs with a working directory, is in the docs: &lt;a href="https://js-lab.app/docs/ask-ai" rel="noopener noreferrer"&gt;Ask AI&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>ai</category>
      <category>ollama</category>
      <category>macos</category>
    </item>
    <item>
      <title>#777 on white fails WCAG. Build the React checker that catches it</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Tue, 24 Nov 2026 16:01:53 +0000</pubDate>
      <link>https://dev.to/jslab/777-on-white-fails-wcag-build-the-react-checker-that-catches-it-5e02</link>
      <guid>https://dev.to/jslab/777-on-white-fails-wcag-build-the-react-checker-that-catches-it-5e02</guid>
      <description>&lt;p&gt;&lt;code&gt;#777777&lt;/code&gt; on white looks fine. It's also a WCAG fail: 4.48:1, against a minimum of 4.5:1 for body text. One step darker on every channel, &lt;code&gt;#767676&lt;/code&gt;, passes at 4.54:1.&lt;/p&gt;

&lt;p&gt;You can't see that difference, so let's build something that can: a small React contrast checker with two inputs, a live ratio and pass/fail for each WCAG level. It's one file with no project. Along the way you'll get the contrast math and a component that needs no &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The math, before any React
&lt;/h2&gt;

&lt;p&gt;WCAG defines contrast in terms of &lt;em&gt;relative luminance&lt;/em&gt;, or how bright a colour looks to a human eye, from 0 (black) to 1 (white). Getting there takes three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Split the hex into red, green and blue, and scale each to 0–1.&lt;/li&gt;
&lt;li&gt;Undo the sRGB gamma curve, since stored values aren't linear light.&lt;/li&gt;
&lt;li&gt;Weight the channels. Green counts the most, because that's where our eyes are most sensitive.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// "#rgb" or "#rrggbb" → [r, g, b], or null while you're still typing&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="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;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="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&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="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&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="n"&gt;input&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="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hex&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="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&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="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;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="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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&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="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&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="k"&gt;as&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// WCAG relative luminance: 0 for black, 1 for white&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="n"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rgb&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&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="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&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="n"&gt;c&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="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;c&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&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="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="n"&gt;r&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="n"&gt;g&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="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;light&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dark&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="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;luminance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;light&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="n"&gt;dark&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="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ratio is the lighter luminance over the darker one, each plus 0.05, so it runs from 1:1 (same colour) to 21:1 (black on white).&lt;/p&gt;

&lt;p&gt;If you've seen &lt;code&gt;0.03928&lt;/code&gt; in the WCAG 2 text instead of &lt;code&gt;0.04045&lt;/code&gt;, that's fine too. No 8-bit channel value falls between the two, so the result is the same either way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the numbers first
&lt;/h2&gt;

&lt;p&gt;Before rendering anything, make sure the function agrees with the spec. Add three bare expressions under it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// 21&lt;/span&gt;
&lt;span class="nf"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#777"&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="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#fff"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// 4.478…&lt;/span&gt;
&lt;span class="nf"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#767676"&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="nf"&gt;parseHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#fff"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4.542…&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's a trap here. Round &lt;code&gt;4.478&lt;/code&gt; to one decimal and you get &lt;code&gt;4.5&lt;/code&gt;, which &lt;em&gt;looks&lt;/em&gt; like a pass. Round for display only, and always compare the raw number.&lt;/p&gt;

&lt;h2&gt;
  
  
  The component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&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="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"AA body text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"AA large text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"AAA body text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min&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="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;ContrastChecker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setFg&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#777777"&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="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setBg&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#ffffff"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Derived on every render. No useEffect, no extra state.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fgRgb&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="n"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bgRgb&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="n"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ratio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fgRgb&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;bgRgb&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;contrast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fgRgb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bgRgb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;fontFamily&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"system-ui"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;360&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setFg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Background&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setBg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ratio&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;two&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="n"&gt;colours&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; #&lt;span class="mi"&gt;2f52c9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;padding&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="n"&gt;borderRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nc"&gt;The&lt;/span&gt; &lt;span class="n"&gt;quick&lt;/span&gt; &lt;span class="n"&gt;brown&lt;/span&gt; &lt;span class="n"&gt;fox&lt;/span&gt; &lt;span class="n"&gt;jumps&lt;/span&gt; &lt;span class="n"&gt;over&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="n"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ratio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;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="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ratio&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;min&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"pass"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fail"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;min&lt;/span&gt;&lt;span class="p"&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="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;import { useState } from "react";&lt;/code&gt; at the top and the three code blocks together make one file.&lt;/p&gt;

&lt;p&gt;Three decisions worth stealing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State holds the raw string, exactly as typed.&lt;/strong&gt; On the way from &lt;code&gt;#2f52c9&lt;/code&gt; to &lt;code&gt;#2f52c8&lt;/code&gt;, the input briefly holds &lt;code&gt;#2f52c&lt;/code&gt;, which isn't a colour. &lt;code&gt;parseHex&lt;/code&gt; returns &lt;code&gt;null&lt;/code&gt;, and the component shows a hint instead of breaking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The ratio is derived, not stored.&lt;/strong&gt; The tempting version keeps &lt;code&gt;ratio&lt;/code&gt; in state and updates it in a &lt;code&gt;useEffect&lt;/code&gt;. That renders once with the old ratio, then again with the new one, and gives you two sources of truth. Computing it during render is one line and is always right.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The swatch only renders when both colours parse.&lt;/strong&gt; The browser never receives half a colour.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run it without a project
&lt;/h2&gt;

&lt;p&gt;I ran this in JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS. It's our own tool, so weigh the praise accordingly. The setup is the part a scaffold usually takes care of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pick a browser runtime.&lt;/strong&gt; A component needs a page. Click &lt;strong&gt;+&lt;/strong&gt; in the tab bar and choose &lt;strong&gt;React&lt;/strong&gt;, and JSLab sets the tab's language, runtime and framework, installs the packages and opens starter code. Paste the file over it. If you start from a plain tab instead, pick &lt;strong&gt;Browser&lt;/strong&gt; in the runtime menu in the status bar, because the default Bun runtime has no page and so no Web View. Plain Browser is enough here, since nothing in this file needs Node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render it.&lt;/strong&gt; Default-export the component and JSLab renders it into the &lt;strong&gt;Web View&lt;/strong&gt; tile beside the console. There's no &lt;code&gt;createRoot&lt;/code&gt; and no &lt;code&gt;index.html&lt;/code&gt;. The &lt;strong&gt;Framework&lt;/strong&gt; menu in the status bar shows that it found React from your imports. If &lt;code&gt;react-dom&lt;/code&gt; isn't installed, the console names the package to install, and ⌘I opens the package sheet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch it rerender.&lt;/strong&gt; Auto Run runs the tab a moment after you stop typing. Change the default &lt;code&gt;"#777777"&lt;/code&gt; to &lt;code&gt;"#767676"&lt;/code&gt;, and both the ratio and the AA body text line in the Web View update. The three &lt;code&gt;contrast(...)&lt;/code&gt; lines show their values in the output, each next to the line that produced it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One thing to know: every run reloads the page, so the DOM starts clean each time. Editing the code resets the inputs to their &lt;code&gt;useState&lt;/code&gt; defaults. When you want a colour pair to stick around while you work on the component, make it the default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make it yours
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add a swap button.&lt;/strong&gt; &lt;code&gt;&amp;lt;button onClick={() =&amp;gt; { setFg(bg); setBg(fg); }}&amp;gt;Swap&amp;lt;/button&amp;gt;&lt;/code&gt;. Contrast is symmetric, so the ratio shouldn't move. That's a free test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accept &lt;code&gt;rgb(…)&lt;/code&gt; too.&lt;/strong&gt; Only &lt;code&gt;parseHex&lt;/code&gt; changes. Everything downstream takes an &lt;code&gt;RGB&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check your own palette.&lt;/strong&gt; Swap the inputs for an array of &lt;code&gt;[fg, bg]&lt;/code&gt; pairs from your design tokens, and render one row per pair.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Web View, the Framework menu and the other frameworks it renders (Vue, Solid, Angular) are covered in the docs: &lt;a href="https://js-lab.app/docs/web-view" rel="noopener noreferrer"&gt;https://js-lab.app/docs/web-view&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>a11y</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>JSLab is out: write code, watch it run as you type</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Sun, 15 Nov 2026 16:01:15 +0000</pubDate>
      <link>https://dev.to/jslab/jslab-is-out-write-code-watch-it-run-as-you-type-3m6k</link>
      <guid>https://dev.to/jslab/jslab-is-out-write-code-watch-it-run-as-you-type-3m6k</guid>
      <description>&lt;p&gt;JSLab is available today for Apple Silicon Macs running macOS 14 or later.&lt;/p&gt;

&lt;p&gt;It's a native JavaScript and TypeScript scratchpad. Open a tab, type, and every result, log and error lands in the output panel, tagged with the line that produced it. No project, no terminal, no build step.&lt;/p&gt;

&lt;h2&gt;
  
  
  A first tab
&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="n"&gt;orders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"EU"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"APAC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;210&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;revenue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//?&lt;/span&gt;
&lt;span class="sb"&gt;`Revenue: ${revenue}`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;410&lt;/code&gt; appears beside line 7 and &lt;code&gt;Revenue: 410&lt;/code&gt; beside line 8. Change a total and both update a moment after you stop typing. No &lt;code&gt;console.log&lt;/code&gt; anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's in it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Auto Run.&lt;/strong&gt; Your code reruns a moment after you stop typing. ⌘R runs on demand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every result, traced to its line.&lt;/strong&gt; Click a row in the output and the editor jumps there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Magic comments.&lt;/strong&gt; &lt;code&gt;value //?&lt;/code&gt; logs a value; &lt;code&gt;//? $.length&lt;/code&gt; logs part of it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Three runtimes, one per tab.&lt;/strong&gt; Bun (the default), Browser, or Browser &amp;amp; Node APIs. Browser tabs render React, Vue and Angular in a Web View beside the console.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;npm packages&lt;/strong&gt;, with types and autocomplete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask AI.&lt;/strong&gt; It reads the code in your tab and sends changes back as an inline diff you accept or reject. Ollama runs locally; OpenAI, Anthropic and Google Gemini use your own key, stored in the macOS Keychain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your code stays on your Mac.&lt;/strong&gt; No telemetry, no crash-reporting services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each feature has its own short post in the &lt;a href="https://dev.to/jslab/scratchpad-js-the-index-1mla"&gt;Scratchpad JS series&lt;/a&gt;, and the docs are at &lt;a href="https://js-lab.app/docs" rel="noopener noreferrer"&gt;js-lab.app/docs&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;14 days free, no account needed: &lt;a href="https://js-lab.app" rel="noopener noreferrer"&gt;js-lab.app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If something breaks or reads wrong, say so in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>macos</category>
      <category>productivity</category>
    </item>
    <item>
      <title>JSLab launch-day FAQ, answered from the docs</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Sun, 15 Nov 2026 00:45:58 +0000</pubDate>
      <link>https://dev.to/jslab/jslab-launch-day-faq-answered-from-the-docs-1304</link>
      <guid>https://dev.to/jslab/jslab-launch-day-faq-answered-from-the-docs-1304</guid>
      <description>&lt;p&gt;&lt;em&gt;JSLab feature notes: one docs page, explained. Today: the questions we expect on launch day, each answered from the &lt;a href="https://js-lab.app/docs" rel="noopener noreferrer"&gt;docs&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JSLab, a fast, native JavaScript &amp;amp; TypeScript scratchpad for macOS, launches tomorrow. Here are the questions we expect, with the docs' answers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which Macs does it run on?
&lt;/h2&gt;

&lt;p&gt;Apple Silicon Macs, on macOS 14 or later. No Intel Macs, no Windows, no Linux, no web version. It needs macOS 14 because license verification uses WebKit's Ed25519 support, which macOS 13 lacks. (&lt;a href="https://js-lab.app/docs/install" rel="noopener noreferrer"&gt;Install&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Do I need an account?
&lt;/h2&gt;

&lt;p&gt;No. The trial starts with no signup, and buying doesn't create an account either. (&lt;a href="https://js-lab.app/docs/license" rel="noopener noreferrer"&gt;Free trial and license&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Is there a trial?
&lt;/h2&gt;

&lt;p&gt;Yes: 14 days, starting the first time you open the app. Every feature works during the trial exactly as it will with a key. If the trial ends, running code pauses; opening, editing and saving keep working, so nothing you've written is locked away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does my code leave my Mac?
&lt;/h2&gt;

&lt;p&gt;Your code runs locally. JSLab has no telemetry, no analytics and no crash reporting. The one feature that sends code anywhere is Ask AI, and only to the provider you choose: with Ollama at its standard local address, nothing leaves your Mac. With OpenAI, Anthropic or Gemini, requests go straight from your Mac to them, with your own key, stored in the macOS Keychain. (&lt;a href="https://js-lab.app/docs/ai-providers" rel="noopener noreferrer"&gt;AI providers and keys&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Does it run TypeScript? npm packages?
&lt;/h2&gt;

&lt;p&gt;Yes, and yes. Types are checked in the editor and stripped when the code runs. ⌘I installs any npm package once, for every tab, with types and autocomplete. (&lt;a href="https://js-lab.app/docs/npm-packages" rel="noopener noreferrer"&gt;npm packages&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  What if my code hangs?
&lt;/h2&gt;

&lt;p&gt;⇧⌘R stops a run; ⌥⌘R kills it. Endless loops are stopped after 2,000 iterations by default. Each run is its own process, so a crash never takes JSLab down. If a tab hangs every time JSLab opens, hold Shift while launching for Safe Mode. (&lt;a href="https://js-lab.app/docs/editor" rel="noopener noreferrer"&gt;The editor&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  How do updates work?
&lt;/h2&gt;

&lt;p&gt;JSLab checks for signed updates about once an hour, fetches them in the background and asks you to restart. Nothing installs while you're working, and an update that can't be verified is never installed. (&lt;a href="https://js-lab.app/docs/updates" rel="noopener noreferrer"&gt;Updates&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Where's my data?
&lt;/h2&gt;

&lt;p&gt;In one folder: &lt;code&gt;~/Library/Application Support/dev.jslab.app/&amp;lt;channel&amp;gt;/&lt;/code&gt;. Settings, session, snippets, keybindings and imported themes are all plain files there. API keys aren't: they're in your Keychain. &lt;strong&gt;Open Data Folder&lt;/strong&gt; in the command palette takes you there. (&lt;a href="https://js-lab.app/docs/reference/troubleshooting" rel="noopener noreferrer"&gt;Troubleshooting&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Can I bring my VS Code theme?
&lt;/h2&gt;

&lt;p&gt;Yes. Themes → Import VS Code Theme… takes a &lt;code&gt;.json&lt;/code&gt; or &lt;code&gt;.vsix&lt;/code&gt;. (&lt;a href="https://js-lab.app/docs/themes" rel="noopener noreferrer"&gt;Themes&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do I start?
&lt;/h2&gt;

&lt;p&gt;Open a tab and type. Then &lt;a href="https://js-lab.app/docs/first-tab" rel="noopener noreferrer"&gt;Your first tab&lt;/a&gt;, or Help → Learning &amp;amp; Tips inside the app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc3fchtixdid129glv9h9.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%2Fc3fchtixdid129glv9h9.png" alt="JSLab editor with TypeScript: an Order interface (region: string, total: number, paid: boolean) and a typed orders array, with the status bar below showing Bun, TypeScript and Side by side." width="668" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSLab launches tomorrow, Nov 15. All the docs: &lt;a href="https://js-lab.app/docs" rel="noopener noreferrer"&gt;https://js-lab.app/docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>macos</category>
    </item>
    <item>
      <title>Scratchpad JS: the index</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Sat, 14 Nov 2026 16:03:14 +0000</pubDate>
      <link>https://dev.to/jslab/scratchpad-js-the-index-1mla</link>
      <guid>https://dev.to/jslab/scratchpad-js-the-index-1mla</guid>
      <description>&lt;p&gt;For two weeks, this series has been one idea a day: a JavaScript or TypeScript technique small enough to try in a scratch file, explained well enough to use at work. Here's all of it, grouped by what you're trying to do. The series box above links every post.&lt;/p&gt;

&lt;h2&gt;
  
  
  "What is this value?"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;#1 Inspect any value without console.log:&lt;/strong&gt; the &lt;code&gt;console.log(x) || x&lt;/code&gt; trick, a &lt;code&gt;tap&lt;/code&gt; helper, and when to just split the chain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#2 Log inside a loop without touching the code:&lt;/strong&gt; conditional logs, &lt;code&gt;console.table&lt;/code&gt;, &lt;code&gt;console.count&lt;/code&gt; and logpoints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#9 Quick data munging:&lt;/strong&gt; &lt;code&gt;Object.groupBy&lt;/code&gt;, a real CSV parser, and the date bug that moves Monday to Sunday.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "Why did it break?"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;#7 Reading a stack trace that points at your own line:&lt;/strong&gt; read it top down, throw &lt;code&gt;Error&lt;/code&gt;s, name functions, wrap with &lt;code&gt;cause&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#6 TypeScript types you can see running:&lt;/strong&gt; why &lt;code&gt;as&lt;/code&gt; lies, and how type guards, assertion functions and &lt;code&gt;satisfies&lt;/code&gt; put checks back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#11 What your TypeScript becomes when it runs:&lt;/strong&gt; what's erased, what's emitted, and &lt;code&gt;erasableSyntaxOnly&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "Will this work there?"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;#5 The same snippet in Bun and in a browser:&lt;/strong&gt; the portable core, feature detection, and detecting once at the edge.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#10 Prototype an API call before you write the client:&lt;/strong&gt; tokens from the environment, timeouts, &lt;code&gt;res.ok&lt;/code&gt;, rate limits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "Can I just try it?"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;#3 Try a React component without creating a project:&lt;/strong&gt; a &lt;code&gt;useDebouncedValue&lt;/code&gt; hook, tested in one file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#8 Canvas sketches with no build step:&lt;/strong&gt; Retina-sharp pixels, delta time, and fading trails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#4 Refactor with a local model, and review it as a diff:&lt;/strong&gt; pin behaviour with &lt;code&gt;console.assert&lt;/code&gt;, then read the diff.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "Make me faster"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;#12 Multi-cursor moves that replace a regex:&lt;/strong&gt; split into lines, select next, column cursors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;#13 A week of JavaScript tips, collected:&lt;/strong&gt; &lt;code&gt;at&lt;/code&gt;, &lt;code&gt;toSorted&lt;/code&gt;, &lt;code&gt;structuredClone&lt;/code&gt;, &lt;code&gt;Object.groupBy&lt;/code&gt; and friends.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why a scratchpad
&lt;/h2&gt;

&lt;p&gt;Every post ended the same way: here's the technique, now try it. That's because a technique you've run once sticks in a way that one you've read about doesn't. And trying it should take seconds, not a project.&lt;/p&gt;

&lt;p&gt;That's the idea behind JSLab, the JavaScript &amp;amp; TypeScript scratchpad for macOS that every example in this series was run in: open a tab, type, and every result shows up beside the line that produced it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgderaip3ewtglw7kgl8b.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%2Fgderaip3ewtglw7kgl8b.png" alt="A 16-line JSLab program that logs each order, groups them by region in a Map and logs the revenue, top region and average, with its nine output rows below, each tagged to its line: EU 120, US 80, EU 45.5, APAC 210, US 64 (:8), Map(3) (:11), Revenue: 519.5 (:13), Top region: APAC (:15), Average: 103.9 (:16)." width="800" height="746"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It launches tomorrow, Nov 15. The docs are already up: &lt;a href="https://js-lab.app/docs" rel="noopener noreferrer"&gt;https://js-lab.app/docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A week of JavaScript tips, collected</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Fri, 13 Nov 2026 16:01:27 +0000</pubDate>
      <link>https://dev.to/jslab/a-week-of-javascript-tips-collected-4hdi</link>
      <guid>https://dev.to/jslab/a-week-of-javascript-tips-collected-4hdi</guid>
      <description>&lt;p&gt;Seven tips, one for each day of the week. Each one replaces a helper you used to write, a library you used to install, or a bug you used to ship. All of them work in current Node, Bun and evergreen browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Monday: &lt;code&gt;.at(-1)&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;steps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"parse"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"check"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"emit"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// "emit"&lt;/span&gt;
&lt;span class="n"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// "check"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No more &lt;code&gt;arr[arr.length - 1]&lt;/code&gt;. Works on strings too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tuesday: &lt;code&gt;toSorted&lt;/code&gt; doesn't mutate
&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="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&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;const&lt;/span&gt; &lt;span class="n"&gt;sorted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toSorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 10]&lt;/span&gt;
&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                          &lt;span class="c1"&gt;// still [10, 1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sort&lt;/code&gt; sorts in place and returns the same array, which surprises everyone once. &lt;code&gt;toSorted&lt;/code&gt;, &lt;code&gt;toReversed&lt;/code&gt; and &lt;code&gt;toSpliced&lt;/code&gt; return a copy. And always pass a compare function: &lt;code&gt;[1, 2, 10].sort()&lt;/code&gt; is &lt;code&gt;[1, 10, 2]&lt;/code&gt;, because the default sort compares strings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wednesday: &lt;code&gt;structuredClone&lt;/code&gt; for deep copies
&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="n"&gt;original&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nested&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;copy&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="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nested&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&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="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nested&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;when&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nb"&gt;Date&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;Unlike &lt;code&gt;JSON.parse(JSON.stringify(x))&lt;/code&gt;, it keeps Dates, Maps and Sets. It throws on functions, which is a feature: you find out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thursday: &lt;code&gt;Object.groupBy&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"core"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Grace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"core"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// { core: [Ada, Grace], web: [Alan] }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;reduce&lt;/code&gt; you've written a hundred times, built in. (More in #9.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Friday: &lt;code&gt;AbortSignal.timeout&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.github.com/zen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AbortSignal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fetch&lt;/code&gt; has no timeout of its own. This one line gives it one, and rejects with a &lt;code&gt;TimeoutError&lt;/code&gt;. (More in #10.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Saturday: &lt;code&gt;Error&lt;/code&gt; with &lt;code&gt;cause&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&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="s2"&gt;"{oops"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Could not read settings"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cause&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your message says what you were doing, and &lt;code&gt;err.cause&lt;/code&gt; still has the original error. (More in #7.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Sunday: &lt;code&gt;satisfies&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/docs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;satisfies&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sb"&gt;`/${string}`&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// fine, and autocomplete knows the keys&lt;/span&gt;
&lt;span class="c1"&gt;// routes.blog;   // error: Property 'blog' does not exist&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It checks that every value starts with &lt;code&gt;/&lt;/code&gt;, without widening the object to &lt;code&gt;Record&amp;lt;string, …&amp;gt;&lt;/code&gt;, so you keep the exact keys. (More in #6.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying them
&lt;/h2&gt;

&lt;p&gt;Each of these is a two-line experiment, which is what a scratchpad is for. In JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS, &lt;strong&gt;Auto Log&lt;/strong&gt; puts the value of each top-level expression beside its line as you type. In Tuesday's block, &lt;code&gt;nums;&lt;/code&gt; shows up as &lt;code&gt;▸ Array(3)&lt;/code&gt;; expand it to check it's still &lt;code&gt;10, 1, 2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If a result surprises you, right-click it and choose &lt;strong&gt;Explain Result&lt;/strong&gt; to ask Ask AI why. It works with your own key, or Ollama locally.&lt;/p&gt;

&lt;p&gt;And if you'd like the tips about JSLab itself: in your first week, it shows a short tip in the status bar the first time you meet a feature, and &lt;strong&gt;Help → Learning &amp;amp; Tips&lt;/strong&gt; has every feature with a video.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. Learning &amp;amp; Tips: &lt;a href="https://js-lab.app/docs/learn" rel="noopener noreferrer"&gt;https://js-lab.app/docs/learn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Ask AI with Ollama, fully local</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Fri, 13 Nov 2026 04:16:07 +0000</pubDate>
      <link>https://dev.to/jslab/ask-ai-with-ollama-fully-local-2pp5</link>
      <guid>https://dev.to/jslab/ask-ai-with-ollama-fully-local-2pp5</guid>
      <description>&lt;p&gt;&lt;em&gt;JSLab feature notes: one docs page, explained. Today: &lt;a href="https://js-lab.app/docs/ask-ai" rel="noopener noreferrer"&gt;Ask AI&lt;/a&gt; with &lt;a href="https://js-lab.app/docs/ai-providers" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS, has an AI Chat panel that answers questions about the code in your tab and returns changes as a diff. It works with your own key, or Ollama locally. This note is about the local option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup: three steps, no key
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;a href="https://ollama.com" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt;, a separate, free program that runs models on your Mac, and start it.&lt;/li&gt;
&lt;li&gt;Pull a model. JSLab's default for Ollama in this version is &lt;code&gt;qwen2.5:7b-instruct&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ollama pull qwen2.5:7b-instruct
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In JSLab, open &lt;strong&gt;Settings → AI&lt;/strong&gt; and set &lt;strong&gt;Provider&lt;/strong&gt; to &lt;strong&gt;Ollama (Local)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. The &lt;strong&gt;Model&lt;/strong&gt; field lists the models you've installed (&lt;strong&gt;Refresh&lt;/strong&gt; re-reads them). Leave it blank for the default, or pick another.&lt;/p&gt;

&lt;h2&gt;
  
  
  What leaves your Mac
&lt;/h2&gt;

&lt;p&gt;Nothing, as long as Ollama is at its standard address, &lt;code&gt;http://localhost:11434&lt;/code&gt;. Each message carries JSLab's instructions, the tab's code (up to 100 KB), the conversation so far, your message and, with &lt;strong&gt;Send Recent Output&lt;/strong&gt; on, the last run's output (up to 20 KB). All of it goes to that local address.&lt;/p&gt;

&lt;p&gt;Change &lt;strong&gt;Ollama Base URL&lt;/strong&gt; to point at a bigger machine on your network and it goes there instead. Your choice, made explicitly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;⌃⌘I&lt;/strong&gt; opens AI Chat in the side bar. Each tab has its own conversation, and it's saved, so it's still there after a relaunch. An empty chat offers starters: &lt;strong&gt;Explain this tab&lt;/strong&gt;, &lt;strong&gt;Why does line N fail?&lt;/strong&gt; after a failed run, and &lt;strong&gt;Add types&lt;/strong&gt; for the name at the caret.&lt;/p&gt;

&lt;p&gt;Code blocks in a reply get four buttons: &lt;strong&gt;Copy&lt;/strong&gt;, &lt;strong&gt;Insert at Cursor&lt;/strong&gt;, &lt;strong&gt;Replace Editor&lt;/strong&gt; and &lt;strong&gt;Preview Changes&lt;/strong&gt;. Preview shows the change as an inline diff in the editor, and nothing changes until you &lt;strong&gt;Apply&lt;/strong&gt; one change, &lt;strong&gt;Apply all&lt;/strong&gt;, or &lt;strong&gt;Discard&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3ww5t38k7nell5zimvct.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%2F3ww5t38k7nell5zimvct.png" alt="JSLab's inline diff from Ask AI: &amp;quot;return settings.editor.tabWidth;&amp;quot; marked for removal and &amp;quot;return settings?.editor?.tabWidth ?? 4;&amp;quot; added in green, with Apply and Discard below." width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain Result
&lt;/h2&gt;

&lt;p&gt;Right-click any output row and choose &lt;strong&gt;Explain Result&lt;/strong&gt;. JSLab asks why that line produced that value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// [1, 10, 2]. Why?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A local model is good at exactly this kind of question: small, concrete, with the code and the value right there.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it can't connect
&lt;/h2&gt;

&lt;p&gt;"Couldn't reach the provider" with Ollama almost always means Ollama isn't running. Start it and click &lt;strong&gt;Retry&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. The full pages: &lt;a href="https://js-lab.app/docs/ask-ai" rel="noopener noreferrer"&gt;https://js-lab.app/docs/ask-ai&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>ai</category>
      <category>ollama</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Building a scratchpad on Bun: 7 things that differ from Node</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Fri, 13 Nov 2026 03:31:07 +0000</pubDate>
      <link>https://dev.to/jslab/building-a-scratchpad-on-bun-7-things-that-differ-from-node-ogp</link>
      <guid>https://dev.to/jslab/building-a-scratchpad-on-bun-7-things-that-differ-from-node-ogp</guid>
      <description>&lt;p&gt;JSLab is a JavaScript &amp;amp; TypeScript scratchpad for macOS, and every run in a Bun tab is a separate Bun process. Bun aims to be Node-compatible, and most Node code runs unchanged. But "most" is where a tool has to make decisions. Here are seven differences, what JSLab does about each, and what they mean if you use Bun yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. It's JavaScriptCore, not V8
&lt;/h2&gt;

&lt;p&gt;Bun runs on JavaScriptCore, Safari's engine. Anything tied to V8 behaves differently: the &lt;code&gt;v8&lt;/code&gt; module is only partly there, heap snapshots aren't V8's format, &lt;code&gt;--inspect&lt;/code&gt; flags don't apply, and &lt;strong&gt;stack trace text is formatted differently&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That last one matters if you parse stack traces. JSLab doesn't parse the text: it maps positions back to your source and renders stacks itself, so the output panel looks the same whichever engine produced the error.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Module resolution is looser
&lt;/h2&gt;

&lt;p&gt;Bun resolves more like a bundler than like Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;slugify&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./util"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no extension: fine in Bun&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"node:fs"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// require inside an ES module: also fine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code that works in Bun can fail in strict Node ESM. If you're writing for both, keep the extensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Bun loads &lt;code&gt;.env&lt;/code&gt; on its own
&lt;/h2&gt;

&lt;p&gt;By default Bun reads &lt;code&gt;.env&lt;/code&gt; files from the current folder. Handy in a project, surprising in a tool. JSLab turns that off and reads the working folder's &lt;code&gt;.env&lt;/code&gt; itself, so the result is the same in every run, and it layers it with your shell and its own Environment Variables sheet in a fixed order.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;code&gt;bunfig.toml&lt;/code&gt; can change everything
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;bunfig.toml&lt;/code&gt; in the folder can change how Bun resolves and runs code. JSLab launches every run with &lt;code&gt;--config=/dev/null&lt;/code&gt;, so a folder's &lt;code&gt;bunfig.toml&lt;/code&gt; is never applied. For the same reason, &lt;code&gt;BUN_OPTIONS&lt;/code&gt; is stripped from the run's environment. And &lt;code&gt;NODE_OPTIONS&lt;/code&gt;? Passed through, but Bun ignores it.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;code&gt;process.exit()&lt;/code&gt; and output
&lt;/h2&gt;

&lt;p&gt;A snippet that logs and then calls &lt;code&gt;process.exit()&lt;/code&gt; should still show its logs. In JSLab, &lt;code&gt;process.exit()&lt;/code&gt; ends the run once its output is delivered. And code that catches the exit (in a &lt;code&gt;try/catch&lt;/code&gt;, say) doesn't keep running: later output is dropped, and its timers and servers are stopped.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Packages without a restart
&lt;/h2&gt;

&lt;p&gt;JSLab installs npm packages into one shared project, and every Bun run finds them through &lt;code&gt;NODE_PATH&lt;/code&gt;. That's why a package you add in one tab is importable in every other tab straight away. With a working directory set, that folder's &lt;code&gt;node_modules&lt;/code&gt; is searched first, so you get the project's versions.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. The Bun is pinned
&lt;/h2&gt;

&lt;p&gt;JSLab ships its own Bun (1.4.0 at the time of writing; Help → About JSLab shows yours). Your snippets don't depend on whether you have Bun installed, or which version is on your &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this adds up to
&lt;/h2&gt;

&lt;p&gt;Each of these comes from the same rule: &lt;strong&gt;a run should behave the same every time, whatever folder or shell it starts from.&lt;/strong&gt; If you build tools on Bun, it's worth applying that rule to the same seven places.&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%2Fq827qstui6j8svlk4kqn.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%2Fq827qstui6j8svlk4kqn.png" alt="A JSLab tab on Bun: &amp;quot;document&amp;quot; in globalThis returns false, &amp;quot;Bun&amp;quot; in globalThis returns true, process.versions.bun returns 1.4.0, and readdir(&amp;quot;.&amp;quot;) counts 16 files, each value tagged to its line." width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The full list, including the Browser &amp;amp; Node APIs runtime, is on one docs page.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. Bun vs Node: &lt;a href="https://js-lab.app/docs/bun-vs-node" rel="noopener noreferrer"&gt;https://js-lab.app/docs/bun-vs-node&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bunjs</category>
      <category>javascript</category>
      <category>node</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Multi-cursor moves that replace a regex</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Thu, 12 Nov 2026 02:02:29 +0000</pubDate>
      <link>https://dev.to/jslab/multi-cursor-moves-that-replace-a-regex-eap</link>
      <guid>https://dev.to/jslab/multi-cursor-moves-that-replace-a-regex-eap</guid>
      <description>&lt;p&gt;You paste ten lines from a spreadsheet and need them as a JavaScript array. You could write a regex. Or you could edit all ten lines at once, which is faster and you can see it working.&lt;/p&gt;

&lt;p&gt;Every Monaco-based editor (VS Code included) has these. The shortcuts below are JSLab's; your editor's may differ, and its command palette will tell you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move 1: a pasted column into an array
&lt;/h2&gt;

&lt;p&gt;You paste this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ada Lovelace
Alan Turing
Grace Hopper
Katherine Johnson
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Select all four lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Split Selection into Lines&lt;/strong&gt; (⇧⌘L): now there's a cursor at the end of each line.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Home&lt;/strong&gt;: every cursor jumps to the start of its line. Type &lt;code&gt;"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;End&lt;/strong&gt;: type &lt;code&gt;",&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"Ada Lovelace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"Alan Turing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"Grace Hopper"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s2"&gt;"Katherine Johnson"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wrap it in &lt;code&gt;const names = [&lt;/code&gt; … &lt;code&gt;];&lt;/code&gt; and you're done. Four lines or four hundred, it's the same four steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move 2: rename by selecting the next match
&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="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put the caret in &lt;code&gt;price&lt;/code&gt; and press &lt;strong&gt;⌘D&lt;/strong&gt; (Select Next Occurrence) once for each match you want. Type &lt;code&gt;cost&lt;/code&gt;, and they all change.&lt;/p&gt;

&lt;p&gt;Unlike find and replace, you see each match get picked, and you can stop before the one you don't want. Here, the arrow function's parameter is a different variable that happens to share the name. ⌘D lets you include it or skip it on purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Move 3: column cursors
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Add Cursor Below&lt;/strong&gt; (⌃⇧↓) stacks cursors straight down, one per line. Good for adding the same thing at the same column, like a key prefix:&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="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://api.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"8080"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="no"&gt;REGION&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"eu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cursor before &lt;code&gt;URL&lt;/code&gt;, ⌃⇧↓ twice, type &lt;code&gt;API_&lt;/code&gt;, and all three keys get the prefix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two more worth knowing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Expand Selection&lt;/strong&gt; (⇧⌘Space) grows the selection to the next enclosing thing: word, string, argument list, block. Faster than dragging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Line&lt;/strong&gt; (⇧⌘D) and &lt;strong&gt;Move Line Up / Down&lt;/strong&gt; (⌃⌘↑ / ⌃⌘↓) rearrange code without cut and paste.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If you think in Vim
&lt;/h2&gt;

&lt;p&gt;JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS, has &lt;strong&gt;Vim Keys&lt;/strong&gt; in Settings → Editor, and &lt;strong&gt;⌘R still runs your code in every mode&lt;/strong&gt;, so you never have to leave Normal mode to see a result.&lt;/p&gt;

&lt;p&gt;In a scratchpad, multi-cursor matters more than in a project: you're constantly reshaping pasted data into something you can run. With Auto Run on, the result updates as soon as you stop typing, so you see the array form as you edit.&lt;/p&gt;

&lt;p&gt;Every one of these is a JSLab command, so you can rebind it in Settings → Keybindings or find it by name with ⇧⌘P.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. Editing shortcuts: &lt;a href="https://js-lab.app/docs/reference/keyboard-shortcuts" rel="noopener noreferrer"&gt;https://js-lab.app/docs/reference/keyboard-shortcuts&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>javascript</category>
      <category>vscode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tabs, files and session restore</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Thu, 12 Nov 2026 00:45:55 +0000</pubDate>
      <link>https://dev.to/jslab/tabs-files-and-session-restore-3213</link>
      <guid>https://dev.to/jslab/tabs-files-and-session-restore-3213</guid>
      <description>&lt;p&gt;&lt;em&gt;JSLab feature notes: one docs page, explained. Today: &lt;a href="https://js-lab.app/docs/first-tab" rel="noopener noreferrer"&gt;Your first tab&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A scratchpad lives or dies on one question: is my stuff still there tomorrow? In JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS, the answer is yes, and this note covers how.&lt;/p&gt;

&lt;h2&gt;
  
  
  Session restore
&lt;/h2&gt;

&lt;p&gt;Quit JSLab and relaunch, and it brings back:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your tabs and their code;&lt;/li&gt;
&lt;li&gt;each tab's layout, folds, cursor and scroll position;&lt;/li&gt;
&lt;li&gt;the window's size and the display it was on.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also kept per tab: its working directory and whether its Web View is showing. Each tab's AI Chat conversation comes back too.&lt;/p&gt;

&lt;p&gt;The session lives in &lt;code&gt;session.json&lt;/code&gt; in JSLab's data folder. If that file can't be read, JSLab restores it from its backup when it can and tells you. A tab whose contents can't be read opens empty and &lt;strong&gt;read-only&lt;/strong&gt;, so JSLab never saves over the file on disk.&lt;/p&gt;

&lt;p&gt;Updates use the same mechanism: restarting to update relaunches JSLab with your tabs as they were.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tabs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;To&lt;/th&gt;
&lt;th&gt;Do this&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Open a blank tab&lt;/td&gt;
&lt;td&gt;⌘T&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pick what a new tab is for&lt;/td&gt;
&lt;td&gt;+ in the tab bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Close the tab&lt;/td&gt;
&lt;td&gt;⌘W&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reopen the tab you closed&lt;/td&gt;
&lt;td&gt;⇧⌘T&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Close every other tab&lt;/td&gt;
&lt;td&gt;⌥⌘T&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jump to a tab&lt;/td&gt;
&lt;td&gt;⌘1 to ⌘8, ⌘9 for the last&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Drag to reorder. Closing the last tab opens a fresh one instead of quitting. A scratch tab is titled from its first line of code; &lt;strong&gt;Rename…&lt;/strong&gt; sets your own title.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;+&lt;/strong&gt; button asks what the tab is for: Plain JavaScript, Plain TypeScript, React, Vue, Solid or Angular. That sets the language, runtime and framework, installs what's needed and opens starter code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Files
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Open… (⌘O)&lt;/strong&gt;, &lt;strong&gt;Save (⌘S)&lt;/strong&gt; and &lt;strong&gt;Save As… (⇧⌘S)&lt;/strong&gt; work with &lt;code&gt;.js&lt;/code&gt;, &lt;code&gt;.jsx&lt;/code&gt;, &lt;code&gt;.ts&lt;/code&gt;, &lt;code&gt;.tsx&lt;/code&gt;, &lt;code&gt;.mjs&lt;/code&gt;, &lt;code&gt;.cjs&lt;/code&gt;, &lt;code&gt;.mts&lt;/code&gt;, &lt;code&gt;.cts&lt;/code&gt;, &lt;code&gt;.json&lt;/code&gt; and &lt;code&gt;.txt&lt;/code&gt;. Drop files on the window and each opens in a new tab. From a terminal, &lt;code&gt;jslab file.ts&lt;/code&gt; does the same.&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%2Ffrvngn1igjmd150ygy73.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%2Ffrvngn1igjmd150ygy73.png" alt="A JSLab window with three tabs open, &amp;quot;Format a relative date&amp;quot;, &amp;quot;Retry with backoff&amp;quot; and &amp;quot;Order totals by region&amp;quot;, each titled from its first line of code, above the start of a TypeScript orders example." width="720" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few guard rails:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSLab asks before it opens or pastes more than 5 MB, and won't open a file over 50 MB.&lt;/li&gt;
&lt;li&gt;Closing a tab with unsaved changes asks whether to save. &lt;strong&gt;Confirm Close&lt;/strong&gt; (Settings → General) asks before closing any tab.&lt;/li&gt;
&lt;li&gt;A saved tab's right-click menu has &lt;strong&gt;Copy Path&lt;/strong&gt; and &lt;strong&gt;Reveal in Finder&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JSLab launches Nov 15. The full page: &lt;a href="https://js-lab.app/docs/first-tab" rel="noopener noreferrer"&gt;https://js-lab.app/docs/first-tab&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>productivity</category>
      <category>macos</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Prettier on demand, on run, on save</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Wed, 11 Nov 2026 00:47:33 +0000</pubDate>
      <link>https://dev.to/jslab/prettier-on-demand-on-run-on-save-m57</link>
      <guid>https://dev.to/jslab/prettier-on-demand-on-run-on-save-m57</guid>
      <description>&lt;p&gt;&lt;em&gt;JSLab feature notes: one docs page, explained. Today: &lt;a href="https://js-lab.app/docs/formatting" rel="noopener noreferrer"&gt;Formatting&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Scratch code is written fast and formatted never. JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS, formats with Prettier, so the mess you typed at speed can look like code before you paste it anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  On demand
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;⌥⇧F (Format Code)&lt;/strong&gt; formats the current tab. It's also in Actions → Format Code and the command palette.&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="n"&gt;order&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"A-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"B-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;paid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One ⌥⇧F later:&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="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"A-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"B-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;paid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;qty&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="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The format lands as &lt;strong&gt;one undo step&lt;/strong&gt;, and JSLab applies minimal edits instead of replacing the whole buffer, so your folds, scroll position and cursor stay where they were.&lt;/p&gt;

&lt;h2&gt;
  
  
  On run, on save
&lt;/h2&gt;

&lt;p&gt;Two settings, both off by default:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Format on Run&lt;/strong&gt; (Settings → General) formats before each run, unless you're typing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Format on Save&lt;/strong&gt; (Settings → Editor) formats when you save a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The options
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Settings → Formatting&lt;/strong&gt; holds every Prettier option JSLab supports, with Prettier's usual defaults:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Print Width&lt;/td&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tab Width&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Semicolons&lt;/td&gt;
&lt;td&gt;On&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Single Quotes&lt;/td&gt;
&lt;td&gt;Off&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Trailing Commas&lt;/td&gt;
&lt;td&gt;All&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arrow Parens&lt;/td&gt;
&lt;td&gt;Always&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Plus Use Tabs, Quote Props, JSX Single Quotes, Bracket Spacing and Bracket Same Line. Print Width goes from 20 to 320, and Tab Width from 1 to 16.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it can't parse
&lt;/h2&gt;

&lt;p&gt;If Prettier can't parse the tab, the status bar says &lt;strong&gt;Couldn't format&lt;/strong&gt;, with Prettier's message, and your code is left as it was. A format that takes too long is stopped and the formatter restarts, so a giant paste can't hang the editor.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. The full page: &lt;a href="https://js-lab.app/docs/formatting" rel="noopener noreferrer"&gt;https://js-lab.app/docs/formatting&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>prettier</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>What your TypeScript becomes when it runs</title>
      <dc:creator>JSLab</dc:creator>
      <pubDate>Tue, 10 Nov 2026 16:00:54 +0000</pubDate>
      <link>https://dev.to/jslab/what-your-typescript-becomes-when-it-runs-5ei3</link>
      <guid>https://dev.to/jslab/what-your-typescript-becomes-when-it-runs-5ei3</guid>
      <description>&lt;p&gt;TypeScript has a simple story: types are checked, then erased, and what runs is JavaScript. That's true for almost every line you write. The exceptions are worth knowing, because they're the lines that behave differently from how they look.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that disappears
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Config&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./config"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&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="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;satisfies&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;boolean&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;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`Hi ${u.name}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it through any TypeScript compiler and you get, give or take whitespace:&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="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&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="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&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="sb"&gt;`Hi ${u.name}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interface, the &lt;code&gt;import type&lt;/code&gt;, the annotations, &lt;code&gt;as&lt;/code&gt; and &lt;code&gt;satisfies&lt;/code&gt;: all gone. None of it exists at runtime, which is why &lt;code&gt;as User[]&lt;/code&gt; can't check anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that doesn't
&lt;/h2&gt;

&lt;p&gt;A few TypeScript features generate JavaScript of their own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enums&lt;/strong&gt; become an object, built by a small function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Low&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;High&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;turns into roughly:&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;var&lt;/span&gt; &lt;span class="nc"&gt;Level&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="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Low"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Low"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"High"&lt;/span&gt;&lt;span class="p"&gt;]&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="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"High"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's why &lt;code&gt;Level[0]&lt;/code&gt; is &lt;code&gt;"Low"&lt;/code&gt;: a numeric enum maps both ways. The exact shape varies by compiler; the idea doesn't.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameter properties&lt;/strong&gt; become assignments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&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="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Point&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="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Namespaces&lt;/strong&gt; with values become an object built by a function too, like enums.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters now
&lt;/h2&gt;

&lt;p&gt;Node can run &lt;code&gt;.ts&lt;/code&gt; files by stripping types, without a compile step. Stripping only works for syntax that can be erased. An enum or a parameter property needs code generated, so Node's default mode refuses it.&lt;/p&gt;

&lt;p&gt;TypeScript 5.8 added a flag for exactly this: &lt;code&gt;erasableSyntaxOnly&lt;/code&gt; reports an error on enums, parameter properties and value namespaces, so your code stays strippable. The usual replacement for an enum is a plain object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Low&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="nc"&gt;High&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="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Seeing it for your own code
&lt;/h2&gt;

&lt;p&gt;You learn this fastest by looking at the output. I do it in JSLab, a JavaScript &amp;amp; TypeScript scratchpad for macOS: &lt;strong&gt;Actions → Show Transpiled Output&lt;/strong&gt; puts the JavaScript your tab actually runs in the side bar, next to your code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It refreshes on each run, and marks itself &lt;strong&gt;Stale&lt;/strong&gt; once you've edited past the run it shows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hide instrumentation&lt;/strong&gt; switches between the code exactly as it runs and the code without JSLab's own additions for Auto Log, logpoints and loop protection. Turn it off once; it's a good look at how those features work.&lt;/li&gt;
&lt;li&gt;Which syntax proposals the transform accepts, such as the pipeline operator, is set in &lt;strong&gt;Settings → Build&lt;/strong&gt;. Decorators work as they are.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Types are checked in the editor and stripped when the code runs, so a type error is an underline, never a failed run.&lt;/p&gt;

&lt;p&gt;JSLab launches Nov 15. Show Transpiled Output: &lt;a href="https://js-lab.app/docs/editor" rel="noopener noreferrer"&gt;https://js-lab.app/docs/editor&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
