JavaScript
The language itself: syntax, runtime behaviour and the habits that keep it readable.
2025
- Object.hasOwn replaces hasOwnPropertyUse Object.hasOwn to check for own properties on null-prototype objects or data that shadows hasOwnProperty.
- Handle money in JS with integer centsStore prices as integer cents so totals add without the 0.1 + 0.2 drift, and format with Intl.NumberFormat only for display.
- Escape HTML with a tagged templateWrite a tagged template that escapes HTML text, joins arrays and accepts markup from trusted strings.
- Predict console.log order: microtasks before timersPredict the output of a short script by following synchronous code, the microtask queue and a zero-delay timer.
- Keep the original error with causePass the caught error as cause when you rethrow so Node can show the original failure alongside your message.
- structuredClone vs JSON copy: what breaksCompare what JSON copying and structuredClone do with dates, collections, cycles, functions and class instances.
- Format "3 days ago" with Intl.RelativeTimeFormatUse Intl.RelativeTimeFormat to write labels such as "3 days ago" and "yesterday" in the reader’s locale.
- Top-level await and module load orderTrace how top-level await delays dependent modules while an independent branch of the import graph runs.
- Import JSON modules with import attributesUse the type: json import attribute to load a JSON module in Node or a browser, with static or dynamic imports.
2023
- Cancel and time out fetch requestsSet your own fetch deadline with AbortSignal.timeout or cancel an in-flight request with AbortController.
- Read from the end with Array.atUse .at(-1) to read an array’s last item, with undefined as the result when the array is empty.
- Array.sort sorts numbers as stringsWithout a comparator, sort() compares numbers as text, so 100 lands before 9. Pass (a, b) => a - b and copy the array first.
- Find heavy dependencies with a Vite treemapAdd rollup-plugin-visualizer to a Vite build, read the treemap, and shrink the biggest rectangle by changing one import.
- Fix stale closures in intervals with refsLet a React interval read the latest state through a ref without resetting the timer on each edit.
- Why async forEach never waitsAn async callback inside forEach runs, but nothing waits for it. Use for...of to run calls in order or Promise.all to run them together.