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

Tag: ES2022

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

JavaScript: Use Error Cause for Better Error Chains

- 06.06.26 - ErcanOPAK comment on JavaScript: Use Error Cause for Better Error Chains

🔗 Don’t Lose the Original Error Throwing new Error() loses original stack. Error cause chains errors. See full context. 📝 Without Error Cause (Lost Context) try { await fetchUser(userId); } catch (err) { throw new Error(`Failed to get user ${userId}`); // Original error stack lost! } ✅ With Error Cause (Full Context) try { await […]

Read More
JavaScript

JavaScript: Use structuredClone() for True Deep Copy of Objects

- 29.05.26 - ErcanOPAK comment on JavaScript: Use structuredClone() for True Deep Copy of Objects

📦 Finally, True Deep Copy Without Libraries JSON.parse(JSON.stringify()) fails with dates, undefined, functions. structuredClone() handles dates, maps, sets, arrays, nested objects — everything. ❌ JSON Hack (Broken) const obj = { date: new Date(), fn: () => {}, undef: undefined }; const copy = JSON.parse(JSON.stringify(obj)); // date becomes string! // fn and undef are gone! […]

Read More
JavaScript

JavaScript: Use Top-Level Await in Modules for Cleaner Async Code

- 28.05.26 | 28.05.26 - ErcanOPAK comment on JavaScript: Use Top-Level Await in Modules for Cleaner Async Code

⏰ Async Without Async Function Wrapper Need await at top level? Used to need IIFE. Top-level await works directly in ES modules. Cleaner initialization code. ❌ Old Way (IIFE) (async () => { const data = await fetch(‘/api/config’); const config = await data.json(); startApp(config); })(); ✅ Top-Level Await // In .mjs or type=”module” script const […]

Read More
JavaScript

JavaScript: Use structuredClone for Deep Object Copy

- 19.03.26 | 19.03.26 - ErcanOPAK comment on JavaScript: Use structuredClone for Deep Object Copy

Deep cloning objects? JSON.parse(JSON.stringify()) fails on dates, functions, undefined. // ❌ Old way (loses dates, functions) const copy = JSON.parse(JSON.stringify(original)); // ✅ New way (preserves everything) const copy = structuredClone(original); // Works with: // – Nested objects // – Arrays // – Dates // – Maps, Sets // – RegExp // – ArrayBuffer Performance: Faster […]

Read More
JavaScript

JavaScript: Use structuredClone() to Deep Copy Objects

- 13.02.26 - ErcanOPAK comment on JavaScript: Use structuredClone() to Deep Copy Objects

JSON.parse(JSON.stringify()) is clunky and breaks on Dates/Functions. Use structuredClone() instead. Old Unreliable Way: const original = { name: ‘John’, date: new Date() }; const copy = JSON.parse(JSON.stringify(original)); console.log(copy.date); // String, not Date! ❌ New Built-In Way: const original = { name: ‘John’, date: new Date(), nested: { deep: { value: 42 } } }; const […]

Read More
JavaScript

JavaScript: Use Array.at() to Access Array Elements from End

- 13.02.26 - ErcanOPAK comment on JavaScript: Use Array.at() to Access Array Elements from End

Getting last array element with arr[arr.length – 1] is verbose. Use .at() instead. Old Way: const arr = [10, 20, 30, 40, 50]; const last = arr[arr.length – 1]; // 50 const secondLast = arr[arr.length – 2]; // 40 New Way: const last = arr.at(-1); // 50 const secondLast = arr.at(-2); // 40 const first […]

Read More
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,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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