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 WeakRef Target Being Collected Too Early

- 21.11.26 - ErcanOPAK comment on JavaScript: Fix a WeakRef Target Being Collected Too Early

⚡ JavaScript: Fix a WeakRef Target Being Collected Too Early A WeakRef doesn’t keep its target alive — if nothing else in the program holds a strong reference to the object it points to, the garbage collector is free to collect it at any point, including almost immediately, even though you just created the WeakRef […]

Read More
JavaScript

JavaScript: Fix a Temporal Polyfill Rounding a Date Wrong

- 20.11.26 - ErcanOPAK comment on JavaScript: Fix a Temporal Polyfill Rounding a Date Wrong

⚡ Fix a Temporal Polyfill Rounding a Date Wrong at a Boundary Calling .round() or .until()/.since() on the Temporal API’s polyfill without an explicit roundingMode defaults to halfExpand, a rounding rule that behaves differently on negative durations than most developers’ mental model of Math.round() built from years of working with positive numbers only. A duration […]

Read More
JavaScript

JavaScript: Fix structuredClone Dropping a Class’s Methods

- 19.11.26 - ErcanOPAK comment on JavaScript: Fix structuredClone Dropping a Class’s Methods

⚡ Fix structuredClone Dropping a Class’s Methods `structuredClone()` implements the HTML structured clone algorithm, which deep-copies DATA — plain objects, arrays, Maps, Sets, Dates — but does not preserve a custom class’s prototype chain. Cloning an instance of a class with methods produces a plain object with the same own properties but a prototype reset […]

Read More
JavaScript

JavaScript: Fix Array.sort Reordering Equal Items Unexpectedly

- 18.11.26 - ErcanOPAK comment on JavaScript: Fix Array.sort Reordering Equal Items Unexpectedly

⚡ JavaScript: Fix Array.sort Reordering Equal Items Unexpectedly Every modern engine’s Array.prototype.sort is specified to be stable, meaning elements the comparator treats as equal keep their original relative order — but that guarantee only holds if the comparator itself behaves like a real comparator. A comparator that subtracts a field which can be undefined for […]

Read More
JavaScript

JavaScript: Fix a WeakMap Losing Entries After a Structured Clone

- 17.11.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap Losing Entries After a Structured Clone

⚡ JavaScript: Fix a WeakMap Losing Entries After a Structured Clone A WeakMap only ever matches a key by strict object reference, which is exactly what makes it silently break the moment an object crosses a structuredClone() boundary — passing data to a Web Worker through postMessage(), or cloning it directly — because structured cloning […]

Read More
JavaScript

JavaScript: Fix a Debounced Method Losing this on a Class

- 16.11.26 - ErcanOPAK comment on JavaScript: Fix a Debounced Method Losing this on a Class

⚡ JavaScript: Fix a Debounced Method Losing this on a Class A debounce helper wraps a plain function reference and returns a new function that calls the original after a delay. When the wrapped function is a class’s regular method, passed directly into the helper, the debounced wrapper eventually invokes the original as a bare […]

Read More
JavaScript

JavaScript: Fix a WeakMap Entry Disappearing Before You Expected

- 15.11.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap Entry Disappearing Before You Expected

⚡ JavaScript: Fix a WeakMap Entry Disappearing Before You Expected A WeakMap holds its keys weakly, meaning an entry can be garbage collected — and silently vanish from the map — as soon as nothing else in the program holds a strong reference to that key object. Code that assumes “the DOM node is still […]

Read More
JavaScript

JavaScript: Fix a WeakRef’s Target Getting Garbage-Collected in the Gap Between an Async Callback’s Check and Its Later Use

- 14.11.26 - ErcanOPAK comment on JavaScript: Fix a WeakRef’s Target Getting Garbage-Collected in the Gap Between an Async Callback’s Check and Its Later Use

⚡ Fix a WeakRef’s Target Getting Garbage-Collected in the Gap Between an Async Callback’s Check and Its Later Use A WeakRef lets you hold a reference to an object without keeping it alive, which is exactly the point, but that also means the object it points to can be collected by the garbage collector at […]

Read More
JavaScript

JavaScript: Fix a ResizeObserver Callback Firing in an Infinite Loop Because It Resizes the Very Element It’s Observing

- 13.11.26 - ErcanOPAK comment on JavaScript: Fix a ResizeObserver Callback Firing in an Infinite Loop Because It Resizes the Very Element It’s Observing

⚡ JavaScript: Fix a ResizeObserver Callback Firing in an Infinite Loop Because It Resizes the Very Element It’s Observing ResizeObserver’s callback fires every time an observed element’s content box changes size, which is exactly what makes it useful for responsive components that need to react to their own container’s dimensions — and exactly what turns […]

Read More
JavaScript

JavaScript: Fix an Intl.NumberFormat Call Rounding a Currency Value Differently Than the Database’s Own Rule Because the Default Rounding Mode Isn’t halfEven

- 12.11.26 - ErcanOPAK comment on JavaScript: Fix an Intl.NumberFormat Call Rounding a Currency Value Differently Than the Database’s Own Rule Because the Default Rounding Mode Isn’t halfEven

⚡ JavaScript: Fix an Intl.NumberFormat Call Rounding a Currency Value Differently Than the Database’s Own Rule Because the Default Rounding Mode Isn’t halfEven `Intl.NumberFormat`’s currency formatting defaults to a `roundingMode` of `halfExpand` (round half away from zero) unless you explicitly specify otherwise, which is a perfectly reasonable default for display purposes — but many financial […]

Read More
JavaScript

JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value

- 11.11.26 - ErcanOPAK comment on JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value

⚡ JavaScript: Fix a Promise.allSettled Call Reporting Every Promise as Fulfilled Even Though One of the Underlying Fetches Actually Failed Because a catch Block Inside It Swallowed the Rejection and Returned an Ordinary Value Promise.allSettled resolves every entry strictly based on whether that specific promise settled by resolving or rejecting — it has no way […]

Read More
JavaScript

JavaScript: Fix structuredClone Throwing on an Object That Worked Fine With JSON.stringify Because It Contains a Value structuredClone Explicitly Refuses to Clone

- 10.11.26 - ErcanOPAK comment on JavaScript: Fix structuredClone Throwing on an Object That Worked Fine With JSON.stringify Because It Contains a Value structuredClone Explicitly Refuses to Clone

⚡ Fix structuredClone Throwing on an Object That Worked Fine With JSON.stringify Because It Contains a Value structuredClone Explicitly Refuses to Clone structuredClone and JSON.stringify/JSON.parse are often reached for interchangeably as a quick way to deep-copy an object, but they handle values neither can meaningfully represent in completely opposite ways: JSON.stringify silently drops a function […]

Read More
JavaScript

JavaScript: Fix a Map Used as a Cache Growing Forever Because Object Keys Inserted Into It Are Compared by Reference, So Two Structurally Identical Keys Never Collide

- 09.11.26 - ErcanOPAK comment on JavaScript: Fix a Map Used as a Cache Growing Forever Because Object Keys Inserted Into It Are Compared by Reference, So Two Structurally Identical Keys Never Collide

⚡ Fix a Map Used as a Cache Growing Forever Because Object Keys Inserted Into It Are Compared by Reference, So Two Structurally Identical Keys Never Collide A Map lets you use objects as keys, unlike a plain object which coerces every key to a string, which looks like exactly what you want for caching […]

Read More
JavaScript

JavaScript: Fix value instanceof Array Returning false for an Array Passed Across an iframe Boundary Because Each Window Has Its Own Array Constructor

- 08.11.26 - ErcanOPAK comment on JavaScript: Fix value instanceof Array Returning false for an Array Passed Across an iframe Boundary Because Each Window Has Its Own Array Constructor

⚡ JavaScript: Fix value instanceof Array Returning false for an Array Passed Across an iframe Boundary Because Each Window Has Its Own Array Constructor Every JavaScript realm — the main page, and separately each iframe, popup window, or worker — has its own global object and therefore its own distinct set of built-in constructors, Array […]

Read More
JavaScript

JavaScript: Fix Promise.race Resolving With a Timeout’s Placeholder Value Instead of Ever Propagating the Slower Promise’s Eventual Rejection

- 07.11.26 - ErcanOPAK comment on JavaScript: Fix Promise.race Resolving With a Timeout’s Placeholder Value Instead of Ever Propagating the Slower Promise’s Eventual Rejection

⚡ JavaScript: Fix Promise.race Resolving With a Timeout’s Placeholder Value Instead of Ever Propagating the Slower Promise’s Eventual Rejection A common pattern for adding a timeout to a slow async call races the real operation against a promise that resolves with a sentinel value after a fixed delay, using Promise.race to take whichever settles first. […]

Read More
JavaScript

JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays

- 06.11.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays

⚡ JavaScript: Fix Array.prototype.flat Not Flattening a Nested Array Returned From an Async Map Because the Outer Array Still Holds Unresolved Promises Instead of Arrays Array.prototype.map with an async callback doesn’t wait for each callback to resolve before moving to the next element — it immediately returns a Promise from every call, so the array […]

Read More
JavaScript

JavaScript: Fix Array.prototype.includes Returning False for NaN Because a Custom Equality Check Replaced Its Built-In SameValueZero Comparison

- 05.11.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.includes Returning False for NaN Because a Custom Equality Check Replaced Its Built-In SameValueZero Comparison

⚡ JavaScript: Fix Array.prototype.includes Returning False for NaN Because a Custom Equality Check Replaced Its Built-In SameValueZero Comparison Array.prototype.includes is specified to use the SameValueZero algorithm, which is the one built-in piece of JavaScript that actually treats NaN as equal to itself, unlike ===, so [NaN].includes(NaN) correctly returns true with no extra work. Code that […]

Read More
JavaScript

JavaScript: Fix a Debounced Function Still Firing Once per Call Instead of Once per Burst Because the Timer Variable Is Declared Inside the Returned Function Instead of the Outer Closure

- 04.11.26 - ErcanOPAK comment on JavaScript: Fix a Debounced Function Still Firing Once per Call Instead of Once per Burst Because the Timer Variable Is Declared Inside the Returned Function Instead of the Outer Closure

⚡ Fix a Debounced Function Still Firing Once per Call Instead of Once per Burst Because the Timer Variable Is Declared Inside the Returned Function Instead of the Outer Closure A correct debounce implementation relies on one shared timer identifier that persists across every call to the debounced function, so each new call can cancel […]

Read More
JavaScript

JavaScript: Fix a Tagged Template Literal Function Receiving a Different Strings Array Identity on Every Call Because a Loose Compiler Transform Recreates It Instead of Caching It

- 02.11.26 - ErcanOPAK comment on JavaScript: Fix a Tagged Template Literal Function Receiving a Different Strings Array Identity on Every Call Because a Loose Compiler Transform Recreates It Instead of Caching It

⚡ Fix a Tagged Template Literal Function Receiving a Different Strings Array Identity on Every Call Because a Loose Compiler Transform Recreates It Instead of Caching It The spec for tagged template literals guarantees that calling the same tag function from the exact same call site always receives the identical, frozen strings array object by […]

Read More
JavaScript

JavaScript: Fix Array.prototype.sort() Producing a Different Order in Two Browsers Because the Compare Function Returns NaN for Equal Elements

- 01.11.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.sort() Producing a Different Order in Two Browsers Because the Compare Function Returns NaN for Equal Elements

⚡ Fix Array.prototype.sort() Producing a Different Order in Two Browsers Because the Compare Function Returns NaN for Equal Elements Array.prototype.sort() expects its compare function to return a negative number, zero, or a positive number, and the specification leaves the sort’s exact behavior unspecified the moment the compare function returns anything else, including NaN, which commonly […]

Read More
JavaScript

JavaScript: Fix Array.prototype.with() Silently Producing a Shallow Copy That Still Shares Nested Object References

- 01.11.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.with() Silently Producing a Shallow Copy That Still Shares Nested Object References

⚡ Fix Array.prototype.with() Silently Producing a Shallow Copy That Still Shares Nested Object References Array.prototype.with() was added specifically to give arrays an immutable alternative to index-assignment, returning a brand new array instead of mutating the original in place, and that framing makes it easy to assume the result is fully independent of the source. What […]

Read More
JavaScript

JavaScript: Fix FinalizationRegistry Cleanup Entries That Stop Arriving Entirely Because the Registry Instance Itself Was Only Reachable From One of Its Own Tracked Objects

- 01.11.26 - ErcanOPAK comment on JavaScript: Fix FinalizationRegistry Cleanup Entries That Stop Arriving Entirely Because the Registry Instance Itself Was Only Reachable From One of Its Own Tracked Objects

⚡ Fix FinalizationRegistry Cleanup Entries That Stop Arriving Entirely Because the Registry Instance Itself Was Only Reachable From One of Its Own Tracked Objects FinalizationRegistry lets you register a callback that runs sometime after an object it’s tracking becomes unreachable and gets garbage collected, which sounds like exactly the right primitive for cleaning up an […]

Read More
JavaScript

JavaScript: Fix Object.groupBy() Silently Splitting What Should Be One Group Into Two Because the Grouping Callback Returns a Number for One Row and a String for Another

- 31.10.26 - ErcanOPAK comment on JavaScript: Fix Object.groupBy() Silently Splitting What Should Be One Group Into Two Because the Grouping Callback Returns a Number for One Row and a String for Another

⚡ Fix Object.groupBy() Silently Splitting What Should Be One Group Into Two Because the Grouping Callback Returns a Number for One Row and a String for Another Object.groupBy() builds its result by calling the grouping callback once per element and using whatever that callback returns as a property key on the result object, and JavaScript […]

Read More
JavaScript

JavaScript: Fix Array.prototype.at() Returning Undefined for a Valid Negative Index Because an Old Polyfill Silently Shipped Without Negative-Index Support

- 31.10.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.at() Returning Undefined for a Valid Negative Index Because an Old Polyfill Silently Shipped Without Negative-Index Support

⚡ Fix Array.prototype.at() Returning Undefined for a Valid Negative Index Because an Old Polyfill Silently Shipped Without Negative-Index Support Array.prototype.at() exists specifically to make negative-index access first-class, arr.at(-1) for the last element, arr.at(-2) for the second-to-last, without the awkward arr[arr.length – 1] arithmetic developers have written by hand for years. A polyfill written to backfill […]

Read More
JavaScript

JavaScript: Fix Object.freeze Not Actually Preventing Changes to a Frozen Object’s Nested Array

- 31.10.26 - ErcanOPAK comment on JavaScript: Fix Object.freeze Not Actually Preventing Changes to a Frozen Object’s Nested Array

⚡ Fix Object.freeze Not Actually Preventing Changes to a Frozen Object’s Nested Array Object.freeze locks down an object so its existing properties can’t be reassigned and no new properties can be added, which reads like it should make the whole object immutable, and for an object made entirely of primitive values, that’s exactly what it […]

Read More
JavaScript

JavaScript: Fix a Generator’s finally Block Never Running Because the Caller Drives It With Manual next() Calls Instead of a for-of Loop

- 31.10.26 - ErcanOPAK comment on JavaScript: Fix a Generator’s finally Block Never Running Because the Caller Drives It With Manual next() Calls Instead of a for-of Loop

⚡ Fix a Generator’s finally Block Never Running Because the Caller Drives It With Manual next() Calls Instead of a for-of Loop JavaScript’s iteration protocol has a built-in cleanup mechanism, and a for-of loop automatically invokes it by calling return on the generator whenever the loop exits early, whether through break, a return, or a […]

Read More
JavaScript

JavaScript: Fix a WeakMap Cache That Keeps Growing Because the Keys Are Primitive Values Instead of Object References

- 30.10.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap Cache That Keeps Growing Because the Keys Are Primitive Values Instead of Object References

⚡ Fix a WeakMap Cache That Keeps Growing Because the Keys Are Primitive Values Instead of Object References WeakMap is often reached for specifically because its entries don’t prevent garbage collection — once nothing else references a key object, that entry is eligible for collection automatically, with no manual cleanup needed. That guarantee depends entirely […]

Read More
JavaScript

JavaScript: Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch

- 30.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch

⚡ Fix a Promise.allSettled Call Hiding a Rejected Promise’s Error Because Nothing Ever Inspects the Rejected Status Branch Promise.allSettled exists specifically so one rejected promise doesn’t short-circuit the whole batch the way Promise.all would — every result resolves with a `{status, value}` or `{status, reason}` object, and the call itself never rejects. That’s exactly what […]

Read More
JavaScript

JavaScript: Fix a WeakMap-Based Cache Still Leaking Memory Because the Key Object Is Held Alive by an Unrelated Closure Elsewhere

- 30.10.26 - ErcanOPAK comment on JavaScript: Fix a WeakMap-Based Cache Still Leaking Memory Because the Key Object Is Held Alive by an Unrelated Closure Elsewhere

⚡ Fix a WeakMap-Based Cache Still Leaking Memory Because the Key Object Is Held Alive by an Unrelated Closure Elsewhere A WeakMap is specifically designed so its entries can be garbage collected the instant nothing else in the program still references the key object – the cache entry itself never keeps the key alive. That […]

Read More
JavaScript

JavaScript: Fix Array.prototype.sort() Changing the Order of Equal-Looking Elements After a Browser Update Because the Comparator Was Never Actually Stable

- 29.10.26 - ErcanOPAK comment on JavaScript: Fix Array.prototype.sort() Changing the Order of Equal-Looking Elements After a Browser Update Because the Comparator Was Never Actually Stable

⚡ Fix Array.prototype.sort() Changing the Order of Equal-Looking Elements After a Browser Update Because the Comparator Was Never Actually Stable Modern JavaScript engines guarantee that Array.prototype.sort() is stable – elements the comparator reports as equal (returning 0) keep their original relative order. That guarantee only holds for elements the comparator is actually consistent about, though […]

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

Posts pagination

1 2 3 … 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