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: Why JSON.stringify Silently Drops undefined Values, Functions, and Symbols From an Object

- 03.10.26 - ErcanOPAK comment on JavaScript: Why JSON.stringify Silently Drops undefined Values, Functions, and Symbols From an Object

⚡ The Object Property That Disappeared on the Way to JSON JSON has no representation for undefined, functions, or symbols – the format simply doesn’t define a way to encode them – so JSON.stringify doesn’t throw or warn when it encounters one, it just leaves the corresponding key out of the output entirely. A property […]

Read More
JavaScript

JavaScript: Fix a Promise.race() Call Whose Losing Promises Keep Running in the Background After It Resolves

- 03.10.26 - ErcanOPAK comment on JavaScript: Fix a Promise.race() Call Whose Losing Promises Keep Running in the Background After It Resolves

🔧 The Promise.race() Winner That Didn’t Actually Stop Anything Promise.race() settles as soon as the first of several promises settles, and returns that result – but it has no way to reach into the other promises and stop them, because a JavaScript Promise has no built-in cancellation mechanism at all. A promise that ‘loses’ the […]

Read More
JavaScript

JavaScript: Why Array Sort Can Reorder Equal Elements Differently Across Browsers

- 03.10.26 - ErcanOPAK comment on JavaScript: Why Array Sort Can Reorder Equal Elements Differently Across Browsers

🔧 The Sort That Agreed on the Order, Just Not Which Order Calling sort with a comparator that returns 0 for elements considered equal reads as though those equal elements will simply stay in whatever order they started in – and for years, that assumption was only sometimes true, because the specification didn’t always require […]

Read More
JavaScript

JavaScript: Why indexOf Can’t Find a NaN You Just Pushed Into the Array

- 27.09.26 - ErcanOPAK comment on JavaScript: Why indexOf Can’t Find a NaN You Just Pushed Into the Array

⚡ The Value That Was Right There in the Array and indexOf Still Couldn’t Find It Array.prototype.indexOf (and lastIndexOf) use strict equality (===) internally to compare values – and NaN, famously, is never strictly equal to anything, including itself. That means myArray.indexOf(NaN) returns -1 even when NaN is genuinely, visibly sitting in the array at […]

Read More
JavaScript

JavaScript: Why structuredClone Throws on Data That JSON.stringify Handled Just Fine

- 27.09.26 - ErcanOPAK comment on JavaScript: Why structuredClone Throws on Data That JSON.stringify Handled Just Fine

⚡ The ‘Safer’ Clone That Started Throwing Where JSON Never Complained Swapping JSON.parse(JSON.stringify(obj)) for the newer, purpose-built structuredClone() is a very reasonable upgrade – it correctly clones Dates, Maps, Sets, and typed arrays that the JSON round-trip quietly mangles. But structuredClone is also genuinely STRICTER: where JSON.stringify silently drops functions, undefined values, and symbols (or […]

Read More
JavaScript

JavaScript: Why Optional Chaining Doesn’t Stop a Function Call From Throwing

- 27.09.26 - ErcanOPAK comment on JavaScript: Why Optional Chaining Doesn’t Stop a Function Call From Throwing

⚡ The Optional Chain That Still Threw an Error Anyway Optional chaining (`?.`) correctly short-circuits to `undefined` when a property in the chain is null or undefined – but it only protects against a MISSING property or method, not against a method that exists and gets called but then throws its own exception internally, which […]

Read More
JavaScript

JavaScript: Why a Set Still Contains ‘Duplicate’ Values That Look Completely Identical

- 26.09.26 - ErcanOPAK comment on JavaScript: Why a Set Still Contains ‘Duplicate’ Values That Look Completely Identical

⚡ The Set That’s Supposed to Remove Duplicates and Somehow Didn’t A JavaScript `Set` is built specifically to hold only unique values – but when it’s populated with objects rather than primitives, two items that look completely identical when logged to the console can both end up in the Set, because `Set` uses the exact […]

Read More
JavaScript

JavaScript: Why Object.freeze() Doesn’t Stop Nested Properties From Being Changed

- 26.09.26 - ErcanOPAK comment on JavaScript: Why Object.freeze() Doesn’t Stop Nested Properties From Being Changed

⚡ Frozen on the Outside, Fully Mutable on the Inside `Object.freeze()` looks like it locks an object down completely, and attempts to reassign its top-level properties do get silently ignored (or throw, in strict mode) – but freeze is shallow: any object or array nested inside the frozen object is a completely separate object reference, […]

Read More
JavaScript

JavaScript: Why Modifying an Array Inside forEach() Skips Some Elements

- 26.09.26 - ErcanOPAK comment on JavaScript: Why Modifying an Array Inside forEach() Skips Some Elements

⚡ Removing Items Inside forEach() Silently Skips Some of Them A `forEach()` loop removes matching items from the same array it’s iterating over – and some items that SHOULD have been removed are left behind, because `forEach()` (like most array iteration methods) tracks its position by INDEX, and removing an element shifts every later element […]

Read More
JavaScript

JavaScript: Why Destructuring a Nested Property Throws Instead of Returning Undefined

- 06.09.26 - ErcanOPAK comment on JavaScript: Why Destructuring a Nested Property Throws Instead of Returning Undefined

⚡ Destructuring a Nested Property Throws an Error Instead of Just Returning Undefined Accessing a deeply nested property that doesn’t exist normally just returns `undefined` in JavaScript – but destructuring the same nested path throws a `TypeError: Cannot destructure property ‘x’ of ‘undefined’ as it is undefined` instead, because destructuring has to actually READ each […]

Read More
JavaScript

JavaScript: Why Comparing Two Dates With == Almost Never Works the Way You Expect

- 06.09.26 - ErcanOPAK comment on JavaScript: Why Comparing Two Dates With == Almost Never Works the Way You Expect

⚡ Why Comparing Two Dates With == Almost Never Does What You Expect Two `Date` objects representing the exact same moment in time compare as NOT equal with `==` (or `===`) – which surprises people expecting date comparison to work like number or string comparison, because in JavaScript, `Date` is an object, and `==`/`===` between […]

Read More
JavaScript

JavaScript: Why a Closure Inside a Loop Captures the Same Value on Every Iteration

- 06.09.26 - ErcanOPAK comment on JavaScript: Why a Closure Inside a Loop Captures the Same Value on Every Iteration

⚡ Every Callback in Your Loop Is Using the Same Final Value, Not Its Own A loop creates a callback for each iteration – a click handler, a `setTimeout`, a promise `.then()` – expecting each one to remember the value of the loop variable at the moment it was created, but every single callback ends […]

Read More
JavaScript

JavaScript: Why Adding a Number and a String With + Produces Unexpected Concatenation

- 05.09.26 - ErcanOPAK comment on JavaScript: Why Adding a Number and a String With + Produces Unexpected Concatenation

⚡ 5 + ‘5’ Isn’t 10 – And That’s Not the Only Surprise Waiting Here A calculation that adds a number to what should be another number produces a concatenated string instead of a sum – ’55’ instead of 10 – because somewhere upstream, one of the two values quietly arrived as a string rather […]

Read More
JavaScript

JavaScript: Why Comparing Two Objects With === Always Returns False Even With Identical Properties

- 05.09.26 - ErcanOPAK comment on JavaScript: Why Comparing Two Objects With === Always Returns False Even With Identical Properties

⚡ Every Property Matches – === Still Says They’re Different Objects Two objects hold exactly the same keys with exactly the same values, logged side by side they look identical – and comparing them with === consistently returns false, confusing anyone who expected equality to mean ‘the data looks the same.’ 🐞 The Problem const […]

Read More
JavaScript

JavaScript: Fix a Debounce Function That Fires on the First Keystroke Instead of the Last

- 05.09.26 - ErcanOPAK comment on JavaScript: Fix a Debounce Function That Fires on the First Keystroke Instead of the Last

⚡ Your Debounce Function Fires Immediately – Then Waits for the Rest A debounce wrapper around a search input is supposed to wait until the user pauses typing before firing – instead it fires instantly on the very first keystroke, then correctly debounces every keystroke after that, producing one extra, unwanted request per search. 🐞 […]

Read More
JavaScript

JavaScript: Fix a Memory Leak Caused by Event Listeners You Forgot to Remove

- 31.08.26 - ErcanOPAK comment on JavaScript: Fix a Memory Leak Caused by Event Listeners You Forgot to Remove

⚡ The Page Gets Slower the Longer It Stays Open – Here’s Why A single-page app feels snappy right after loading, then gradually gets sluggish the longer a user keeps it open, especially after navigating between views repeatedly. Nothing crashed – the browser’s memory usage just keeps climbing, and it never comes back down. 🐞 […]

Read More
JavaScript

JavaScript: Why ‘this’ Silently Becomes undefined Inside a Callback Function

- 31.08.26 - ErcanOPAK comment on JavaScript: Why ‘this’ Silently Becomes undefined Inside a Callback Function

⚡ The Method Works Fine – Until You Pass It as a Callback A method reads this.value perfectly well when called directly on the object. Pass that exact same method as a callback to setTimeout, an event listener, or an array method, and this quietly becomes undefined — throwing an error the moment the callback […]

Read More
JavaScript

JavaScript: Why localStorage Silently Throws in Private Browsing Mode

- 31.08.26 | 31.08.26 - ErcanOPAK comment on JavaScript: Why localStorage Silently Throws in Private Browsing Mode

⚡ localStorage Isn’t Always There — Code Like It Might Not Be Code that calls localStorage.setItem() directly works perfectly in normal testing, then throws an uncaught exception and breaks the whole page for users in Safari’s Private Browsing mode, some locked-down corporate browsers, or with storage explicitly disabled. 🐞 The Problem function saveDraft(text) { localStorage.setItem(‘draft’, […]

Read More
JavaScript

JavaScript: Why Array.sort() Turns Your Numbers Into Strings and Wrecks the Order

- 30.08.26 | 31.08.26 - ErcanOPAK comment on JavaScript: Why Array.sort() Turns Your Numbers Into Strings and Wrecks the Order

⚡ sort() Isn’t Sorting Numbers the Way You Think Calling .sort() on an array of numbers with no arguments doesn’t sort numerically — it converts every number to a string first and compares them alphabetically, and nothing throws an error to warn you it happened. 🐞 The Problem const values = [10, 1, 2, 21, […]

Read More
JavaScript

JavaScript: Why a Forgotten clearInterval() Is Silently Draining Your Users’ Battery

- 30.08.26 | 31.08.26 - ErcanOPAK comment on JavaScript: Why a Forgotten clearInterval() Is Silently Draining Your Users’ Battery

⚡ Missing clearInterval = Battery Drain A setInterval started when a component/page section mounts and never explicitly stopped keeps running in the background forever — even after the UI it was updating is gone — quietly burning CPU and battery on every device that ever visited the page. 🐞 The Problem function startLiveClock() { setInterval(() […]

Read More
JavaScript

JavaScript: Why == Silently Breaks Comparisons — And Why === Isn’t Even the Full Fix

- 30.08.26 - ErcanOPAK comment on JavaScript: Why == Silently Breaks Comparisons — And Why === Isn’t Even the Full Fix

⚡ == Lies, === Doesn’t An if-statement that should never pass, passes. A bug ships to production because 0 == “” is somehow true. JavaScript’s loose equality performs invisible type coercion, and most developers only half-understand the rule. 🐞 The Problem console.log(0 == “”); // true — string coerced to number console.log(0 == “0”); // […]

Read More
JavaScript

JavaScript Closures: The Secret Behind Functional Programming

- 29.08.26 | 29.08.26 - ErcanOPAK comment on JavaScript Closures: The Secret Behind Functional Programming

🔒 Quick Win: Closures are functions that remember their outer variables. They’re the foundation of functional programming in JavaScript. Closures are powerful but often misunderstood. Master them for better code. 🚀 What are Closures? // ✅ Basic closure function createCounter() { let count = 0; // Outer variable return function() { count++; // Inner function […]

Read More
JavaScript

JavaScript Event Delegation: Master Efficient Event Handling

- 29.08.26 - ErcanOPAK comment on JavaScript Event Delegation: Master Efficient Event Handling

⚡ Key Insights: Event delegation attaches one listener to a parent element, handling events for all children. Saves memory and handles dynamic elements. Adding event listeners to every element is inefficient. Event Delegation is the solution. ❌ The Problem – Many Listeners // ❌ Adds listener to EVERY button document.querySelectorAll(‘button’).forEach(button => { button.addEventListener(‘click’, handleClick); }); […]

Read More
JavaScript

JavaScript Debounce and Throttle: Control Event Frequency Like a Pro

- 23.08.26 - ErcanOPAK comment on JavaScript Debounce and Throttle: Control Event Frequency Like a Pro

⚡ Key Takeaways: Debounce delays function execution. Throttle limits execution frequency. Essential for performance optimization. Events fire too often. Debounce and throttle control them. 🔄 Debounce – Wait and Execute // ✅ Debounce implementation function debounce(func, delay = 300) { let timeoutId; return function (…args) { clearTimeout(timeoutId); timeoutId = setTimeout(() => { func.apply(this, args); }, […]

Read More
JavaScript

JavaScript Promise.all and Promise.race: Master Async Control

- 23.08.26 - ErcanOPAK comment on JavaScript Promise.all and Promise.race: Master Async Control

⚡ Key Takeaways: Promise.all runs promises in parallel. Promise.race completes on first resolution. Master these for better async code. Working with multiple promises? Promise.all and Promise.race are your tools. 🚀 Promise.all – Parallel Execution // ✅ Run multiple API calls in parallel async function getDashboardData(userId) { // ❌ Sequential – Slow const user = await […]

Read More
JavaScript

Step-by-Step: JavaScript Web Workers for Multi-Threaded Applications

- 23.08.26 - ErcanOPAK comment on Step-by-Step: JavaScript Web Workers for Multi-Threaded Applications

🧵 Key Takeaways: Web Workers bring multi-threading to JavaScript. Perfect for heavy computations, data processing, and background tasks. JavaScript is single-threaded. Web Workers change that. 🚀 Create Web Worker // ✅ worker.js – Heavy computation in background self.addEventListener(‘message’, (event) => { const data = event.data; if (data.type === ‘process’) { const result = heavyComputation(data.payload); self.postMessage({ […]

Read More
JavaScript

JavaScript Proxy and Reflect: Metaprogramming Power for Modern Apps

- 22.08.26 - ErcanOPAK comment on JavaScript Proxy and Reflect: Metaprogramming Power for Modern Apps

🪄 Key Takeaways: Trap object operations, validate properties, create reactive data, and build elegant APIs with JavaScript’s powerful metaprogramming tools. Want to intercept and customize object operations? Proxy and Reflect are your magic wand. 🎯 Basic Proxy // ❌ Without Proxy – No validation const user = { name: “John”, age: 25 }; user.age = […]

Read More
JavaScript

JavaScript Async/Await: Complete Guide to Clean Promise Chains

- 19.08.26 - ErcanOPAK comment on JavaScript Async/Await: Complete Guide to Clean Promise Chains

Stop the callback hell and promise pyramid! Async/await makes asynchronous JavaScript code look synchronous and maintainable. Step 1: The Problem – Promise Chains // ❌ Callback Hell getUser(1, (user) => { getOrders(user.id, (orders) => { getOrderDetails(orders[0].id, (details) => { processOrder(details, (result) => { console.log(‘Done!’, result); }); }); }); }); // ❌ Promise Pyramid getUser(1) .then(user […]

Read More
JavaScript

Step-by-Step: Building a Weather App with Fetch API

- 18.08.26 - ErcanOPAK comment on Step-by-Step: Building a Weather App with Fetch API

🌤️ Weather App = Fetch API Real-time data is everywhere. Step-by-step guide to build a weather app using Fetch API. 📝 Step 1-4: Setup and API // Step 1: HTML Structure <div class=”weather-app”> <input type=”text” id=”city” placeholder=”Enter city name…”> <button id=”search-btn”>Search</button> <div id=”weather-data”></div> </div> // Step 2: API Configuration const API_KEY = ‘your-api-key’; const API_URL […]

Read More
JavaScript

JavaScript: Web Workers ile Parallel Processing

- 18.08.26 - ErcanOPAK comment on JavaScript: Web Workers ile Parallel Processing

🧵 Web Workers = Parallel Processing Single thread yeterli değil. Web Workers ile background processing yapın. 🎯 Web Worker Implementation // 1. Worker File (worker.js) self.addEventListener(‘message’, (e) => { const data = e.data; const result = heavyComputation(data); self.postMessage(result); }); function heavyComputation(data) { // CPU-intensive işlem let result = 0; for (let i = 0; i […]

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

Posts pagination

« Previous 1 2 3 4 5 … 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