<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ValPetal Tech Labs</title>
    <description>The latest articles on Forem by ValPetal Tech Labs (@valpetaltechlabs).</description>
    <link>https://forem.com/valpetaltechlabs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2718253%2Fe51e870c-6bd0-4c99-a5d1-41377671979d.png</url>
      <title>Forem: ValPetal Tech Labs</title>
      <link>https://forem.com/valpetaltechlabs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/valpetaltechlabs"/>
    <language>en</language>
    <item>
      <title>Javascript Question of the Day #30 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Wed, 11 Mar 2026 08:01:19 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-30-talkoverflow-3755</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-30-talkoverflow-3755</guid>
      <description>&lt;p&gt;Why Array.prototype.sort mutates in place and returns the same reference — the silent aliasing bug that corrupts your "original" array after sorting in production JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:groupPost:4314060-7437404916748410880/" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;88&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ranked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&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="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ranked&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ranked&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ranked&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt; &lt;code&gt;sort()&lt;/code&gt; is one of the few array methods that does not return a new array. Think carefully about what &lt;code&gt;ranked&lt;/code&gt; actually is before the push happens.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: A) 6, true, 95&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
true
95
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This quiz exposes one of the most common and silent bugs in JavaScript array handling: &lt;strong&gt;&lt;code&gt;Array.prototype.sort&lt;/code&gt; sorts the array in place and returns a reference to the same array&lt;/strong&gt; — not a new one. This behavior is fundamentally different from the functional array methods developers use daily (&lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;flat&lt;/code&gt;), all of which return new arrays and leave the original untouched.&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;scores.sort(...)&lt;/code&gt; is called, two things happen simultaneously:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The original &lt;code&gt;scores&lt;/code&gt; array is mutated — its elements are reordered in descending order.&lt;/li&gt;
&lt;li&gt;The return value is the exact same array object that was sorted — not a copy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Assigning the return value to &lt;code&gt;ranked&lt;/code&gt; does not produce a second array. &lt;code&gt;ranked&lt;/code&gt; is just another name for &lt;code&gt;scores&lt;/code&gt;. They are the same object in memory. Any mutation applied to one is immediately visible through the other — including the &lt;code&gt;scores.push(70)&lt;/code&gt; that comes next.&lt;/p&gt;

&lt;p&gt;This is why &lt;code&gt;ranked.length&lt;/code&gt; is &lt;code&gt;6&lt;/code&gt; instead of &lt;code&gt;5&lt;/code&gt;, &lt;code&gt;ranked === scores&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; (strict equality checks object identity), and &lt;code&gt;ranked[0]&lt;/code&gt; is &lt;code&gt;95&lt;/code&gt; (the highest score after the descending sort).&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const scores = [85, 92, 78, 95, 88]&lt;/code&gt;&lt;/strong&gt; — Creates an array of five numbers. Let's call this Object A.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const ranked = scores.sort((a, b) =&amp;gt; b - a)&lt;/code&gt;&lt;/strong&gt; — Sorts Object A in place in descending order: &lt;code&gt;[95, 92, 88, 85, 78]&lt;/code&gt;. &lt;code&gt;sort()&lt;/code&gt; returns a reference to Object A. &lt;code&gt;ranked&lt;/code&gt; now points to the same Object A. There is still only &lt;strong&gt;one array&lt;/strong&gt; in memory. Both &lt;code&gt;scores&lt;/code&gt; and &lt;code&gt;ranked&lt;/code&gt; are aliases for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;scores.push(70)&lt;/code&gt;&lt;/strong&gt; — Appends &lt;code&gt;70&lt;/code&gt; to Object A. Since &lt;code&gt;ranked&lt;/code&gt; points to the same Object A, &lt;code&gt;ranked&lt;/code&gt; is now &lt;code&gt;[95, 92, 88, 85, 78, 70]&lt;/code&gt; and its &lt;code&gt;length&lt;/code&gt; is &lt;code&gt;6&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(ranked.length)&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;ranked&lt;/code&gt; is Object A, which now has 6 elements. Prints &lt;code&gt;6&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(ranked === scores)&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;===&lt;/code&gt; on objects checks reference identity. &lt;code&gt;ranked&lt;/code&gt; and &lt;code&gt;scores&lt;/code&gt; point to the same object. Prints &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(ranked[0])&lt;/code&gt;&lt;/strong&gt; — The first element of the descending-sorted array is &lt;code&gt;95&lt;/code&gt;. Prints &lt;code&gt;95&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; The developer's mental model is reasonable — in most modern JavaScript, array transformation methods return new arrays. &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;reduce&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, &lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;flat&lt;/code&gt;, &lt;code&gt;flatMap&lt;/code&gt; — all of these give you a new array and preserve the original. &lt;code&gt;sort&lt;/code&gt; (and &lt;code&gt;reverse&lt;/code&gt; and &lt;code&gt;splice&lt;/code&gt;) are the legacy exceptions that mutate in place. The return value of &lt;code&gt;sort()&lt;/code&gt; looks like a "sorted copy" in assignment syntax (&lt;code&gt;const ranked = scores.sort(...)&lt;/code&gt;), but it's actually the sorted original handed back.&lt;/p&gt;

&lt;p&gt;Since ES2023, &lt;code&gt;Array.prototype.toSorted()&lt;/code&gt; provides a non-mutating alternative that genuinely returns a new sorted array. The asymmetry between &lt;code&gt;sort&lt;/code&gt; and &lt;code&gt;toSorted&lt;/code&gt; exists precisely because the original &lt;code&gt;sort&lt;/code&gt; behavior is a well-known footgun.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Real-World Impact
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Where this appears:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Table sorting in dashboards:&lt;/strong&gt; A developer fetches a list of records, stores it as &lt;code&gt;originalData&lt;/code&gt;, and sorts a "view" copy for display: &lt;code&gt;const sorted = originalData.sort(compareFn)&lt;/code&gt;. When the user resets filters, &lt;code&gt;originalData&lt;/code&gt; is already mutated and sorted — the "original" order is gone. The reset button does nothing meaningful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Leaderboard / ranking features:&lt;/strong&gt; A game or analytics app maintains a live scores array. A function computes &lt;code&gt;const topFive = scores.sort((a, b) =&amp;gt; b - a).slice(0, 5)&lt;/code&gt;. The &lt;code&gt;.sort()&lt;/code&gt; mutates the live &lt;code&gt;scores&lt;/code&gt; array, causing all downstream consumers of &lt;code&gt;scores&lt;/code&gt; to see it in sorted order rather than insertion order (e.g., recent-activity feeds, historical charts).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pagination logic:&lt;/strong&gt; An app applies &lt;code&gt;.sort()&lt;/code&gt; to paginate data on the frontend. The &lt;code&gt;allItems&lt;/code&gt; array used by the page-count calculation is now in sorted order, which may not matter for counts — but if another component iterates &lt;code&gt;allItems&lt;/code&gt; expecting insertion order (e.g., to highlight "newly added" items), it silently gets the wrong order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test isolation failures:&lt;/strong&gt; A test creates a shared fixture array, sorts it in one test, then expects it to be in original order in a later test. Because &lt;code&gt;sort&lt;/code&gt; mutated in place, subsequent tests fail inconsistently depending on execution order — a classic shared-mutable-state test pollution scenario.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Array.prototype.sort&lt;/code&gt; mutates the original array and returns the same reference.&lt;/strong&gt; Unlike &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt;, and &lt;code&gt;concat&lt;/code&gt;, &lt;code&gt;sort&lt;/code&gt; does not create a new array. Assigning the return value to a new variable creates an alias, not a copy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Always copy before sorting if you need the original order preserved.&lt;/strong&gt; Use &lt;code&gt;[...arr].sort(compareFn)&lt;/code&gt;, &lt;code&gt;arr.slice().sort(compareFn)&lt;/code&gt;, or &lt;code&gt;Array.from(arr).sort(compareFn)&lt;/code&gt; to sort a copy. This is an extremely common defensive pattern in production code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Array.prototype.toSorted()&lt;/code&gt; (ES2023) is the non-mutating alternative.&lt;/strong&gt; &lt;code&gt;arr.toSorted(compareFn)&lt;/code&gt; returns a new sorted array and leaves &lt;code&gt;arr&lt;/code&gt; untouched. Prefer it in new code when targeting modern environments. Similarly, &lt;code&gt;toReversed()&lt;/code&gt; and &lt;code&gt;toSpliced()&lt;/code&gt; are the non-mutating versions of &lt;code&gt;reverse&lt;/code&gt; and &lt;code&gt;splice&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Array.prototype.reverse&lt;/code&gt; has the same mutation behavior.&lt;/strong&gt; It reorders elements in place and returns the same array. &lt;code&gt;const reversed = arr.reverse()&lt;/code&gt; is an alias, not a copy. &lt;code&gt;arr.toReversed()&lt;/code&gt; is the safe alternative.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strict equality (&lt;code&gt;===&lt;/code&gt;) on objects checks identity, not structure.&lt;/strong&gt; &lt;code&gt;ranked === scores&lt;/code&gt; being &lt;code&gt;true&lt;/code&gt; is the diagnostic tell. When two variables point to the same object, mutations through either variable affect both. If you suspect aliasing, &lt;code&gt;===&lt;/code&gt; confirms it; use it in debugging before reaching for deep-equality utilities.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>help</category>
    </item>
    <item>
      <title>Question of the Day #23 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Thu, 26 Feb 2026 13:19:05 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/question-of-the-day-23-talkoverflow-1i8d</link>
      <guid>https://forem.com/valpetaltechlabs/question-of-the-day-23-talkoverflow-1i8d</guid>
      <description>&lt;p&gt;Why parseInt(0.0000005) returns 5: The dangerous interaction between scientific notation and string coercion.&lt;/p&gt;

&lt;p&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:groupPost:8571393-7432774837908979712/" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;

&lt;p&gt;What will be the output / behavior?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0000005&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hint: &lt;code&gt;parseInt&lt;/code&gt; converts its first argument to a string before parsing. How does JavaScript represent very small numbers as strings?&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;The correct output is &lt;strong&gt;5&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This behavior is a classic example of &lt;strong&gt;implicit type coercion&lt;/strong&gt; combined with &lt;strong&gt;scientific notation&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Implicit String Conversion:&lt;/strong&gt; The &lt;code&gt;parseInt&lt;/code&gt; function expects its first argument to be a string. If you pass a number, JavaScript first converts it to a string using the abstract &lt;code&gt;ToString&lt;/code&gt; operation.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Scientific Notation:&lt;/strong&gt; For very small numbers (specifically, those with more than 6 leading zeros after the decimal point), JavaScript's default string representation uses exponential notation.

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;String(0.000005)&lt;/code&gt; is &lt;code&gt;"0.000005"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;String(0.0000005)&lt;/code&gt; is &lt;code&gt;"5e-7"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Parsing Logic:&lt;/strong&gt; &lt;code&gt;parseInt&lt;/code&gt; parses the string from left to right. It stops parsing as soon as it encounters a character that is not a valid digit for the specified radix (default is 10).

&lt;ul&gt;
&lt;li&gt;  It sees &lt;code&gt;"5"&lt;/code&gt; (valid digit).&lt;/li&gt;
&lt;li&gt;  It sees &lt;code&gt;"e"&lt;/code&gt; (invalid digit).&lt;/li&gt;
&lt;li&gt;  It stops and returns the integer parsed so far: &lt;code&gt;5&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0000005&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// value is stored as a number&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Step 1: value is coerced to string -&amp;gt; "5e-7"&lt;/span&gt;
&lt;span class="c1"&gt;// Step 2: parseInt("5e-7") starts parsing&lt;/span&gt;
&lt;span class="c1"&gt;// Step 3: Parses '5', stops at 'e'&lt;/span&gt;
&lt;span class="c1"&gt;// Result: 5&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;parseInt&lt;/code&gt; is for strings.&lt;/strong&gt; Avoid using it on values that are already numbers.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Know your string representations.&lt;/strong&gt; JavaScript automatically switches to scientific notation for numbers smaller than &lt;code&gt;1e-6&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Use Math methods for numbers.&lt;/strong&gt; &lt;code&gt;Math.trunc()&lt;/code&gt; is the safer, semantic equivalent for "drop the decimal part" on numeric values.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>[Talk::Overflow #24] Replay London 2025 — Modernise</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Wed, 25 Feb 2026 12:11:03 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/talkoverflow-19-replay-london-2025-modernise-4oic</link>
      <guid>https://forem.com/valpetaltechlabs/talkoverflow-19-replay-london-2025-modernise-4oic</guid>
      <description>&lt;p&gt;Replay 2025 took place March 3–5 in London under the banner "Modernise," bringing together engineers from fintech, logistics, pharma, telecom, and platform engineering to share how they're building production systems on top of Temporal. This wasn't a product launch event disguised as a conference. It was three days of teams who've already shipped talking about what worked, what broke, and what they'd do differently.&lt;/p&gt;

&lt;p&gt;The timing matters. Distributed systems are no longer optional — they're the default. And with every team running microservices, event-driven pipelines, and now AI agents, the question has shifted from "should we orchestrate?" to "how do we orchestrate without losing our minds?" Replay 2025 answered that question with war stories from companies processing billions in payments, managing millions of IoT devices, and running drug discovery pipelines that used to take days.&lt;/p&gt;

&lt;p&gt;The conference also marked a pivotal moment for Temporal itself: the GA of Nexus for cross-team workflow orchestration, a pre-release Ruby SDK, Worker Versioning APIs, and Temporal Cloud on Google Cloud. These aren't incremental improvements — they're the kind of capabilities that change how you architect systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  Top 5 Talks (Most Impactful by Views)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Durable Execution: This Changes Everything — Tom Wheeler
&lt;/h3&gt;

&lt;p&gt;Tom Wheeler poses a deceptively simple question: "How would you code if your application could not fail?" He contrasts the way senior engineers instinctively design for failure modes — retries, timeouts, partial completions — with how beginners assume the happy path is the only path. The talk builds a compelling case for &lt;strong&gt;Durable Execution&lt;/strong&gt; as a paradigm shift, not just a feature. The practical takeaway: you can write business logic that reads like it runs on a single machine while the runtime handles crashes, restarts, and network partitions transparently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ROJq6_GFbME" rel="noopener noreferrer"&gt;Watch on YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Replay 2025 Keynote Demo: AI Agents Using Temporal
&lt;/h3&gt;

&lt;p&gt;The keynote demo made the strongest case yet for Temporal as infrastructure for &lt;strong&gt;agentic AI&lt;/strong&gt; systems. Rather than hand-waving about the future, the demo showed a working AI agent pipeline built on Temporal, demonstrating how durable execution solves the exact problems that make AI agents unreliable in production: long-running tasks, external API failures, and multi-step reasoning chains that need to recover from partial failures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=YDxAWrIBQNE" rel="noopener noreferrer"&gt;Watch on YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Getting Started with Worker Versioning — Drew Hoskins &amp;amp; Shahab Tajik
&lt;/h3&gt;

&lt;p&gt;The new &lt;strong&gt;Worker Versioning APIs&lt;/strong&gt; solve one of Temporal's biggest operational pain points — deploying changes to long-running workflows without breaking in-flight executions. Assignment rules, redirect rules, and a versioning model that gives teams fine-grained control. For teams running Temporal in production with frequent deployments, this session is required viewing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=rm4BlD9WXqc" rel="noopener noreferrer"&gt;Watch on YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Temporal and Spring Boot — Tihomir Surdilovic
&lt;/h3&gt;

&lt;p&gt;A thorough walkthrough of the &lt;strong&gt;Temporal Spring Boot integration&lt;/strong&gt; nearing GA status. Covers configuration, observability, scaling, and testing — the four pillars that determine whether a framework integration works in production. The testing section alone — workflow replay testing and Activity mocking — is worth the watch for Java teams.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=LRK5S_qDpsg" rel="noopener noreferrer"&gt;Watch on YouTube&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Salesforce: Migrating a Monolithic Cloud — Trevor Grieger &amp;amp; Austin Deal
&lt;/h3&gt;

&lt;p&gt;Migrating &lt;strong&gt;Marketing Cloud&lt;/strong&gt; onto Hyperforce with 1,000+ engineers involved. Temporal powers the cross-substrate migration system with workflow-driven phases and rollback capabilities. Enterprise scale, proven in production. The architectural patterns are applicable far beyond Salesforce's specific use case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=1TDX9WEJRMA" rel="noopener noreferrer"&gt;Watch on YouTube&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The full issue covers all 27 talks with detailed summaries, speaker information, and direct YouTube links.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the complete article on Talk::Overflow:&lt;/strong&gt; &lt;a href="https://talkoverflow.substack.com/p/talkoverflow-19-replay-london-2025" rel="noopener noreferrer"&gt;talkoverflow.substack.com/p/talkoverflow-19-replay-london-2025&lt;/a&gt;&lt;/p&gt;




</description>
      <category>ai</category>
      <category>programming</category>
      <category>beginners</category>
      <category>bestofdev</category>
    </item>
    <item>
      <title>Question of the Day #22 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Wed, 25 Feb 2026 11:42:11 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/question-of-the-day-22-talkoverflow-468h</link>
      <guid>https://forem.com/valpetaltechlabs/question-of-the-day-22-talkoverflow-468h</guid>
      <description>&lt;p&gt;Why a function declaration after a return statement still shadows your outer variable — and how this "dead code" hoisting trap silently breaks state updates in production JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7432379245324058624/" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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;Hint:&lt;/strong&gt; Before any code inside a function runs, the engine has already processed all declarations in the function body — including ones that appear after a &lt;code&gt;return&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: B) 10, 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first &lt;code&gt;console.log&lt;/code&gt; prints &lt;code&gt;10&lt;/code&gt;. The second prints &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This quiz exploits the fact that &lt;strong&gt;function declarations are hoisted to the top of their enclosing function scope&lt;/strong&gt; — even when they appear after a &lt;code&gt;return&lt;/code&gt; statement, where they can never be reached at runtime.&lt;/p&gt;

&lt;p&gt;When the engine enters &lt;code&gt;bar()&lt;/code&gt;, it performs &lt;strong&gt;declaration hoisting&lt;/strong&gt; before executing any code. It finds &lt;code&gt;function x() {}&lt;/code&gt; at the bottom of the function body and creates a local binding &lt;code&gt;x&lt;/code&gt; initialized to that function. This local &lt;code&gt;x&lt;/code&gt; completely &lt;strong&gt;shadows&lt;/strong&gt; the outer &lt;code&gt;var x = 1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At runtime, the function effectively becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;  &lt;span class="c1"&gt;// hoisted function declaration&lt;/span&gt;
  &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="c1"&gt;// reassigns local x to 10&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;           &lt;span class="c1"&gt;// 10&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;x = 10&lt;/code&gt; assignment targets the &lt;strong&gt;local&lt;/strong&gt; &lt;code&gt;x&lt;/code&gt;, not the outer one. The outer &lt;code&gt;x&lt;/code&gt; remains &lt;code&gt;1&lt;/code&gt; throughout.&lt;/p&gt;

&lt;p&gt;This pattern commonly surfaces when developers add utility functions inside other functions during refactoring, not realizing those function names may collide with outer variables.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;var x = 1;&lt;/code&gt;&lt;/strong&gt; — Declares &lt;code&gt;x&lt;/code&gt; in the outer (global/module) scope and initializes it to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;function bar() {&lt;/code&gt;&lt;/strong&gt; — The engine parses the entire body of &lt;code&gt;bar&lt;/code&gt; before executing it. It encounters &lt;code&gt;function x() {}&lt;/code&gt; and hoists it — creating a &lt;strong&gt;local&lt;/strong&gt; binding &lt;code&gt;x&lt;/code&gt; inside &lt;code&gt;bar&lt;/code&gt;, initialized to the function object. This local &lt;code&gt;x&lt;/code&gt; shadows the outer &lt;code&gt;x&lt;/code&gt; for the entire duration of &lt;code&gt;bar&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;x = 10;&lt;/code&gt;&lt;/strong&gt; — This assignment targets the &lt;strong&gt;local&lt;/strong&gt; &lt;code&gt;x&lt;/code&gt; (the hoisted function declaration). The local &lt;code&gt;x&lt;/code&gt; is now &lt;code&gt;10&lt;/code&gt;. The outer &lt;code&gt;x&lt;/code&gt; is untouched.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(x);&lt;/code&gt;&lt;/strong&gt; — Prints &lt;code&gt;10&lt;/code&gt; (the local &lt;code&gt;x&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;return;&lt;/code&gt;&lt;/strong&gt; — Exits &lt;code&gt;bar&lt;/code&gt;. Everything below this line is unreachable at runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;function x() {}&lt;/code&gt;&lt;/strong&gt; — This is a function declaration. Its positional placement after &lt;code&gt;return&lt;/code&gt; is irrelevant — the declaration was already hoisted during the parsing phase. It has no runtime effect here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;bar();&lt;/code&gt;&lt;/strong&gt; — Calls &lt;code&gt;bar&lt;/code&gt;, which logs &lt;code&gt;10&lt;/code&gt; as described above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(x);&lt;/code&gt;&lt;/strong&gt; — Prints the outer &lt;code&gt;x&lt;/code&gt;, which is still &lt;code&gt;1&lt;/code&gt;. The assignment inside &lt;code&gt;bar&lt;/code&gt; never touched it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; Most developers read &lt;code&gt;x = 10&lt;/code&gt; and assume it refers to the outer &lt;code&gt;x&lt;/code&gt; because they don't see any local declaration of &lt;code&gt;x&lt;/code&gt; before the &lt;code&gt;return&lt;/code&gt;. The &lt;code&gt;function x() {}&lt;/code&gt; after &lt;code&gt;return&lt;/code&gt; looks dead — but its &lt;em&gt;declaration&lt;/em&gt; is very much alive due to hoisting.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Function declarations are hoisted regardless of reachability.&lt;/strong&gt; A &lt;code&gt;function&lt;/code&gt; declaration after &lt;code&gt;return&lt;/code&gt;, inside a never-entered &lt;code&gt;if&lt;/code&gt; branch, or at the end of a thousand-line function is still hoisted to the top of its enclosing scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hoisted function declarations create local bindings that shadow outer variables.&lt;/strong&gt; Unlike a simple &lt;code&gt;x = 10&lt;/code&gt; assignment (which would target the outer scope), the presence of &lt;code&gt;function x() {}&lt;/code&gt; anywhere in the function body creates a &lt;em&gt;local&lt;/em&gt; &lt;code&gt;x&lt;/code&gt; that captures all references to &lt;code&gt;x&lt;/code&gt; within that function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;"Dead code" can have live side effects.&lt;/strong&gt; In JavaScript, unreachable function declarations still participate in scope creation. Never assume code after &lt;code&gt;return&lt;/code&gt; is safe to ignore during code review.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;const&lt;/code&gt;/&lt;code&gt;let&lt;/code&gt; and arrow functions to avoid this class of bugs.&lt;/strong&gt; &lt;code&gt;const x = () =&amp;gt; {}&lt;/code&gt; is not hoisted and will throw a &lt;code&gt;ReferenceError&lt;/code&gt; if accessed before its declaration, making the bug immediately visible instead of silent.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Linting rules like &lt;code&gt;no-unreachable&lt;/code&gt; and &lt;code&gt;no-shadow&lt;/code&gt; catch this pattern.&lt;/strong&gt; Enable them to flag function declarations after &lt;code&gt;return&lt;/code&gt; statements and variable name collisions across scopes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Javascript Question of the Day #21 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Tue, 24 Feb 2026 11:17:06 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-21-talkoverflow-bc4</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-21-talkoverflow-bc4</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5tvpo4phj2nalz5lw0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5tvpo4phj2nalz5lw0q.png" alt="Javascript Logo" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7431997142032080897/" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; makes a sound&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;constructor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;constructor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;Object&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;Hint:&lt;/strong&gt; When you replace the entire prototype object with a plain object literal, think about what built-in property the original prototype had that the new one does not.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: A) Speaks, false, true, true&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rex makes a sound
false
true
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;Every function in JavaScript is automatically given a &lt;code&gt;prototype&lt;/code&gt; object that contains a single non-enumerable property: &lt;code&gt;constructor&lt;/code&gt;, pointing back to the function itself. When you &lt;strong&gt;replace&lt;/strong&gt; the entire &lt;code&gt;prototype&lt;/code&gt; with a new object literal (&lt;code&gt;Animal.prototype = { ... }&lt;/code&gt;), that replacement object is just a plain &lt;code&gt;Object&lt;/code&gt; — its &lt;code&gt;constructor&lt;/code&gt; property is inherited from &lt;code&gt;Object.prototype&lt;/code&gt; and points to &lt;code&gt;Object&lt;/code&gt;, not &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Meanwhile, the &lt;code&gt;instanceof&lt;/code&gt; operator doesn't care about the &lt;code&gt;constructor&lt;/code&gt; property at all. It walks the internal &lt;code&gt;[[Prototype]]&lt;/code&gt; chain of the left-hand operand and checks whether the right-hand operand's current &lt;code&gt;.prototype&lt;/code&gt; appears anywhere in that chain. Since &lt;code&gt;dog.__proto__&lt;/code&gt; is the same object as &lt;code&gt;Animal.prototype&lt;/code&gt; (the replacement), &lt;code&gt;dog instanceof Animal&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; — even though &lt;code&gt;dog.constructor&lt;/code&gt; is &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This creates a dangerous inconsistency: &lt;code&gt;instanceof&lt;/code&gt; says one thing, &lt;code&gt;constructor&lt;/code&gt; says another.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;function Animal(name) { this.name = name; }&lt;/code&gt;&lt;/strong&gt; — Declares a constructor function. At this point, &lt;code&gt;Animal.prototype&lt;/code&gt; is automatically created with a &lt;code&gt;constructor&lt;/code&gt; property that references &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Animal.prototype = { speak() { ... } }&lt;/code&gt;&lt;/strong&gt; — Completely replaces the original &lt;code&gt;Animal.prototype&lt;/code&gt; with a new object literal. This new object has &lt;code&gt;speak&lt;/code&gt; as an own method, but it does &lt;strong&gt;not&lt;/strong&gt; have a &lt;code&gt;constructor&lt;/code&gt; property pointing to &lt;code&gt;Animal&lt;/code&gt;. Its prototype is &lt;code&gt;Object.prototype&lt;/code&gt;, so &lt;code&gt;constructor&lt;/code&gt; resolves to &lt;code&gt;Object.prototype.constructor&lt;/code&gt;, which is &lt;code&gt;Object&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const dog = new Animal('Rex')&lt;/code&gt;&lt;/strong&gt; — Creates a new instance. The &lt;code&gt;new&lt;/code&gt; operator sets &lt;code&gt;dog.__proto__&lt;/code&gt; to the current value of &lt;code&gt;Animal.prototype&lt;/code&gt; (the replacement object). &lt;code&gt;dog&lt;/code&gt; gets an own property &lt;code&gt;name: 'Rex'&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(dog.speak())&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;dog&lt;/code&gt; has no own &lt;code&gt;speak&lt;/code&gt; method, so JavaScript walks to &lt;code&gt;dog.__proto__&lt;/code&gt; (the replacement prototype) and finds &lt;code&gt;speak&lt;/code&gt;. Calls it with &lt;code&gt;this&lt;/code&gt; bound to &lt;code&gt;dog&lt;/code&gt;. Prints &lt;code&gt;Rex makes a sound&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(dog.constructor === Animal)&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;dog&lt;/code&gt; has no own &lt;code&gt;constructor&lt;/code&gt;. Walks to &lt;code&gt;dog.__proto__&lt;/code&gt; (the replacement object). That object also has no own &lt;code&gt;constructor&lt;/code&gt;. Walks to &lt;code&gt;Object.prototype&lt;/code&gt;, which has &lt;code&gt;constructor: Object&lt;/code&gt;. So &lt;code&gt;dog.constructor&lt;/code&gt; is &lt;code&gt;Object&lt;/code&gt;, not &lt;code&gt;Animal&lt;/code&gt;. Prints &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(dog instanceof Animal)&lt;/code&gt;&lt;/strong&gt; — The &lt;code&gt;instanceof&lt;/code&gt; operator checks: does &lt;code&gt;Animal.prototype&lt;/code&gt; exist anywhere in &lt;code&gt;dog&lt;/code&gt;'s &lt;code&gt;[[Prototype]]&lt;/code&gt; chain? &lt;code&gt;dog.__proto__&lt;/code&gt; is exactly &lt;code&gt;Animal.prototype&lt;/code&gt;. Prints &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(dog.constructor === Object)&lt;/code&gt;&lt;/strong&gt; — As established, &lt;code&gt;dog.constructor&lt;/code&gt; resolves to &lt;code&gt;Object.prototype.constructor&lt;/code&gt;, which is &lt;code&gt;Object&lt;/code&gt;. Prints &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; Developers often treat &lt;code&gt;constructor&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt; as two views of the same relationship. They aren't. &lt;code&gt;instanceof&lt;/code&gt; checks the live prototype chain linkage. &lt;code&gt;constructor&lt;/code&gt; is just a regular property that can be lost, overwritten, or inherited from the wrong place. Replacing the entire prototype object severs the &lt;code&gt;constructor&lt;/code&gt; link while leaving &lt;code&gt;instanceof&lt;/code&gt; intact.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Replacing &lt;code&gt;Fn.prototype&lt;/code&gt; entirely destroys the &lt;code&gt;constructor&lt;/code&gt; link.&lt;/strong&gt; The new object literal inherits &lt;code&gt;constructor&lt;/code&gt; from &lt;code&gt;Object.prototype&lt;/code&gt;, which is &lt;code&gt;Object&lt;/code&gt;. Always restore it: &lt;code&gt;Animal.prototype.constructor = Animal&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;instanceof&lt;/code&gt; and &lt;code&gt;constructor&lt;/code&gt; check different things.&lt;/strong&gt; &lt;code&gt;instanceof&lt;/code&gt; walks the &lt;code&gt;[[Prototype]]&lt;/code&gt; chain looking for a specific prototype object. &lt;code&gt;constructor&lt;/code&gt; is a plain property subject to normal prototype lookup — it can point anywhere.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Augment prototypes instead of replacing them.&lt;/strong&gt; Use &lt;code&gt;Animal.prototype.speak = function() { ... }&lt;/code&gt; to add methods without losing &lt;code&gt;constructor&lt;/code&gt;. If you must replace the prototype, always add &lt;code&gt;constructor&lt;/code&gt; back.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ES6 classes handle this correctly.&lt;/strong&gt; Class syntax never replaces the prototype object — it augments it. This is one of the subtle safety improvements that classes provide over manual constructor functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Never rely on &lt;code&gt;constructor&lt;/code&gt; for type checking in production.&lt;/strong&gt; Use &lt;code&gt;instanceof&lt;/code&gt;, &lt;code&gt;Symbol.hasInstance&lt;/code&gt;, or explicit type tags instead. Treat &lt;code&gt;constructor&lt;/code&gt; as an informational convenience, not a guarantee.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>interview</category>
    </item>
    <item>
      <title>Javascript Question of the Day #20 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Fri, 20 Feb 2026 10:02:33 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-20-talkoverflow-4k3b</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-20-talkoverflow-4k3b</guid>
      <description>&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:groupPost:8571393-7430550021076582400/" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;notifications&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="nx"&gt;alice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasOwnProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;settings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;bob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;settings&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;Hint:&lt;/strong&gt; When you write &lt;code&gt;alice.settings.theme = 'dark'&lt;/code&gt;, ask yourself: are you creating a new property on &lt;code&gt;alice&lt;/code&gt;, or reaching through the prototype chain to mutate something shared?&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: A) dark, false, true&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dark
false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;JavaScript's prototype chain has an asymmetry that trips up even experienced developers: &lt;strong&gt;reading&lt;/strong&gt; a property walks up the prototype chain, but &lt;strong&gt;writing&lt;/strong&gt; a property creates it directly on the instance — &lt;em&gt;unless&lt;/em&gt; the write is a nested property access on a reference type.&lt;/p&gt;

&lt;p&gt;When you write &lt;code&gt;alice.settings.theme = 'dark'&lt;/code&gt;, JavaScript first &lt;strong&gt;reads&lt;/strong&gt; &lt;code&gt;alice.settings&lt;/code&gt;. Since &lt;code&gt;alice&lt;/code&gt; has no own &lt;code&gt;settings&lt;/code&gt; property, the engine walks up the prototype chain and finds the &lt;code&gt;settings&lt;/code&gt; object on &lt;code&gt;User.prototype&lt;/code&gt;. It returns a &lt;strong&gt;reference&lt;/strong&gt; to that shared object. Then it sets &lt;code&gt;.theme = 'dark'&lt;/code&gt; on that shared object — mutating the prototype's &lt;code&gt;settings&lt;/code&gt; in place.&lt;/p&gt;

&lt;p&gt;This is fundamentally different from &lt;code&gt;alice.settings = { theme: 'dark' }&lt;/code&gt;, which &lt;em&gt;would&lt;/em&gt; create a new own property on &lt;code&gt;alice&lt;/code&gt; via the prototype chain's write semantics. The distinction is between a &lt;strong&gt;simple assignment&lt;/strong&gt; (which shadows on the instance) and a &lt;strong&gt;nested property mutation&lt;/strong&gt; (which reads the prototype reference and mutates through it).&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;alice.settings&lt;/code&gt; and &lt;code&gt;bob.settings&lt;/code&gt; both resolve to the exact same object on &lt;code&gt;User.prototype&lt;/code&gt;, mutating it through one instance affects all instances.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;function User(name) { this.name = name; }&lt;/code&gt;&lt;/strong&gt; — A constructor function. When called with &lt;code&gt;new&lt;/code&gt;, it creates an instance and sets the &lt;code&gt;name&lt;/code&gt; property directly on it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;User.prototype.settings = { theme: 'light', notifications: true };&lt;/code&gt;&lt;/strong&gt; — A single &lt;code&gt;settings&lt;/code&gt; object is placed on the prototype. Every instance created from &lt;code&gt;User&lt;/code&gt; will share this exact object reference unless they shadow it with an own property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const alice = new User('Alice')&lt;/code&gt;&lt;/strong&gt; — Creates a new instance. &lt;code&gt;alice&lt;/code&gt; has one own property: &lt;code&gt;name: 'Alice'&lt;/code&gt;. It has no own &lt;code&gt;settings&lt;/code&gt; property — it inherits &lt;code&gt;settings&lt;/code&gt; from &lt;code&gt;User.prototype&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const bob = new User('Bob')&lt;/code&gt;&lt;/strong&gt; — Same structure. &lt;code&gt;bob&lt;/code&gt; inherits the same &lt;code&gt;settings&lt;/code&gt; object from the same prototype.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;alice.settings.theme = 'dark'&lt;/code&gt;&lt;/strong&gt; — This is the critical line. JavaScript evaluates this as two operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read &lt;code&gt;alice.settings&lt;/code&gt;:&lt;/strong&gt; &lt;code&gt;alice&lt;/code&gt; has no own &lt;code&gt;settings&lt;/code&gt;, so the engine walks the prototype chain and returns &lt;code&gt;User.prototype.settings&lt;/code&gt; — the shared object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write &lt;code&gt;.theme = 'dark'&lt;/code&gt;:&lt;/strong&gt; Sets the &lt;code&gt;theme&lt;/code&gt; property on the object that was returned. This mutates &lt;code&gt;User.prototype.settings&lt;/code&gt; directly. No new property is created on &lt;code&gt;alice&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(bob.settings.theme)&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;bob.settings&lt;/code&gt; also resolves to &lt;code&gt;User.prototype.settings&lt;/code&gt;, which was just mutated. Prints &lt;code&gt;dark&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(alice.hasOwnProperty('settings'))&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;alice&lt;/code&gt; never received an own &lt;code&gt;settings&lt;/code&gt; property. The mutation went through the prototype reference, not via assignment to &lt;code&gt;alice.settings&lt;/code&gt;. Prints &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(alice.settings === bob.settings)&lt;/code&gt;&lt;/strong&gt; — Both resolve to the same &lt;code&gt;User.prototype.settings&lt;/code&gt; object. Prints &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; &lt;code&gt;alice.settings.theme = 'dark'&lt;/code&gt; looks like it's modifying Alice's settings, but it's actually modifying &lt;em&gt;everyone's&lt;/em&gt; settings. The dot-chain reads the shared prototype reference before performing the write, so the mutation leaks across all instances. This is the difference between &lt;code&gt;obj.prop = value&lt;/code&gt; (shadows on instance) and &lt;code&gt;obj.prop.nested = value&lt;/code&gt; (mutates through prototype).&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Real-World Impact
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Where this appears:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Shared default configuration objects:&lt;/strong&gt; When developers put default config objects on a prototype (or a class's static property) and later mutate nested values, they accidentally change the defaults for all existing and future instances. This is especially common in plugin architectures where a base class provides default options.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Component state in legacy frameworks:&lt;/strong&gt; Before modern frameworks enforced immutability patterns, it was common to put default state objects on prototypes. Mutating nested state on one component instance would silently corrupt all sibling components sharing the same prototype.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ORM/model defaults:&lt;/strong&gt; Data model classes with default nested objects (like &lt;code&gt;permissions: { read: true, write: false }&lt;/code&gt;) on the prototype will share state between model instances if any code mutates a nested field instead of replacing the whole object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixin patterns:&lt;/strong&gt; When using &lt;code&gt;Object.assign&lt;/code&gt; or manual prototype extension to mix in behavior with default option objects, any nested mutation on one instance affects all instances that share the mixin.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Never put mutable reference types (objects, arrays) on a prototype.&lt;/strong&gt; Primitive values on prototypes are safe because assignments always shadow them on the instance. Objects and arrays are shared references, and nested mutations affect all instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;obj.prop.nested = value&lt;/code&gt; reads through the prototype chain, then mutates the shared reference.&lt;/strong&gt; Only a direct assignment like &lt;code&gt;obj.prop = value&lt;/code&gt; creates an own property on the instance and shadows the prototype.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;hasOwnProperty&lt;/code&gt; is your diagnostic tool.&lt;/strong&gt; If &lt;code&gt;instance.hasOwnProperty('prop')&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt;, you're reading from the prototype — and any nested mutation will affect all instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initialize mutable defaults in the constructor, not on the prototype.&lt;/strong&gt; Use &lt;code&gt;this.settings = { ...User.defaults }&lt;/code&gt; or &lt;code&gt;this.settings = Object.assign({}, defaultSettings)&lt;/code&gt; inside the constructor to give each instance its own copy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modern class syntax has the same trap.&lt;/strong&gt; Writing &lt;code&gt;class User { settings = { theme: 'light' } }&lt;/code&gt; is safe (class fields create own properties), but &lt;code&gt;User.prototype.settings = { ... }&lt;/code&gt; after the class definition is not. Know the difference.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript Question of the Day #19 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Thu, 19 Feb 2026 06:11:19 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-19-talkoverflow-kcn</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-19-talkoverflow-kcn</guid>
      <description>&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7430126021078679552" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;9.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4.99&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;5.00&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prices&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="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&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="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mf"&gt;19.98&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;Hint:&lt;/strong&gt; The &lt;code&gt;+&lt;/code&gt; operator has two jobs in JavaScript. What decides which one it picks? Watch what happens to the accumulator the moment it meets a string.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: B) 9.994.995, string, false&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9.994.995
string
false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;+&lt;/code&gt; operator in JavaScript is overloaded: it performs &lt;strong&gt;numeric addition&lt;/strong&gt; when both operands are numbers, but switches to &lt;strong&gt;string concatenation&lt;/strong&gt; the moment &lt;strong&gt;either operand is a string&lt;/strong&gt;. This is defined by the ECMAScript spec's &lt;a href="https://tc39.es/ecma262/#sec-addition-operator-plus" rel="noopener noreferrer"&gt;Abstract Addition&lt;/a&gt; operation — if &lt;code&gt;ToPrimitive&lt;/code&gt; of either side produces a string, both sides are coerced to strings and concatenated.&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;reduce&lt;/code&gt;, the accumulator &lt;code&gt;sum&lt;/code&gt; starts as &lt;code&gt;0&lt;/code&gt; (a number). The first iteration adds &lt;code&gt;9.99&lt;/code&gt;, keeping it numeric. But the second element &lt;code&gt;'4.99'&lt;/code&gt; is a &lt;strong&gt;string&lt;/strong&gt;. At that point, &lt;code&gt;+&lt;/code&gt; switches to concatenation and the accumulator becomes a string. From there, every subsequent &lt;code&gt;+&lt;/code&gt; operation continues to concatenate — even though &lt;code&gt;5.00&lt;/code&gt; is a number, the left operand is already a string, so &lt;code&gt;5.00&lt;/code&gt; is coerced to &lt;code&gt;"5"&lt;/code&gt; and appended.&lt;/p&gt;

&lt;p&gt;This is a textbook silent data corruption bug. No error is thrown, no warning is logged. The code runs to completion, but &lt;code&gt;total&lt;/code&gt; holds a nonsensical string like &lt;code&gt;"9.994.995"&lt;/code&gt; instead of the expected &lt;code&gt;19.98&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const prices = [9.99, '4.99', 5.00]&lt;/code&gt;&lt;/strong&gt; — An array with three elements. The first and third are numbers. The second is a &lt;strong&gt;string&lt;/strong&gt; — this is the trap. In production, this often happens when API responses, form inputs, URL parameters, or &lt;code&gt;localStorage&lt;/code&gt; values return numeric data as strings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;prices.reduce((sum, p) =&amp;gt; sum + p, 0)&lt;/code&gt;&lt;/strong&gt; — Starts reducing with an initial accumulator of &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iteration 1: &lt;code&gt;sum = 0&lt;/code&gt;, &lt;code&gt;p = 9.99&lt;/code&gt;&lt;/strong&gt; — Both are numbers. &lt;code&gt;0 + 9.99 = 9.99&lt;/code&gt;. The accumulator is &lt;code&gt;9.99&lt;/code&gt; (number).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iteration 2: &lt;code&gt;sum = 9.99&lt;/code&gt;, &lt;code&gt;p = '4.99'&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;sum&lt;/code&gt; is a number, &lt;code&gt;p&lt;/code&gt; is a string. The &lt;code&gt;+&lt;/code&gt; operator sees a string on the right side and chooses &lt;strong&gt;concatenation&lt;/strong&gt;. &lt;code&gt;9.99&lt;/code&gt; is coerced to &lt;code&gt;"9.99"&lt;/code&gt;, then concatenated with &lt;code&gt;"4.99"&lt;/code&gt;. The accumulator becomes &lt;code&gt;"9.994.99"&lt;/code&gt; (string). &lt;strong&gt;This is the point of no return.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iteration 3: &lt;code&gt;sum = '9.994.99'&lt;/code&gt;, &lt;code&gt;p = 5.00&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;sum&lt;/code&gt; is now a string. Even though &lt;code&gt;p&lt;/code&gt; is a number, &lt;code&gt;+&lt;/code&gt; still chooses concatenation because the left operand is a string. &lt;code&gt;5.00&lt;/code&gt; is coerced to &lt;code&gt;"5"&lt;/code&gt; (trailing zero is dropped in &lt;code&gt;Number.toString()&lt;/code&gt;). The accumulator becomes &lt;code&gt;"9.994.995"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(total)&lt;/code&gt;&lt;/strong&gt; — Prints &lt;code&gt;9.994.995&lt;/code&gt;. This looks like it could be a decimal number with two dots, but it's actually a string that makes no numeric sense.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(typeof total)&lt;/code&gt;&lt;/strong&gt; — Prints &lt;code&gt;string&lt;/code&gt;. The type has silently changed from number to string mid-reduction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(total === 19.98)&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;"9.994.995" === 19.98&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt;. Strict equality between a string and a number always returns &lt;code&gt;false&lt;/code&gt; without coercion.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; The &lt;code&gt;+&lt;/code&gt; operator's switch from addition to concatenation is &lt;strong&gt;irreversible within the reduce chain&lt;/strong&gt;. Once a single string element flips the accumulator to a string, every subsequent iteration concatenates — even for numeric elements. There is no error, no NaN, no indication that anything went wrong. The code silently produces garbage.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The &lt;code&gt;+&lt;/code&gt; operator picks concatenation over addition if either operand is a string.&lt;/strong&gt; This is asymmetric — once a string appears, the operation flips irreversibly in a reduce chain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Always coerce values before arithmetic.&lt;/strong&gt; Use &lt;code&gt;Number(p)&lt;/code&gt;, &lt;code&gt;parseFloat(p)&lt;/code&gt;, or the unary &lt;code&gt;+p&lt;/code&gt; operator inside your reducer: &lt;code&gt;prices.reduce((sum, p) =&amp;gt; sum + Number(p), 0)&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API data types are a contract, not a guarantee.&lt;/strong&gt; Validate and parse numeric fields at the boundary where external data enters your application — never assume the type is correct.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;This bug produces no errors.&lt;/strong&gt; Unlike most type-related issues, &lt;code&gt;+&lt;/code&gt; coercion never throws. The result is valid JavaScript — it's just not the value you expected. This makes it one of the hardest bugs to catch without explicit type checks or TypeScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;typeof&lt;/code&gt; checks or runtime validation in reducers can act as guardrails.&lt;/strong&gt; In critical financial calculations, consider asserting that every element is a number before reducing, or use a library that enforces decimal arithmetic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript Interview Question of the Day #18 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Mon, 16 Feb 2026 07:45:23 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-interview-question-of-the-day-18-talkoverflow-4f7m</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-interview-question-of-the-day-18-talkoverflow-4f7m</guid>
      <description>&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7429065052089090048" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rejected&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Resolved&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Timeout&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;End&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;promise&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;then:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;catch:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt; Once a promise changes state, can anything else change it again? Pay attention to which calls run synchronously inside the executor versus what gets scheduled.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: A) End, then: Resolved&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;End
then: Resolved
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This quiz tests one of the most fundamental — yet frequently misunderstood — rules of Promises: &lt;strong&gt;a promise can only be settled once&lt;/strong&gt;. Once &lt;code&gt;resolve()&lt;/code&gt; or &lt;code&gt;reject()&lt;/code&gt; is called, the promise transitions from &lt;code&gt;pending&lt;/code&gt; to either &lt;code&gt;fulfilled&lt;/code&gt; or &lt;code&gt;rejected&lt;/code&gt;, and that state is &lt;strong&gt;permanent&lt;/strong&gt;. Any subsequent calls to &lt;code&gt;resolve()&lt;/code&gt; or &lt;code&gt;reject()&lt;/code&gt; are &lt;strong&gt;silently ignored&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Inside the Promise constructor, the executor function runs synchronously. The first &lt;code&gt;setTimeout&lt;/code&gt; schedules a &lt;code&gt;reject()&lt;/code&gt; as a macrotask (it doesn't run yet). Then &lt;code&gt;resolve("Resolved")&lt;/code&gt; executes immediately and settles the promise as fulfilled. The second &lt;code&gt;setTimeout&lt;/code&gt; schedules another &lt;code&gt;resolve()&lt;/code&gt; as a macrotask (also doesn't run yet). Finally, &lt;code&gt;console.log("End")&lt;/code&gt; prints.&lt;/p&gt;

&lt;p&gt;When the macrotasks eventually fire, both the &lt;code&gt;reject()&lt;/code&gt; and the second &lt;code&gt;resolve()&lt;/code&gt; are no-ops — the promise is already settled.&lt;/p&gt;

&lt;p&gt;This means only the &lt;code&gt;.then()&lt;/code&gt; handler fires, and &lt;code&gt;.catch()&lt;/code&gt; never executes.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;new Promise((resolve, reject) =&amp;gt; { ... })&lt;/code&gt;&lt;/strong&gt; — The executor function runs &lt;strong&gt;synchronously&lt;/strong&gt; the moment the Promise is constructed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;setTimeout(() =&amp;gt; reject("Rejected"), 0)&lt;/code&gt;&lt;/strong&gt; — Schedules a callback on the &lt;strong&gt;macrotask queue&lt;/strong&gt;. This does NOT run now. It will run after all synchronous code and microtasks complete.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;resolve("Resolved")&lt;/code&gt;&lt;/strong&gt; — This runs &lt;strong&gt;synchronously&lt;/strong&gt; and immediately settles the promise in the &lt;code&gt;fulfilled&lt;/code&gt; state with the value &lt;code&gt;"Resolved"&lt;/code&gt;. This is the critical moment — the promise is now permanently settled.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;setTimeout(() =&amp;gt; resolve("Timeout"), 0)&lt;/code&gt;&lt;/strong&gt; — Schedules another macrotask. Like the first &lt;code&gt;setTimeout&lt;/code&gt;, this doesn't run yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log("End")&lt;/code&gt;&lt;/strong&gt; — Runs synchronously, prints &lt;code&gt;End&lt;/code&gt;. Note: the executor continues running even after &lt;code&gt;resolve()&lt;/code&gt; is called — &lt;code&gt;resolve()&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; act like &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The executor finishes.&lt;/strong&gt; The Promise constructor returns the (already fulfilled) promise to the variable &lt;code&gt;promise&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;.then(data =&amp;gt; console.log("then:", data))&lt;/code&gt;&lt;/strong&gt; — Since the promise is already fulfilled, this handler is queued as a &lt;strong&gt;microtask&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;.catch(err =&amp;gt; console.log("catch:", err))&lt;/code&gt;&lt;/strong&gt; — This handler is attached but will never fire because the promise is fulfilled, not rejected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Synchronous code is done.&lt;/strong&gt; The microtask queue is processed: the &lt;code&gt;.then()&lt;/code&gt; handler runs and prints &lt;code&gt;then: Resolved&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Macrotask queue is processed:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First &lt;code&gt;setTimeout&lt;/code&gt; fires: &lt;code&gt;reject("Rejected")&lt;/code&gt; — &lt;strong&gt;silently ignored&lt;/strong&gt;, promise is already settled.&lt;/li&gt;
&lt;li&gt;Second &lt;code&gt;setTimeout&lt;/code&gt; fires: &lt;code&gt;resolve("Timeout")&lt;/code&gt; — &lt;strong&gt;silently ignored&lt;/strong&gt;, promise is already settled.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A promise can only be settled once.&lt;/strong&gt; The first call to &lt;code&gt;resolve()&lt;/code&gt; or &lt;code&gt;reject()&lt;/code&gt; wins. All subsequent calls are silently ignored — no errors, no warnings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;resolve()&lt;/code&gt; does not stop executor execution.&lt;/strong&gt; Unlike &lt;code&gt;return&lt;/code&gt;, calling &lt;code&gt;resolve()&lt;/code&gt; inside a Promise executor does not prevent the remaining code from running. If you want to stop, use &lt;code&gt;return resolve(value)&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Synchronous code in the executor runs before any scheduled callbacks.&lt;/strong&gt; &lt;code&gt;setTimeout(..., 0)&lt;/code&gt; schedules work for later (macrotask queue), while &lt;code&gt;resolve()&lt;/code&gt; called directly runs immediately during executor execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The executor runs synchronously.&lt;/strong&gt; The function passed to &lt;code&gt;new Promise()&lt;/code&gt; is invoked immediately and synchronously — it is not deferred or queued.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;When wrapping async operations in Promises, guard against double-settlement.&lt;/strong&gt; Use a flag or &lt;code&gt;return&lt;/code&gt; after the first &lt;code&gt;resolve()&lt;/code&gt;/&lt;code&gt;reject()&lt;/code&gt; call to make the intent explicit and prevent subtle bugs in multi-path async logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>[Talk::Overflow #23] tiny ruby #{conf} 2025</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Fri, 13 Feb 2026 07:57:54 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/talkoverflow-23-tiny-ruby-conf-2025-2eee</link>
      <guid>https://forem.com/valpetaltechlabs/talkoverflow-23-tiny-ruby-conf-2025-2eee</guid>
      <description>&lt;p&gt;&lt;strong&gt;tiny ruby #{conf} 2025&lt;/strong&gt; was a single-track Ruby conference in Helsinki, Finland. Six talks, one day, no filler.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Read the full post and subscribe at &lt;a href="https://talkoverflow.substack.com/p/talkoverflow-23-tiny-ruby-conf-2025" rel="noopener noreferrer"&gt;Talk::Overflow&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ruby conferences are often mistaken for "Rails conferences with nostalgia." tiny ruby #{conf} 2025 is a useful corrective: the agenda is about &lt;em&gt;engineering choices&lt;/em&gt; — how you model complexity, how you ship and run Ruby in real environments, and how you keep your craft (and career) compounding.&lt;/p&gt;

&lt;p&gt;For Ruby on Rails engineers, the signal is practical:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Ruby is still a productivity language, but the bar has moved toward &lt;strong&gt;operability&lt;/strong&gt;, &lt;strong&gt;modeling discipline&lt;/strong&gt;, and &lt;strong&gt;developer leverage&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  "Small" runtimes and "small" concepts (booleans!) hide real complexity that bites production systems.&lt;/li&gt;
&lt;li&gt;  Tooling and workflows (Docker, CI, mentoring/pairing, AI assistance) are the multiplier, not the side quest.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  All Talks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Even smaller Rubies — Chris Hasiński
&lt;/h3&gt;

&lt;p&gt;Ruby isn't just "Rails on servers" — it's also a language that can shrink down into places you don't usually associate with dynamic runtimes. This talk tours &lt;strong&gt;mruby&lt;/strong&gt; and &lt;strong&gt;mruby/c&lt;/strong&gt;, focusing on both useful and delightfully weird deployments: &lt;strong&gt;game scripting&lt;/strong&gt;, &lt;strong&gt;retro consoles&lt;/strong&gt;, and even "auto-focus glasses."&lt;/p&gt;

&lt;p&gt;The practical takeaway for Rails folks isn't that you should rewrite your app for embedded; it's that Ruby's ecosystem includes runtime options that can fit tighter constraints than CRuby-on-Linux. The tradeoff is obvious: smaller runtimes mean tighter APIs, different extension stories, and fewer "it just works" assumptions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Brewing potions with Ruby and linear programming — Youssef Boulkaid
&lt;/h3&gt;

&lt;p&gt;This is an applied modeling talk disguised as a cozy-game anecdote. Starting from &lt;em&gt;Potionomics&lt;/em&gt; (a game about running a potion shop), it drops into the real work: &lt;strong&gt;combinatorics&lt;/strong&gt;, &lt;strong&gt;data modeling&lt;/strong&gt;, and &lt;strong&gt;optimization&lt;/strong&gt; with &lt;strong&gt;linear programming&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The interesting bit for working engineers is the shape of the problem: when "try all the combinations" stops scaling, you need a solver mindset, not more brute force. Ruby is a perfectly reasonable glue language for these kinds of models, especially when the goal is clarity and iteration speed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker – Build the Perfect Home for Ruby — Matti Paksula
&lt;/h3&gt;

&lt;p&gt;Rails ships a Dockerfile now, but "it builds" isn't the same as "it's a good container image." This talk is about turning Docker into a repeatable home for Ruby apps using &lt;strong&gt;gem caching&lt;/strong&gt;, &lt;strong&gt;layer strategy&lt;/strong&gt;, &lt;strong&gt;multi-arch builds&lt;/strong&gt;, and faster &lt;strong&gt;CI/CD&lt;/strong&gt; pipelines.&lt;/p&gt;

&lt;p&gt;For teams shipping Rails, the payoff is simple: shorter feedback loops and fewer "works on my machine" mismatches between dev and production. The talk's stance is pragmatic — optimize where it moves the needle, not because container lore says you should.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unlocking the Rubetta Stones — Louis Antonopoulos
&lt;/h3&gt;

&lt;p&gt;This talk uses a playful framing — decaying "ancient tablets" that must be deciphered quickly — to explore concurrency and assistance workflows in Ruby. The core ingredients are &lt;strong&gt;Ractors&lt;/strong&gt; (Ruby's parallel execution model) and an &lt;strong&gt;AI assistant&lt;/strong&gt; as a collaborator in the translation effort.&lt;/p&gt;

&lt;p&gt;Even if you don't use Ractors daily in Rails work, the underlying lesson is relevant: when the workload is parallelizable, architecture choices matter more than clever code. The tradeoff is complexity: concurrency models introduce sharp edges, and "AI help" only helps if you can validate outputs and keep the system grounded in reality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Revisiting Booleans in Ruby — Sarah Lima
&lt;/h3&gt;

&lt;p&gt;Booleans look harmless until your domain stops being binary. This talk argues that Ruby truthiness and "just use true/false" often become a modeling trap, especially when systems evolve into multi-state workflows.&lt;/p&gt;

&lt;p&gt;The useful takeaway is: when you model a complex state machine as a boolean, you're hiding information — and you'll pay for it later in conditionals, edge cases, and unreadable code. If you want codebases that stay maintainable at year 3+, revisiting basic types like this is not pedantry — it's preventative engineering.&lt;/p&gt;

&lt;h3&gt;
  
  
  Level Up Your Engineering Career with Mentorship, Pairing, and AI — Hana Harencarova
&lt;/h3&gt;

&lt;p&gt;Not every high-leverage talk is about code paths; some are about feedback loops. This one is a practical pitch for accelerating growth through &lt;strong&gt;mentorship&lt;/strong&gt;, &lt;strong&gt;pair programming&lt;/strong&gt;, and &lt;strong&gt;AI&lt;/strong&gt; — with an emphasis on not learning alone.&lt;/p&gt;

&lt;p&gt;For Rails engineers, the key point is that ecosystems change fast (tooling, deployment norms, testing culture), and solo learning often leads to local maxima. Pairing and mentorship shorten the time-to-correctness for both technical decisions and career decisions. The tradeoff is coordination cost: you have to create the space for pairing and mentorship to actually happen, and you need norms that make it safe and useful.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Read the full post and subscribe at &lt;a href="https://talkoverflow.substack.com/p/talkoverflow-23-tiny-ruby-conf-2025" rel="noopener noreferrer"&gt;Talk::Overflow&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>techtalks</category>
      <category>programming</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Question of the Day #17 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Fri, 13 Feb 2026 07:52:02 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/question-of-the-day-17-talkoverflow-2ohk</link>
      <guid>https://forem.com/valpetaltechlabs/question-of-the-day-17-talkoverflow-2ohk</guid>
      <description>&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7427960253817741312" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&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;Hint:&lt;/strong&gt; Think about where &lt;code&gt;var&lt;/code&gt; declarations end up before any code runs — and what happens when you increment something that doesn't have a value yet.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct answer: B) NaN, 0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first &lt;code&gt;console.log&lt;/code&gt; prints &lt;code&gt;NaN&lt;/code&gt;. The second prints &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This quiz targets a subtle but dangerous interaction between &lt;code&gt;var&lt;/code&gt; hoisting and variable shadowing.&lt;/p&gt;

&lt;p&gt;When JavaScript parses the &lt;code&gt;increment&lt;/code&gt; function, the &lt;code&gt;var count;&lt;/code&gt; declaration is &lt;strong&gt;hoisted&lt;/strong&gt; to the top of the function scope — even though it appears after &lt;code&gt;count++&lt;/code&gt; in the source code. This creates a &lt;strong&gt;local&lt;/strong&gt; &lt;code&gt;count&lt;/code&gt; variable inside &lt;code&gt;increment&lt;/code&gt;, completely separate from the outer &lt;code&gt;let count = 0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At runtime, the function effectively becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// hoisted — initialized to undefined&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;         &lt;span class="c1"&gt;// undefined + 1 → NaN&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// NaN&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The outer &lt;code&gt;let count = 0&lt;/code&gt; is never touched because the local &lt;code&gt;var count&lt;/code&gt; &lt;strong&gt;shadows&lt;/strong&gt; it entirely within the function.&lt;/p&gt;

&lt;p&gt;This is a real production bug that typically appears when developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accidentally add a &lt;code&gt;var&lt;/code&gt; declaration for a variable they intended to reference from an outer scope&lt;/li&gt;
&lt;li&gt;Refactor code by moving variable declarations around without realizing &lt;code&gt;var&lt;/code&gt; hoists to the function boundary&lt;/li&gt;
&lt;li&gt;Copy-paste code fragments that introduce an unintended local declaration&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;let count = 0;&lt;/code&gt;&lt;/strong&gt; — Declares &lt;code&gt;count&lt;/code&gt; in the outer (module/script) scope with value &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;function increment() {&lt;/code&gt;&lt;/strong&gt; — JavaScript parses the entire function body before executing. It finds &lt;code&gt;var count;&lt;/code&gt; and hoists it to the top of the function, initializing it to &lt;code&gt;undefined&lt;/code&gt;. This local &lt;code&gt;count&lt;/code&gt; shadows the outer &lt;code&gt;count&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;count++;&lt;/code&gt;&lt;/strong&gt; — Operates on the &lt;strong&gt;local&lt;/strong&gt; &lt;code&gt;count&lt;/code&gt;, which is &lt;code&gt;undefined&lt;/code&gt;. The &lt;code&gt;++&lt;/code&gt; postfix operator converts &lt;code&gt;undefined&lt;/code&gt; to &lt;code&gt;NaN&lt;/code&gt; via &lt;code&gt;Number(undefined)&lt;/code&gt;, then attempts &lt;code&gt;NaN + 1&lt;/code&gt;, which is &lt;code&gt;NaN&lt;/code&gt;. The local &lt;code&gt;count&lt;/code&gt; is now &lt;code&gt;NaN&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;var count;&lt;/code&gt;&lt;/strong&gt; — This is a no-op at runtime. The declaration was already hoisted; no new assignment happens here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;return count;&lt;/code&gt;&lt;/strong&gt; — Returns the local &lt;code&gt;count&lt;/code&gt;, which is &lt;code&gt;NaN&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(increment());&lt;/code&gt;&lt;/strong&gt; — Prints &lt;code&gt;NaN&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(count);&lt;/code&gt;&lt;/strong&gt; — Prints &lt;code&gt;0&lt;/code&gt;. The outer &lt;code&gt;count&lt;/code&gt; was never modified because the function only ever operated on its own local &lt;code&gt;count&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;var&lt;/code&gt; declarations are hoisted to the top of their enclosing function&lt;/strong&gt; — not to the line where they appear. This means a &lt;code&gt;var&lt;/code&gt; anywhere in a function creates a local variable that exists from the very first line of that function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hoisted &lt;code&gt;var&lt;/code&gt; variables shadow outer variables silently.&lt;/strong&gt; Unlike &lt;code&gt;let&lt;/code&gt;/&lt;code&gt;const&lt;/code&gt; which would cause a clear TDZ error if accessed before declaration, &lt;code&gt;var&lt;/code&gt; quietly creates an &lt;code&gt;undefined&lt;/code&gt; binding that masks the outer scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;undefined++&lt;/code&gt; evaluates to &lt;code&gt;NaN&lt;/code&gt;, not an error.&lt;/strong&gt; JavaScript's type coercion converts &lt;code&gt;undefined&lt;/code&gt; to &lt;code&gt;NaN&lt;/code&gt; before the arithmetic operation, producing a silent wrong result rather than a crash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Always prefer &lt;code&gt;let&lt;/code&gt;/&lt;code&gt;const&lt;/code&gt; over &lt;code&gt;var&lt;/code&gt;.&lt;/strong&gt; With &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;, attempting to use the variable before its declaration throws a &lt;code&gt;ReferenceError&lt;/code&gt; (Temporal Dead Zone), making this class of bugs immediately visible instead of silently corrupting data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Linting rules like &lt;code&gt;no-shadow&lt;/code&gt; and &lt;code&gt;no-var&lt;/code&gt; exist specifically to prevent this.&lt;/strong&gt; Enable them in ESLint to catch accidental variable shadowing and &lt;code&gt;var&lt;/code&gt; usage before they reach production.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Javascript Question of the Day #16 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Thu, 12 Feb 2026 10:33:14 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-16-talkoverflow-25e4</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-16-talkoverflow-25e4</guid>
      <description>&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7427650613326385152" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;set:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;42&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="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&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;assign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&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="nx"&gt;base&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt; &lt;code&gt;Object.assign&lt;/code&gt; writes to the target using &lt;code&gt;[[Set]]&lt;/code&gt;, triggering setters. Spread reads from the source using &lt;code&gt;[[Get]]&lt;/code&gt;, creating plain data properties. Think about which side the accessor runs on.&lt;/p&gt;

&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct Answer: A) set:100, get / 42&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The output will be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;"set:100, get"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;42&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;This quiz exposes one of the most commonly misunderstood distinctions in JavaScript object manipulation: &lt;strong&gt;&lt;code&gt;Object.assign&lt;/code&gt; invokes setters on the target&lt;/strong&gt;, while &lt;strong&gt;spread (&lt;code&gt;...&lt;/code&gt;) invokes getters on the source and creates plain data properties on the new object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These two operations look interchangeable in everyday code, but they interact with property descriptors in fundamentally different ways — a distinction that causes real production bugs in state management systems, reactive frameworks, and configuration merging utilities.&lt;/p&gt;

&lt;p&gt;The core mechanism:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Object.assign(target, source)&lt;/code&gt;&lt;/strong&gt; iterates over the source's own enumerable properties, reads each value, then writes it to the target using the target's &lt;code&gt;[[Set]]&lt;/code&gt; semantics. If the target has a setter for that property, the setter fires.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;{ ...source }&lt;/code&gt;&lt;/strong&gt; iterates over the source's own enumerable properties using &lt;code&gt;[[Get]]&lt;/code&gt; semantics, reads each value (triggering getters on the source), and creates a brand-new plain object with simple data properties — no getters or setters are copied.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setup:&lt;/strong&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;set:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
     &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;42&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="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;base&lt;/code&gt; has an accessor property &lt;code&gt;value&lt;/code&gt; with both a getter and a setter&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;source&lt;/code&gt; has a plain data property &lt;code&gt;value&lt;/code&gt; with the number &lt;code&gt;100&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;log&lt;/code&gt; tracks every accessor invocation&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Object.assign(base, source);&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Object.assign&lt;/code&gt; reads &lt;code&gt;source.value&lt;/code&gt; → gets &lt;code&gt;100&lt;/code&gt; (plain data property, no getter)&lt;/li&gt;
&lt;li&gt;Then it writes to &lt;code&gt;base.value = 100&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;base&lt;/code&gt; has a &lt;strong&gt;setter&lt;/strong&gt; for &lt;code&gt;value&lt;/code&gt;, so the setter fires&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;log.push("set:100")&lt;/code&gt; → log is now &lt;code&gt;["set:100"]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Crucially:&lt;/strong&gt; the value &lt;code&gt;100&lt;/code&gt; is never actually stored on &lt;code&gt;base&lt;/code&gt;. The setter received it but didn't persist it — there's no backing field. The getter still returns &lt;code&gt;42&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;const copy = { ...base };&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spread reads all own enumerable properties of &lt;code&gt;base&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;base.value&lt;/code&gt; is accessed → the &lt;strong&gt;getter&lt;/strong&gt; fires&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;log.push("get")&lt;/code&gt; → log is now &lt;code&gt;["set:100", "get"]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The getter returns &lt;code&gt;42&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;copy&lt;/code&gt; is created as &lt;code&gt;{ value: 42 }&lt;/code&gt; — a plain data property, not an accessor&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(log.join(", "));&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Outputs: &lt;code&gt;"set:100, get"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;console.log(copy.value);&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;copy.value&lt;/code&gt; is a plain data property with value &lt;code&gt;42&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Outputs: &lt;code&gt;42&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Note:&lt;/strong&gt; The getter does NOT fire here — &lt;code&gt;copy&lt;/code&gt; has a plain property, not an accessor&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The non-obvious part:&lt;/strong&gt; Most developers assume that since &lt;code&gt;Object.assign(base, source)&lt;/code&gt; was called with &lt;code&gt;{ value: 100 }&lt;/code&gt;, then &lt;code&gt;base.value&lt;/code&gt; is now &lt;code&gt;100&lt;/code&gt;. But the setter intercepted the write without storing anything, so the getter still returns its hardcoded &lt;code&gt;42&lt;/code&gt;. Then, when spread reads &lt;code&gt;base.value&lt;/code&gt;, it calls the getter — not the stored value from the assign. The resulting &lt;code&gt;copy&lt;/code&gt; object strips all accessor behavior entirely and holds a frozen snapshot (&lt;code&gt;42&lt;/code&gt;) as a plain data property.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Common mistake:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Developer assumes these are equivalent:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;merged1&lt;/span&gt; &lt;span class="o"&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;assign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Triggers target's setters&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;merged2&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="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;       &lt;span class="c1"&gt;// Triggers target's getters, ignores setters&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are NOT equivalent when accessor properties are involved. The first mutates &lt;code&gt;target&lt;/code&gt; via its setters. The second creates a new object from getter return values.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Object.assign&lt;/code&gt; uses &lt;code&gt;[[Set]]&lt;/code&gt; on the target:&lt;/strong&gt; It triggers setters on the destination object. If the setter doesn't store the value, the property's getter still returns its original value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spread uses &lt;code&gt;[[Get]]&lt;/code&gt; on the source:&lt;/strong&gt; It triggers getters on the source object and creates plain data properties on the new object. Accessor behavior is not transferred.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spread strips property descriptors:&lt;/strong&gt; The resulting object from &lt;code&gt;{ ...obj }&lt;/code&gt; always has plain data properties — no getters, setters, non-enumerable flags, or non-configurable flags survive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;Object.assign&lt;/code&gt; does not copy descriptors either:&lt;/strong&gt; It reads values from the source (triggering getters) and writes them to the target (triggering setters). To truly copy descriptors, use &lt;code&gt;Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setters without backing storage are a trap:&lt;/strong&gt; If a setter doesn't persist the value (common in validation layers, logging interceptors, or reactive proxies), &lt;code&gt;Object.assign&lt;/code&gt; appears to succeed but the value is silently lost. The getter continues returning whatever it was designed to return.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Javascript Question of the Day #15 [Talk::Overflow]</title>
      <dc:creator>ValPetal Tech Labs</dc:creator>
      <pubDate>Wed, 11 Feb 2026 10:40:14 +0000</pubDate>
      <link>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-15-talkoverflow-27p4</link>
      <guid>https://forem.com/valpetaltechlabs/javascript-question-of-the-day-15-talkoverflow-27p4</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This post explains a quiz originally shared as a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7427298346534379520" rel="noopener noreferrer"&gt;LinkedIn poll&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔹 The Question
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="na"&gt;fetchUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/users/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&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;fetchPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/posts/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&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="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchPost&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt; Arrow functions don't create their own &lt;code&gt;this&lt;/code&gt; — they inherit it from the enclosing lexical scope. What is &lt;code&gt;this&lt;/code&gt; at the top level of a script?&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Solution
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Correct Answer: B) &lt;code&gt;undefined/users/1&lt;/code&gt; / &lt;code&gt;https://api.example.com/posts/2&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  🧠 How this works
&lt;/h4&gt;

&lt;p&gt;The core mechanism here is &lt;strong&gt;lexical &lt;code&gt;this&lt;/code&gt; binding in arrow functions&lt;/strong&gt; versus &lt;strong&gt;dynamic &lt;code&gt;this&lt;/code&gt; binding in regular methods&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you define a method using the &lt;strong&gt;arrow function syntax&lt;/strong&gt; (&lt;code&gt;fetchUser: (id) =&amp;gt; { ... }&lt;/code&gt;), the arrow function does &lt;strong&gt;not&lt;/strong&gt; get its own &lt;code&gt;this&lt;/code&gt;. Instead, it captures &lt;code&gt;this&lt;/code&gt; from the &lt;strong&gt;enclosing lexical scope&lt;/strong&gt; — which in this case is the top-level script scope.&lt;/p&gt;

&lt;p&gt;At the top level of a non-module script:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a browser: &lt;code&gt;this&lt;/code&gt; is the &lt;code&gt;window&lt;/code&gt; object&lt;/li&gt;
&lt;li&gt;In Node.js REPL: &lt;code&gt;this&lt;/code&gt; is the &lt;code&gt;global&lt;/code&gt; object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In both cases, &lt;code&gt;this.baseURL&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt; because there is no &lt;code&gt;baseURL&lt;/code&gt; property on the global object.&lt;/p&gt;

&lt;p&gt;When you define a method using &lt;strong&gt;shorthand syntax&lt;/strong&gt; (&lt;code&gt;fetchPost(id) { ... }&lt;/code&gt;), it's a regular function. When called as &lt;code&gt;api.fetchPost(2)&lt;/code&gt;, &lt;code&gt;this&lt;/code&gt; is dynamically bound to &lt;code&gt;api&lt;/code&gt; — the object before the dot. So &lt;code&gt;this.baseURL&lt;/code&gt; correctly resolves to &lt;code&gt;"https://api.example.com"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; The object literal &lt;code&gt;{ ... }&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; a scope. Arrow functions defined inside an object literal do not capture &lt;code&gt;this&lt;/code&gt; as the object — they capture &lt;code&gt;this&lt;/code&gt; from whatever scope the object literal is being evaluated in.&lt;/p&gt;

&lt;h4&gt;
  
  
  🔍 Line-by-line explanation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;const api = { ... }&lt;/code&gt;&lt;/strong&gt; — An object literal is created. This is an expression, not a scope boundary. The &lt;code&gt;this&lt;/code&gt; value inside is inherited from the surrounding context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;baseURL: "https://api.example.com"&lt;/code&gt;&lt;/strong&gt; — A simple string property on the object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;fetchUser: (id) =&amp;gt; { ... }&lt;/code&gt;&lt;/strong&gt; — An arrow function is assigned to the &lt;code&gt;fetchUser&lt;/code&gt; property. At this point, the arrow function permanently captures &lt;code&gt;this&lt;/code&gt; from the enclosing scope (the top-level script). &lt;code&gt;this&lt;/code&gt; here is the global object (or &lt;code&gt;undefined&lt;/code&gt; in strict mode / ES modules).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;fetchPost(id) { ... }&lt;/code&gt;&lt;/strong&gt; — A regular method defined using shorthand syntax. It will receive &lt;code&gt;this&lt;/code&gt; dynamically based on how it's called.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;api.fetchUser(1)&lt;/code&gt;&lt;/strong&gt; — The arrow function runs. &lt;code&gt;this&lt;/code&gt; is the global object (captured at definition time). &lt;code&gt;this.baseURL&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt;. The template literal produces &lt;code&gt;"undefined/users/1"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;api.fetchPost(2)&lt;/code&gt;&lt;/strong&gt; — The regular method runs. &lt;code&gt;this&lt;/code&gt; is &lt;code&gt;api&lt;/code&gt; (because &lt;code&gt;api.&lt;/code&gt; is before &lt;code&gt;fetchPost&lt;/code&gt;). &lt;code&gt;this.baseURL&lt;/code&gt; is &lt;code&gt;"https://api.example.com"&lt;/code&gt;. The template literal produces &lt;code&gt;"https://api.example.com/posts/2"&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The misleading part:&lt;/strong&gt; It looks like both methods are defined "inside" the &lt;code&gt;api&lt;/code&gt; object, so you'd expect both to have &lt;code&gt;this === api&lt;/code&gt;. But object literals don't create a &lt;code&gt;this&lt;/code&gt; context — only functions, classes, and the global scope do.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Key Takeaways
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Arrow functions capture &lt;code&gt;this&lt;/code&gt; lexically&lt;/strong&gt; — from the enclosing &lt;em&gt;function&lt;/em&gt; or &lt;em&gt;script&lt;/em&gt; scope, not from the object they're defined in. Object literals are not scopes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use shorthand method syntax for object methods&lt;/strong&gt; (&lt;code&gt;method() { }&lt;/code&gt;) when you need &lt;code&gt;this&lt;/code&gt; to reference the object. Arrow functions are the wrong tool for this job.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Arrow functions shine in callbacks&lt;/strong&gt; — inside a regular method, arrow functions correctly inherit &lt;code&gt;this&lt;/code&gt; from that method, making them ideal for &lt;code&gt;.map()&lt;/code&gt;, &lt;code&gt;.filter()&lt;/code&gt;, &lt;code&gt;setTimeout&lt;/code&gt;, and event handlers inside methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;This bug is silent&lt;/strong&gt; — &lt;code&gt;undefined&lt;/code&gt; coerces to a string without throwing, so broken arrow-function methods often produce subtly wrong output rather than crashing, making them hard to detect without tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ESLint can catch this&lt;/strong&gt; — The &lt;code&gt;no-invalid-this&lt;/code&gt; rule and the &lt;code&gt;class-methods-use-this&lt;/code&gt; rule can help flag arrow functions that reference &lt;code&gt;this&lt;/code&gt; in unexpected scopes.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Follow me for JavaScript puzzles and weekly curations of developer talks &amp;amp; insights at Talk::Overflow: &lt;a href="https://talkoverflow.substack.com/" rel="noopener noreferrer"&gt;https://talkoverflow.substack.com/&lt;/a&gt;&lt;/p&gt;

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