About

JavaScript Guide

Language internals, runtime, frameworks — how things work at code level

Browser APIs

Web Workers — How to Use Multi-Threading in JavaScript

Structured Clone of postMessage and SharedArrayBuffer

Web Workers run JavaScript on a separate thread from main. No DOM access, communicate via postMessage. Offload heavy computation to Workers to keep UI responsive.

Service Worker Lifecycle — The Order of install, activate, fetch

The core of PWA — how offline caching works

Service Workers act as proxies between browser and network. Lifecycle: install → activate → fetch. Cache API stores resources for offline app functionality.

Intersection Observer — Detect Element Visibility Without Scroll Events

Performance-friendly implementation for lazy loading, infinite scroll, animation triggers

Intersection Observer fires callbacks when elements enter/exit the viewport. Better performance than scroll events + getBoundingClientRect(), executed at browser-optimized timing.

Popover API — Why You Can Now Build Tooltips Without JavaScript

A single popover attribute handles open/close, Esc dismissal, and accessibility automatically

Traditional tooltips required event listeners, state management, and manual ARIA synchronization. The Popover API replaces all of that natively. Just popover and popovertarget attributes handle open/close, Esc key, and keyboard navigation automatically.

Cookie, localStorage or sessionStorage — Three Questions Decide It

Why the folder tree went to a cookie and the scroll position to sessionStorage on the same screen

Does the server read it, must the first HTML show it, should it survive closing the tab. Ask in that order and almost everything sorts itself out. Secrets skip the questions and go to an HttpOnly cookie.

event.target vs currentTarget — The Bug That Only Fired on the Icon Stroke

Read data-* from currentTarget. SVG only takes clicks on painted strokes

When you read data-* from the element that owns the listener, use event.currentTarget. event.target is the innermost element actually clicked, so hitting the stroke of an SVG icon inside a button gives you a <path> and undefined.

Web Audio

Drums on setInterval Drift — Say "Play at 0.55s", Not "Play Now"

A lookahead scheduler: the JS timer only wakes things up, the audio clock does the timing

To keep time in the browser, don't play sounds directly in a timer callback. Wake every 25ms and schedule the next 0.1s of notes on the AudioContext clock. Under the same interference, setInterval wobbled between 114 and 136ms; the scheduled version stayed on its 0.5s grid.

"Left Ear Only" Means Two Things — StereoPanner Moves, ChannelSplitter Picks

pan: -1 doesn't drop the right channel, it folds it into the left. Measured

Earphones just play the L/R they receive. On the web, StereoPannerNode with pan: -1 moves the right channel into the left, while ChannelSplitter keeps only the left channel and drops the right. Both leave the right ear silent, but the left ear hears different things.

Test Audio With AnalyserNode, Not the Screen — Why All 17 Demos Looked Silent in a Background Tab

The drawing stops, the sound doesn't. Measuring the peak also catches clipping

If you check audio demos through browser automation by looking at a canvas waveform, requestAnimationFrame pauses in background tabs and everything reads as silent. Measure the peak from AnalyserNode's time-domain data instead and you catch both silence and clipping (above 1). It found three clipping cases for us.

Strudel Is Great for Beat Sketches, Weak for Finished Tracks — and Lazy Importing It Silently Drops Effects

Notes from embedding it in an app, plus the audio init trap that waits for "the next mousedown"

Strudel is strong at tweaking loops on the fly and weak at finishing a song or shipping inside a product. Its bundle (about 659KB) made us dynamic-import it on click, and then audio init waited for a mousedown that had already happened, so AudioWorklet effects like shape dropped out with no visible error. Firing one mousedown yourself fixes it.