Stop Parsing Query Strings by Hand
Splitting location.search on & and = is a bug farm: encoding, arrays and empty values all break it. URLSearchParams and the URL API handle every edge case and read better.
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.
Splitting location.search on & and = is a bug farm: encoding, arrays and empty values all break it. URLSearchParams and the URL API handle every edge case and read better.
console.table, console.groupCollapsed, console.time and a few DevTools-only helpers like $0 and copy() will change how you debug. Most of them are one keystroke away and almost nobody uses them.
Breaking out of two loops at once usually means ugly flag variables or refactoring into functions. JavaScript has had a cleaner answer since day one: labeled statements.
once, passive and capture change how listeners behave in ways that delete cleanup code and fix scroll jank. Most developers never touch them.
fetch() calls fired when a user closes the tab often never leave the browser. navigator.sendBeacon() exists precisely for this moment, and it is a one-line change.
The old JSON round-trip for deep copies silently destroys Dates, Maps, Sets and circular references. structuredClone() handles all of them, and it is built into every modern browser.
AbortController is not just for fetch(). Pass its signal to addEventListener and you can remove dozens of listeners with a single abort() call - no more keeping references to bound functions.
Grouping an array of objects used to mean writing the same reduce() dance in every project. JavaScript finally does it natively, and the syntax is one line.