??=, ||= and &&=: The Assignment Operators Nobody Told You About
ES2021 added three assignment operators that collapse the most common if-statements in JavaScript. Knowing when ??= beats ||= is the part that matters.
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.
ES2021 added three assignment operators that collapse the most common if-statements in JavaScript. Knowing when ??= beats ||= is the part that matters.
Escaped slashes, mangled unicode, silent failures returning false - json_encode ships with defaults from another era, and five flags fix all of it.
strtotime and DateTime parse a small English grammar - "last day of next month", "second friday of january" - that replaces whole functions of calendar math.
ob_start() plus include turns any PHP file into a string-returning template - the exact mechanism template engines are built on, useful raw for emails, PDFs and HTML fragments.
match() is not just a stricter switch. Feed it true as the subject and every arm becomes an arbitrary condition - an elegant, exhaustive replacement for elseif ladders.
The third parameter turns array_column into a re-indexing tool, it reads object properties, and combined with array_map it handles most of your collection reshaping.
The lobotomized owl, :not(:last-child) margins, negative-margin wrappers - all workarounds for spacing between flex items. gap has worked in flexbox everywhere since 2021.
List bullets and text-highlight colors are both fully styleable with dedicated pseudo-elements - no list-style: none rebuilds, no browser defaults clashing with your brand.
Stop writing a font-size media query for every breakpoint. clamp() scales type smoothly with the viewport between a floor and a ceiling you control.
A headline that wraps leaving one lonely word on the second line looks broken. text-wrap: balance makes the browser distribute the words evenly, and text-wrap: pretty fixes paragraphs.
Custom checkbox hacks - hidden inputs, pseudo-element ticks, sprite images - solved a problem that accent-color now handles in a single declaration.
new FormData(form) reads every field in one call, posts natively with fetch, and Object.fromEntries turns it into JSON. You may never write form.elements loops again.