javascript

  • Promise.allSettled, for when one failure must not lose the rest

    Promise.all rejects on the first failure and discards every other result, including the ones that had already succeeded. The result objects have a status discriminator rather than being…

  • BigInt exists, and JSON does not know about it

    An identifier larger than 2^53 loses precision as a JavaScript number, and BigInt fixes the arithmetic and not the transport. This is the reason well-designed APIs return large…

  • A dynamic import is a promise and a chunk boundary

    The syntax looks like a function call and is a language feature, and a bundler recognises it as a split point with no configuration at all. The chunk-load…

  • AbortController, and the search that races itself

    A type-ahead fires a request per keystroke and the responses arrive out of order, so the results for a shorter query can overwrite the results for a longer…

  • Lazy loading arrived in the browser

    One attribute replaces an IntersectionObserver and a library — and applying it to everything makes the Largest Contentful Paint worse rather than better.

  • A stale closure in an effect, and the two ways out

    An effect with an empty dependency array captures the first render’s variables permanently, so a timer set up once reads values that stopped being current seconds later. A…

  • The new JSX transform, and the React import that goes away

    Every file using JSX had to import React even when it never referenced it, because JSX compiled to React.createElement. The compiled output imports react/jsx-runtime instead, which is a…

  • CSS custom properties, read and written from JavaScript

    A theme value duplicated in a stylesheet and in a JavaScript constant is two sources of truth, and custom properties are readable and writable from both. The trim()…

  • useMemo is a hint, not a guarantee

    The documentation says React may discard memoised values to free memory, and code that treats useMemo as a cache with a guarantee is relying on something that is…

  • globalThis, and the four ways it used to be written

    A library that runs in a browser, in Node and in a worker had four different names for the global object and a small dance to pick one.…