Blog
Code Snippets.
Short pieces of code that solve one problem, with the reasoning behind them.
6 postsRSS feed
Simplify Popups with HTML Popover API
Learn how to effortlessly create accessible popups, tooltips, and modals using the native HTML Popover API, reducing custom JavaScript and improving user experience.
Simplify Promise Handling with Promise.withResolvers
Learn how the new Promise.withResolvers static method streamlines common asynchronous patterns in JavaScript, reducing boilerplate and improving code clarity.
Web Workers: move heavy work off the main thread
Heavy JavaScript freezes the page because it shares a thread with the interface. A Web Worker runs that work in the background. A working example and the limits to know.
Promise.allSettled: keep the results that succeeded
Promise.all throws away every result when one request fails. Promise.allSettled waits for all of them and reports each outcome, so one failure cannot empty a page.
Intersection Observer: react when elements scroll into view
Scroll listeners that measure element positions are slow and fiddly. Intersection Observer tells you when an element enters the viewport, with a few lines of code.
structuredClone: deep copy objects in JavaScript
The spread operator copies only one level, and the JSON trick loses dates and breaks on cycles. structuredClone makes a true deep copy with one built-in call.
Tell us what’s in the way.
A few lines is enough. You get a candid yes, a candid no, or a sharper question.
- Working software in week four
- A reply in one business day
- Handover is the deliverable
Prefer email? hello@2haas.com