Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: JavaScript

JavaScript

JavaScript: Fix a WeakMap-Backed Cache Silently Losing Entries Because the Key Object Gets Re-Created on Every Render Instead of Reused

- 29.10.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap-Backed Cache Silently Losing Entries Because the Key Object Gets Re-Created on Every Render Instead of Reused

⚡ Fix a WeakMap-Backed Cache Silently Losing Entries Because the Key Object Gets Re-Created on Every Render Instead of Reused A WeakMap is keyed by object identity, not by value equality or any serialized form of an object’s contents. Building a brand-new object literal inside the very function that performs the cache lookup – a […]

Read More
JavaScript

JavaScript: Fix a Proxy-Wrapped Object Losing Its Custom Methods After It’s Passed Through JSON.stringify and Rebuilt With JSON.parse

- 29.10.26 - ErcanOPAK comment on JavaScript: Fix a Proxy-Wrapped Object Losing Its Custom Methods After It’s Passed Through JSON.stringify and Rebuilt With JSON.parse

⚡ Fix a Proxy-Wrapped Object Losing Its Custom Methods After It’s Passed Through JSON.stringify and Rebuilt With JSON.parse JSON.stringify only serializes an object’s own enumerable data properties – it has no concept of a Proxy’s traps, a class’s prototype methods, or any function-valued property, all of which are silently skipped. Round-tripping a reactive object through […]

Read More
JavaScript

JavaScript: Fix a Debounced Function That Never Fires on the Trailing Edge Because Every New Call Keeps Resetting the Same Timer

- 28.10.26 - ErcanOPAK comment on JavaScript: Fix a Debounced Function That Never Fires on the Trailing Edge Because Every New Call Keeps Resetting the Same Timer

⚡ Fix a Debounced Function That Never Fires on the Trailing Edge Because Every New Call Keeps Resetting the Same Timer A trailing-edge debounce is supposed to wait for a pause in activity and then fire exactly once, which works perfectly as long as calls eventually stop coming. The trouble shows up when calls arrive […]

Read More
JavaScript

JavaScript: Fix a NaN Check That Silently Breaks After Swapping Array.prototype.includes() for indexOf Because indexOf Can Never Find NaN

- 28.10.26 - ErcanOPAK comment on JavaScript: Fix a NaN Check That Silently Breaks After Swapping Array.prototype.includes() for indexOf Because indexOf Can Never Find NaN

⚡ Fix a NaN Check That Silently Breaks After Swapping Array.prototype.includes() for indexOf Because indexOf Can Never Find NaN Array.prototype.includes() uses the SameValueZero algorithm, which treats NaN as equal to itself, so values.includes(NaN) correctly returns true when NaN is present. Array.prototype.indexOf() uses strict equality instead, where NaN === NaN is false by definition, so indexOf […]

Read More
JavaScript

JavaScript: Fix an Array.prototype.sort() Call That Silently Reorders Numbers Alphabetically Because No Compare Function Was Passed

- 28.10.26 - ErcanOPAK comment on JavaScript: Fix an Array.prototype.sort() Call That Silently Reorders Numbers Alphabetically Because No Compare Function Was Passed

⚡ Fix an Array.prototype.sort() Call That Silently Reorders Numbers Alphabetically Because No Compare Function Was Passed Calling sort with no arguments converts every element to a string first and compares those strings character by character, which means an array of numbers gets ordered alphabetically rather than numerically the moment any value crosses a digit-count boundary […]

Read More
JavaScript

JavaScript: Fix a WeakMap Entry Disappearing Early Because the Only Remaining Reference to Its Key Lived Inside a Closure the Engine Could Still Collect

- 23.10.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap Entry Disappearing Early Because the Only Remaining Reference to Its Key Lived Inside a Closure the Engine Could Still Collect

⚡ Fix a WeakMap Entry Disappearing Early Because the Only Remaining Reference to Its Key Lived Inside a Closure the Engine Could Still Collect A WeakMap entry is supposed to stay alive for as long as something else in the program is still holding a strong reference to its key object – that’s the entire […]

Read More
JavaScript

JavaScript: Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values

- 23.10.26 - ErcanOPAK comment on JavaScript: Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values

⚡ Fix an async Function Inside Array.prototype.map() Silently Returning an Array of Pending Promises Instead of Resolved Values Passing an async function directly into .map() compiles and runs without any error, which is exactly what makes this bug so easy to ship: every async function implicitly returns a Promise, so .map()’s callback dutifully returns one […]

Read More
JavaScript

JavaScript: Fix Optional Chaining Silently Hiding a Typo in a Property Name Instead of Throwing Where You’d Notice

- 23.10.26 - ErcanOPAK comment on JavaScript: Fix Optional Chaining Silently Hiding a Typo in a Property Name Instead of Throwing Where You’d Notice

⚡ ?. Doesn’t Just Guard Against null – It Guards Against Your Typos Too Optional chaining (?.) is genuinely useful for safely reading a property that might legitimately not exist yet on an object that’s still loading, but it applies that same forgiveness to every property access in the chain – including one where you […]

Read More
JavaScript

JavaScript: Fix a Global RegExp Silently Skipping Matches Because lastIndex Carried Over From an Earlier Call

- 22.10.26 - ErcanOPAK comment on JavaScript: Fix a Global RegExp Silently Skipping Matches Because lastIndex Carried Over From an Earlier Call

⚡ A Reused Global RegExp Remembers Exactly Where It Left Off A RegExp object created once with the global flag and reused across multiple calls to test() or exec() isn’t stateless the way most people assume a regular expression check should be – it keeps its own lastIndex property between calls, and once that index […]

Read More
JavaScript

JavaScript: Fix an IntersectionObserver Callback That Never Fires Because the Target Starts Outside the Viewport With display: none

- 22.10.26 - ErcanOPAK comment on JavaScript: Fix an IntersectionObserver Callback That Never Fires Because the Target Starts Outside the Viewport With display: none

⚡ The Observer That’s Watching an Element That Isn’t There Yet IntersectionObserver reports intersection changes relative to an element’s actual rendered box, and an element with display: none has no rendered box at all – it isn’t positioned off-screen, it simply doesn’t participate in layout – so observing an element while it’s still display: none […]

Read More
JavaScript

JavaScript: Fix a Promise.allSettled Call Whose Rejected Results Get Silently Ignored Because Only value Was Read, Never status

- 22.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise.allSettled Call Whose Rejected Results Get Silently Ignored Because Only value Was Read, Never status

⚡ The Settled Promise That Nobody Checked for Failure Promise.allSettled exists specifically so a batch of independent async operations can all finish – successes and failures alike – without one rejection aborting the whole batch the way Promise.all’s fail-fast behavior would, but that safety comes with a cost: every result in the returned array is […]

Read More
JavaScript

JavaScript: Fix a MutationObserver Callback That Silently Stops Firing After the Observed Node Is Replaced, Not Just Removed

- 21.10.26 - ErcanOPAK comment on JavaScript: Fix a MutationObserver Callback That Silently Stops Firing After the Observed Node Is Replaced, Not Just Removed

⚡ The Observer Still Watching a Node Nobody’s Using Anymore A MutationObserver is attached to a specific DOM node reference at the moment observe() is called, and it keeps watching that exact node for as long as it exists in memory – but a framework or a piece of app code that replaces an element […]

Read More
JavaScript

JavaScript: Fix a structuredClone Call Silently Throwing Because the Object Still Holds a Reference to a DOM Node

- 21.10.26 - ErcanOPAK comment on JavaScript: Fix a structuredClone Call Silently Throwing Because the Object Still Holds a Reference to a DOM Node

⚡ The Deep Clone That Chokes on One Stray Reference structuredClone() looks like a drop-in, dependency-free replacement for JSON.parse(JSON.stringify(x)) for deep-cloning plain data, and for most objects it genuinely is a strict upgrade – it correctly handles Dates, Maps, Sets, and circular references that JSON serialization would mangle or crash on outright. But it uses […]

Read More
JavaScript

JavaScript: Fix an Intl.NumberFormat Call That Silently Rounds Differently Than toFixed() for the Same Number

- 21.10.26 - ErcanOPAK comment on JavaScript: Fix an Intl.NumberFormat Call That Silently Rounds Differently Than toFixed() for the Same Number

⚡ The Two Correct Ways to Round the Same Number toFixed() and Intl.NumberFormat use different rounding rules under the hood: toFixed() relies on IEEE 754 floating-point rounding, which can round a value like 1.005 down instead of up because of how that number is actually represented in binary, while Intl.NumberFormat’s formatting algorithm follows a different […]

Read More
JavaScript

JavaScript: Fix an Object’s Key Order That Silently Changes Because Integer-Like String Keys Always Sort Numerically First

- 21.10.26 - ErcanOPAK comment on JavaScript: Fix an Object’s Key Order That Silently Changes Because Integer-Like String Keys Always Sort Numerically First

⚡ The Object Whose Keys Reorder Themselves Modern JavaScript guarantees that an object’s own enumerable keys are visited in insertion order – but that guarantee comes with one carve-out almost nobody remembers: keys that look like non-negative integers (“0”, “1”, “42”, but not “01” or “1.5”) are always visited first, sorted in ascending numeric order, […]

Read More
JavaScript

JavaScript: Fix a String.replace() Call That Silently Only Replaces the First Match Because the Regex Pattern Is Missing the Global Flag

- 16.10.26 - ErcanOPAK comment on JavaScript: Fix a String.replace() Call That Silently Only Replaces the First Match Because the Regex Pattern Is Missing the Global Flag

⚡ The Replace That Stops After the First Hit String.prototype.replace() with a regular expression argument only replaces every occurrence if that regular expression was built with the global flag – without it, replace() silently stops after the very first match and leaves every other occurrence in the string completely untouched. There’s no warning, no partial-replace […]

Read More
JavaScript

JavaScript: Fix a parseInt() Call That Silently Stops at the First Non-Digit Character Instead of Throwing on a Malformed Number String

- 16.10.26 - ErcanOPAK comment on JavaScript: Fix a parseInt() Call That Silently Stops at the First Non-Digit Character Instead of Throwing on a Malformed Number String

⚡ The Number Parse That Stops Instead of Complaining parseInt() reads digits from the start of a string and simply stops the moment it hits a character that isn’t part of a valid number – it doesn’t throw, and it only returns NaN if there was no usable number at the very start. That means […]

Read More
JavaScript

JavaScript: Fix a Promise Chain That Silently Swallows a Rejection Because of a Missing Return

- 16.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise Chain That Silently Swallows a Rejection Because of a Missing Return

⚡ The Promise Chain That Forgot to Return Inside a .then() callback, calling another function that returns a promise without returning that promise yourself breaks the chain in a way that looks completely fine. The outer chain doesn’t wait for the inner promise and never sees its rejection – the inner promise becomes an orphaned, […]

Read More
JavaScript

JavaScript: Fix Array.prototype.sort() Silently Mutating the Original Array When You Meant to Sort a Copy

- 15.10.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.sort() Silently Mutating the Original Array When You Meant to Sort a Copy

⚡ The Sort That Rearranged the Wrong Array Array.prototype.sort() sorts the array in place and returns a reference to that same array – it does not hand back a new, independently sorted copy. Code that writes const sorted = items.sort(…) while still holding onto items elsewhere, expecting items to keep its original order, is actually […]

Read More
JavaScript

JavaScript: Fix a Web Worker postMessage Call That Silently Clones a Large ArrayBuffer Instead of Transferring It Because transfer Was Never Specified

- 15.10.26 - ErcanOPAK comment on JavaScript: Fix a Web Worker postMessage Call That Silently Clones a Large ArrayBuffer Instead of Transferring It Because transfer Was Never Specified

⚡ The postMessage That Copied Instead of Handing Off postMessage() defaults to a structured clone of everything you pass it, which for a large ArrayBuffer means the engine copies every byte into a brand-new buffer on the receiving side before the worker ever touches it – doubling memory use and burning time proportional to the […]

Read More
JavaScript

JavaScript: Fix a Generator Function Return Value That Gets Silently Ignored Unless You Read It From the Final done Result

- 15.10.26 - ErcanOPAK comment on JavaScript: Fix a Generator Function Return Value That Gets Silently Ignored Unless You Read It From the Final done Result

⚡ The Generator’s return Value Nobody Read A generator function can return a final value with an ordinary return statement, but that value doesn’t come out of a for…of loop the way yielded values do – for…of only reads values while done is false, and the final { value, done: true } result, the one […]

Read More
JavaScript

JavaScript: Fix a structuredClone Call That Throws Instead of Just Dropping Functions or DOM Nodes

- 11.10.26 - ErcanOPAK comment on JavaScript: Fix a structuredClone Call That Throws Instead of Just Dropping Functions or DOM Nodes

⚡ The Clone That Throws Instead of Just Skipping JSON.stringify has trained a lot of developers to expect that cloning data just quietly drops whatever it can’t represent – functions disappear, undefined properties vanish, and the result is usually good enough without anyone noticing. structuredClone() uses a different algorithm – the HTML structured clone algorithm, […]

Read More
JavaScript

JavaScript: Fix a Promise.race Call That Silently Leaks Unhandled Rejections From Every Promise That Didn’t Win

- 11.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise.race Call That Silently Leaks Unhandled Rejections From Every Promise That Didn’t Win

⚡ The Promises Promise.race Leaves Running After It Picks a Winner Promise.race settles the instant the first of its input promises settles, whether that first settlement is a resolve or a reject – and that’s the entire contract. Every other promise in the array keeps running exactly as it would have on its own, completely […]

Read More
JavaScript

JavaScript: Fix a WeakRef Target That Gets Collected Earlier Than Expected Because Nothing Else Holds a Strong Reference to It

- 11.10.26 - ErcanOPAK comment on JavaScript: Fix a WeakRef Target That Gets Collected Earlier Than Expected Because Nothing Else Holds a Strong Reference to It

⚡ The WeakRef That Let Go Sooner Than Expected A WeakRef deliberately holds a reference to its target that the garbage collector is free to ignore entirely, which is the whole point of using one, caching a large object without being the reason it stays alive. The part that catches people off guard is how […]

Read More
JavaScript

JavaScript: Fix a Proxy Object That Silently Breaks Object.keys() Because the has Trap Was Never Implemented

- 10.10.26 - ErcanOPAK comment on JavaScript: Fix a Proxy Object That Silently Breaks Object.keys() Because the has Trap Was Never Implemented

⚡ The Proxy That Forgets to Answer ‘Does This Key Exist’ Object.keys(), for…in, and the spread operator on a Proxy don’t call the get trap at all – they go through the ownKeys and getOwnPropertyDescriptor traps to list property names and descriptors, which is a completely separate path from the get trap used for direct […]

Read More
JavaScript

JavaScript: Fix a setTimeout Delay That Fires Immediately Because a Non-Numeric String Was Passed Instead of a Number

- 10.10.26 - ErcanOPAK comment on JavaScript: Fix a setTimeout Delay That Fires Immediately Because a Non-Numeric String Was Passed Instead of a Number

⚡ The Delay That Was Never Really a Number setTimeout coerces whatever it receives as a delay into a number using the same rules as the unary plus operator, and when that value is a string built from a template or concatenation that didn’t evaluate the way the author expected, say it accidentally contains a […]

Read More
JavaScript

JavaScript: Fix an Array.flat() Call That Silently Stops at One Level Because the Default Depth Isn’t Infinity

- 10.10.26 - ErcanOPAK comment on JavaScript: Fix an Array.flat() Call That Silently Stops at One Level Because the Default Depth Isn’t Infinity

⚡ The Flatten That Only Went One Floor Down Array.prototype.flat() takes an optional depth argument controlling how many levels of nested arrays it flattens, and it’s easy to assume calling it with no argument at all flattens everything, the way a method simply named ‘flat’ sounds like it should. The actual default depth is 1, […]

Read More
JavaScript

JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

- 04.10.26 - ErcanOPAK comment on JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

⚡ The Default Value That Only Worked for One Kind of Missing A default value in a destructuring pattern only kicks in when the corresponding position is exactly undefined – not when it is missing from a shorter array, and specifically not when it is present but holds the value null, which JavaScript treats as […]

Read More
JavaScript

JavaScript: Why a WeakMap Silently Loses Its Entry the Moment the Key Object Gets Garbage Collected

- 04.10.26 - ErcanOPAK comment on JavaScript: Why a WeakMap Silently Loses Its Entry the Moment the Key Object Gets Garbage Collected

⚡ The WeakMap Entry That Vanished On Its Own A WeakMap holds its keys weakly on purpose – storing an object as a key does not keep that object alive, so once every other reference to it is gone, the garbage collector is free to reclaim it, and its entry disappears from the map along […]

Read More
JavaScript

JavaScript: Fix a Click Handler That Fires Twice Because of Event Bubbling Through a Nested Element

- 04.10.26 - ErcanOPAK comment on JavaScript: Fix a Click Handler That Fires Twice Because of Event Bubbling Through a Nested Element

⚡ The Click That Reported for Duty Twice A click event doesn’t just fire on the element the user actually clicked – it bubbles upward through every ancestor element in the DOM, triggering any click listener attached along the way. Attaching a click handler to both an icon and its parent button, or to a […]

Read More
Page 2 of 11
« Previous 1 2 3 4 5 6 7 … 11 Next »

Posts pagination

« Previous 1 2 3 4 … 11 Next »
November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com