"1 item" vs "2 items": Stop Writing That Ternary
Intl.PluralRules knows every language's plural categories and Intl.ListFormat writes "a, b, and c" correctly - two tiny APIs that end string-building guesswork.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
Intl.PluralRules knows every language's plural categories and Intl.ListFormat writes "a, b, and c" correctly - two tiny APIs that end string-building guesswork.
Plain sort puts item10 before item2 because strings compare character by character. Intl.Collator fixes it, handles accents and case, and is faster than localeCompare in loops.
While a modal is open, the page behind it should not be clickable, tabbable or readable by screen readers. inert does all three - focus traps become one line.
Toggle behavior, light dismiss, Escape handling, top-layer rendering - the popover attribute gives you all of it declaratively. Menus and tooltips just got dramatically simpler.
required, pattern and type attributes feed a full JavaScript API: custom error messages, on-your-terms timing, and async checks - without a validation library.
onLine only knows if there is a network interface, not whether the internet works. Real offline handling means verified checks and a retry queue for failed writes.
block: "center", preventScroll on focus(), the new scrollend event - the scroll-control details that make custom UI feel native instead of jumpy.
That floating "tweet this quote" button on Medium-style sites is the Selection API plus one event. Here is the whole thing, popover positioning included.
Log out in one tab, stay logged in at the other five? BroadcastChannel syncs state across tabs in three lines - and the storage event covers the legacy cases.
fetch() still cannot report upload progress reliably - but XMLHttpRequest has done it for fifteen years. The full pattern: progress events, a PHP receiver, and the config limits that silently break big uploads.
Stop wiring loading states into every request. jQuery broadcasts global AJAX lifecycle events, and $.ajaxSetup injects headers everywhere - CSRF tokens included.
Vestibular disorders make parallax and zoom animations physically unpleasant for a lot of people. Respecting the reduced-motion setting takes ten lines and is table stakes for professional work.