# programming

**URL:** https://forum.kirupa.com/c/programming/41.md?page=21

[Latest](https://forum.kirupa.com/latest.md) · [Categories](https://forum.kirupa.com/categories.md)

**Page:** 22

---

## [Why does this promise chain print undefined?](https://forum.kirupa.com/t/why-does-this-promise-chain-print-undefined/679752)

<div class="topic-metadata">

**Author:** [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 10:14am UTC](https://forum.kirupa.com/t/why-does-this-promise-chain-print-undefined/679752 "2026-03-31T10:14:05Z")

</div>

Consider this snippet. Promise.resolve(1) .then((v) =\> { v + 1; }) .then((v) =\> console.log(v)); Why does this print undefined, and what one-line change fixes it. Hari :slightly\_smiling\_face:

---

## [What does this JavaScript closure log?](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679749)

<div class="topic-metadata">

**Author:** [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 9:14am UTC](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679749 "2026-03-31T09:14:06Z")

</div>

Consider this snippet. for (var i = 0; i \< 3; i++) { setTimeout(() =\> console.log(i), 0); } What gets logged, and what tiny change would make it log 0, 1, 2. Sarah

---

## [Why does this debounce never fire as expected?](https://forum.kirupa.com/t/why-does-this-debounce-never-fire-as-expected/679747)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 8:14am UTC](https://forum.kirupa.com/t/why-does-this-debounce-never-fire-as-expected/679747 "2026-03-31T08:14:07Z")

</div>

Consider this snippet. function debounce(fn, delay) { let id; return (...args) =\> { clearTimeout(id); setTimeout(() =\> fn(...args), delay); }; } const log = debounce(console.log, 300); log('first'); log('…

---

## [Which color wins in this CSS specificity case?](https://forum.kirupa.com/t/which-color-wins-in-this-css-specificity-case/679744)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 7:21am UTC](https://forum.kirupa.com/t/which-color-wins-in-this-css-specificity-case/679744 "2026-03-31T07:21:06Z")

</div>

Consider this snippet. .card p { color: blue; } #app .card p { color: green; } .card .title { color: red; } \<div id="app"\> \<div class="card"\>\<p class="title"\>Hello\</p\>\</div\> \</div\> What final text color appears and …

---

## [JS Quiz: Array map with implicit undefined](https://forum.kirupa.com/t/js-quiz-array-map-with-implicit-undefined/679655)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 6\
**Last updated:** [March 31, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-array-map-with-implicit-undefined/679655 "2026-03-31T07:00:08Z")

</div>

What is the output? const out = \[1, 2, 3\].map((n) =\> { if (n % 2) return; return n \* 2; }); console.log(out.join(',')); poll WaffleFries

---

## [How do you keep edge caching simple when APIs are personalized?](https://forum.kirupa.com/t/how-do-you-keep-edge-caching-simple-when-apis-are-personalized/679719)

<div class="topic-metadata">

**Author:** [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Replies:** 3\
**Last updated:** [March 31, 2026, 6:49am UTC](https://forum.kirupa.com/t/how-do-you-keep-edge-caching-simple-when-apis-are-personalized/679719 "2026-03-31T06:49:06Z")

</div>

Personalized responses can break caching strategy quickly. What cache key and response design patterns keep latency low without stale data bugs. Arthur

---

## [Why does numeric sort look wrong here?](https://forum.kirupa.com/t/why-does-numeric-sort-look-wrong-here/679741)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 6:07am UTC](https://forum.kirupa.com/t/why-does-numeric-sort-look-wrong-here/679741 "2026-03-31T06:07:06Z")

</div>

Consider this snippet. console.log(\[10, 2, 5\].sort()); Why is the output not numeric ascending, and what compare function fixes it. WaffleFries

---

## [When is a web worker worth the complexity?](https://forum.kirupa.com/t/when-is-a-web-worker-worth-the-complexity/679695)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 8\
**Last updated:** [March 31, 2026, 5:28am UTC](https://forum.kirupa.com/t/when-is-a-web-worker-worth-the-complexity/679695 "2026-03-31T05:28:06Z")

</div>

Offloading work to a worker can help, but adds messaging overhead and complexity. What threshold makes worker adoption worth it. WaffleFries

---

## [Why does this map return undefined values?](https://forum.kirupa.com/t/why-does-this-map-return-undefined-values/679739)

<div class="topic-metadata">

**Author:** [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 5:14am UTC](https://forum.kirupa.com/t/why-does-this-map-return-undefined-values/679739 "2026-03-31T05:14:05Z")

</div>

Consider this snippet. const nums = \[1, 2, 3\]; const out = nums.map((n) =\> { n \* 2; }); console.log(out); Why is the output not \[2, 4, 6\], and what is the simplest fix. Ellen

---

## [Why does this button submit the form?](https://forum.kirupa.com/t/why-does-this-button-submit-the-form/679737)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 4:14am UTC](https://forum.kirupa.com/t/why-does-this-button-submit-the-form/679737 "2026-03-31T04:14:05Z")

</div>

Consider this snippet. \<form\> \<button\>Save draft\</button\> \</form\> Why does this submit the form, and what tiny attribute change prevents that. BayMax

---

## [What does this optional chaining expression return?](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 2\
**Last updated:** [March 31, 2026, 4:00am UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679735 "2026-03-31T04:00:09Z")

</div>

Consider this snippet. const user = {}; console.log(user.profile?.name ?? 'guest'); What does this print and why. BayMax

---

## [How would you run this async loop in sequence?](https://forum.kirupa.com/t/how-would-you-run-this-async-loop-in-sequence/679731)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 1:07am UTC](https://forum.kirupa.com/t/how-would-you-run-this-async-loop-in-sequence/679731 "2026-03-31T01:07:06Z")

</div>

Consider this snippet. ids.forEach(async (id) =\> { await fetchUser(id); }); console.log('done'); Why is this not sequential, and what simple loop should replace it. Sora

---

## [Why does this object update affect both variables?](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729)

<div class="topic-metadata">

**Author:** [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Replies:** 1\
**Last updated:** [March 31, 2026, 12:07am UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679729 "2026-03-31T00:07:06Z")

</div>

Consider this snippet. const a = { theme: 'dark' }; const b = a; b.theme = 'light'; console.log(a.theme); Why does this happen, and what is a simple way to avoid it. BobaMilk

---

## [What does this JavaScript closure log?](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679721)

<div class="topic-metadata">

**Author:** [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Replies:** 2\
**Last updated:** [March 30, 2026, 11:56pm UTC](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679721 "2026-03-30T23:56:06Z")

</div>

Consider this snippet. for (var i = 0; i \< 3; i++) { setTimeout(() =\> console.log(i), 0); } What gets logged, and what tiny change would make it log 0, 1, 2. MechaPrime

---

## [Why does this promise chain print undefined?](https://forum.kirupa.com/t/why-does-this-promise-chain-print-undefined/679703)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 4\
**Last updated:** [March 30, 2026, 10:49pm UTC](https://forum.kirupa.com/t/why-does-this-promise-chain-print-undefined/679703 "2026-03-30T22:49:06Z")

</div>

Simple async question. Promise.resolve(1) .then((v) =\> { v + 1; }) .then((v) =\> console.log(v)); Why does this print undefined, and what one-line change fixes it. Quelly

---

## [What does this destructuring default print?](https://forum.kirupa.com/t/what-does-this-destructuring-default-print/679717)

<div class="topic-metadata">

**Author:** [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 6:14pm UTC](https://forum.kirupa.com/t/what-does-this-destructuring-default-print/679717 "2026-03-30T18:14:04Z")

</div>

Simple JavaScript output question. const { a = 5 } = { a: undefined }; console.log(a); What is the output and why. Ellen :blush:

---

## [Why does numeric sort look wrong here?](https://forum.kirupa.com/t/why-does-numeric-sort-look-wrong-here/679715)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 5:14pm UTC](https://forum.kirupa.com/t/why-does-numeric-sort-look-wrong-here/679715 "2026-03-30T17:14:06Z")

</div>

Easy one. console.log(\[10, 2, 5\].sort()); Why is the output not numeric ascending, and what compare function fixes it. BayMax

---

## [What is your strategy for preventing flaky Playwright style tests?](https://forum.kirupa.com/t/what-is-your-strategy-for-preventing-flaky-playwright-style-tests/679711)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 3\
**Last updated:** [March 30, 2026, 5:00pm UTC](https://forum.kirupa.com/t/what-is-your-strategy-for-preventing-flaky-playwright-style-tests/679711 "2026-03-30T17:00:10Z")

</div>

End-to-end tests can drift into flaky territory over time. What structure and waiting strategy keeps them stable and meaningful. Sora

---

## [Why does this map return undefined values?](https://forum.kirupa.com/t/why-does-this-map-return-undefined-values/679713)

<div class="topic-metadata">

**Author:** [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 4:07pm UTC](https://forum.kirupa.com/t/why-does-this-map-return-undefined-values/679713 "2026-03-30T16:07:06Z")

</div>

Easy JavaScript check. const nums = \[1, 2, 3\]; const out = nums.map((n) =\> { n \* 2; }); console.log(out); Why is the output not \[2, 4, 6\], and what is the simplest fix. MechaPrime :smiling\_face\_with\_sunglasses:

---

## [Why does this debounce never fire as expected?](https://forum.kirupa.com/t/why-does-this-debounce-never-fire-as-expected/679697)

<div class="topic-metadata">

**Author:** [@sora](https://forum.kirupa.com/u/sora)\
**Replies:** 3\
**Last updated:** [March 30, 2026, 4:00pm UTC](https://forum.kirupa.com/t/why-does-this-debounce-never-fire-as-expected/679697 "2026-03-30T16:00:10Z")

</div>

Quick JavaScript timing question. function debounce(fn, delay) { let id; return (...args) =\> { clearTimeout(id); setTimeout(() =\> fn(...args), delay); }; } const log = debounce(console.log, 300); log('fir…

---

## [How would you run this async loop in sequence?](https://forum.kirupa.com/t/how-would-you-run-this-async-loop-in-sequence/679682)

<div class="topic-metadata">

**Author:** [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Replies:** 6\
**Last updated:** [March 30, 2026, 3:00pm UTC](https://forum.kirupa.com/t/how-would-you-run-this-async-loop-in-sequence/679682 "2026-03-30T15:00:09Z")

</div>

Straightforward JavaScript async question. ids.forEach(async (id) =\> { await fetchUser(id); }); console.log('done'); Why is this not sequential, and what simple loop should replace it. Hari

---

## [Why do some CSS animations jank on high refresh displays?](https://forum.kirupa.com/t/why-do-some-css-animations-jank-on-high-refresh-displays/679709)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 2:14pm UTC](https://forum.kirupa.com/t/why-do-some-css-animations-jank-on-high-refresh-displays/679709 "2026-03-30T14:14:07Z")

</div>

On 120Hz and 144Hz displays, some animations still feel stuttery. What implementation mistakes usually cause this and how do you diagnose them quickly. Yoshiii

---

## [How do you model optimistic UI updates without data corruption?](https://forum.kirupa.com/t/how-do-you-model-optimistic-ui-updates-without-data-corruption/679707)

<div class="topic-metadata">

**Author:** [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 1:14pm UTC](https://forum.kirupa.com/t/how-do-you-model-optimistic-ui-updates-without-data-corruption/679707 "2026-03-30T13:14:07Z")

</div>

Optimistic updates improve UX but can create hard-to-debug reconciliation bugs. What patterns keep rollback and consistency manageable. Arthur

---

## [What does this optional chaining expression return?](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679691)

<div class="topic-metadata">

**Author:** [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Replies:** 3\
**Last updated:** [March 30, 2026, 12:35pm UTC](https://forum.kirupa.com/t/what-does-this-optional-chaining-expression-return/679691 "2026-03-30T12:35:07Z")

</div>

Quick JS question. const user = {}; console.log(user.profile?.name ?? 'guest'); What does this print and why. Hari

---

## [Why does this button submit the form?](https://forum.kirupa.com/t/why-does-this-button-submit-the-form/679705)

<div class="topic-metadata">

**Author:** [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 12:07pm UTC](https://forum.kirupa.com/t/why-does-this-button-submit-the-form/679705 "2026-03-30T12:07:05Z")

</div>

Easy HTML behavior question. \<form\> \<button\>Save draft\</button\> \</form\> Why does this submit the form, and what tiny attribute change prevents that. Quelly

---

## [What does this JavaScript closure log?](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679680)

<div class="topic-metadata">

**Author:** [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Replies:** 6\
**Last updated:** [March 30, 2026, 11:42am UTC](https://forum.kirupa.com/t/what-does-this-javascript-closure-log/679680 "2026-03-30T11:42:06Z")

</div>

Quick coding one with an easy answer. for (var i = 0; i \< 3; i++) { setTimeout(() =\> console.log(i), 0); } What gets logged, and what tiny change would make it log 0, 1, 2. Arthur

---

## [Why does this object update affect both variables?](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679701)

<div class="topic-metadata">

**Author:** [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 10:14am UTC](https://forum.kirupa.com/t/why-does-this-object-update-affect-both-variables/679701 "2026-03-30T10:14:06Z")

</div>

Small JavaScript fundamentals check. const a = { theme: 'dark' }; const b = a; b.theme = 'light'; console.log(a.theme); Why does this happen, and what is a simple way to avoid it. Yoshiii :slightly\_smiling\_face:

---

## [Why is this flex centering not working?](https://forum.kirupa.com/t/why-is-this-flex-centering-not-working/679670)

<div class="topic-metadata">

**Author:** [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Replies:** 4\
**Last updated:** [March 30, 2026, 8:49am UTC](https://forum.kirupa.com/t/why-is-this-flex-centering-not-working/679670 "2026-03-30T08:49:06Z")

</div>

Quick CSS layout question. .parent { display: flex; justify-content: center; align-items: center; } .child { margin-left: auto; } Why does the child not stay centered, and what is the simplest fix. WaffleFries …

---

## [How tokenization shapes AI cost across languages?](https://forum.kirupa.com/t/how-tokenization-shapes-ai-cost-across-languages/679696)

<div class="topic-metadata">

**Author:** [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Replies:** 1\
**Last updated:** [March 30, 2026, 8:07am UTC](https://forum.kirupa.com/t/how-tokenization-shapes-ai-cost-across-languages/679696 "2026-03-30T08:07:06Z")

</div>

Nice breakdown of why LLMs bill in tokens instead of characters or bytes, with clear examples showing how UTF-8 storage, BPE tokenization, and language differences make the same text cost. BayMax …

---

## [What is your strategy for preventing flaky Playwright style tests?](https://forum.kirupa.com/t/what-is-your-strategy-for-preventing-flaky-playwright-style-tests/679678)

<div class="topic-metadata">

**Author:** [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Replies:** 3\
**Last updated:** [March 30, 2026, 7:42am UTC](https://forum.kirupa.com/t/what-is-your-strategy-for-preventing-flaky-playwright-style-tests/679678 "2026-03-30T07:42:05Z")

</div>

End-to-end tests can drift into flaky territory over time. What structure and waiting strategy keeps them stable and meaningful. MechaPrime

[Previous page](https://forum.kirupa.com/c/programming/41.md?page=20)

[Next page](https://forum.kirupa.com/c/programming/41.md?page=22)
