<?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: axtk</title>
    <description>The latest articles on DEV Community by axtk (@axtk).</description>
    <link>https://dev.to/axtk</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%2F2968141%2F7d1d7dd8-0cc8-4e4c-a8ef-11bfd3ea6505.png</url>
      <title>DEV Community: axtk</title>
      <link>https://dev.to/axtk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/axtk"/>
    <language>en</language>
    <item>
      <title>Prefer let over const (not the other way around)</title>
      <dc:creator>axtk</dc:creator>
      <pubDate>Sat, 03 May 2025 15:33:39 +0000</pubDate>
      <link>https://dev.to/axtk/prefer-let-over-const-not-the-other-way-around-4jin</link>
      <guid>https://dev.to/axtk/prefer-let-over-const-not-the-other-way-around-4jin</guid>
      <description>&lt;p&gt;Preferring &lt;code&gt;const&lt;/code&gt; over &lt;code&gt;let&lt;/code&gt; has become sort of mainstream (often enforced with a &lt;a href="https://eslint.org/docs/latest/rules/prefer-const" rel="noopener noreferrer"&gt;linting rule&lt;/a&gt;), but that actually breaks their semantics and discards the developer's intention.&lt;/p&gt;

&lt;p&gt;Semantically, &lt;code&gt;const&lt;/code&gt; is a developer's way to communicate to other devs that the variable &lt;em&gt;shouldn't be&lt;/em&gt; changed, not that it &lt;em&gt;isn't&lt;/em&gt; changed in the current version of code. The developer's intention that a variable shouldn't be changed can't be inferred solely from static analysis of the code, unlike the variable's property of currently being unchanged.&lt;/p&gt;

&lt;p&gt;Automatically replacing &lt;code&gt;let&lt;/code&gt; with &lt;code&gt;const&lt;/code&gt; results in the loss of the distinction between constants specifically marked as never-to-be-changed by a developer with variables that happen to be unchanged, but not inherently unchangeable.&lt;/p&gt;

&lt;p&gt;For currently unchanged variables, the &lt;em&gt;prefer const&lt;/em&gt; rule also introduces an unnecessary diff when the variable has to be reassigned in a later code change, by converting &lt;code&gt;const&lt;/code&gt; to &lt;code&gt;let&lt;/code&gt;. And since any &lt;code&gt;const&lt;/code&gt; can now be easily switched to &lt;code&gt;let&lt;/code&gt;, devs are deprived of a simple way to convey the meaning that a variable is not supposed to be modified.&lt;/p&gt;

&lt;p&gt;To fix this, &lt;code&gt;let&lt;/code&gt; should be preferred over &lt;code&gt;const&lt;/code&gt; by default, with &lt;code&gt;const&lt;/code&gt; reserved to things that devs decide shouldn't be changed.&lt;/p&gt;

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