JavaScript’s Syntactic Quirks

Jason Orendorff looked into the JS spec, in detail … JavaScript is rather hard to parse. Here is an in-depth accounting of its syntactic quirks, with an eye toward actually implementing a parser from scratch. One quirk most JS devs have will have certainly heard of is Automatic Semicolon Insertion (ASI). JavaScript’s Syntactic Quirks →

The Quest for the Perfect Dark Mode Toggle, using Vanilla JavaScript

In The Quest for the Perfect Dark Mode, Joshua W Comeau extensively explains how he has implemented the Dark Mode Toggle on his Gatsby-powered website. It follows the system’s light/dark mode preference, but also allows for an override which he persists in localStorage. The flow to decide if Dark Mode should be used or not […]

The Cost of Javascript Frameworks

Tim Kaldec has measured the JavaScript bytes and the JavaScript CPU time for a bunch of sites. Right now, if you’re using a framework to build your site, you’re making a trade-off in terms of initial performance—even in the best of scenarios. Some trade-off may be acceptable in the right situations, but it’s important that […]

Schedule local notifications that don’t require a network connection with the Notifications API

As of Chrome 80, the Notifications API became available as an Origin Trial. The problem with the Push API is that it’s not reliable for triggering notifications which must be shown when a particular condition, like time or location, is met. Notification triggers solve this problem by letting you schedule notifications with their triggering condition […]

useAbortController – A React Hook to work with the AbortController

Kent C. Dodds recently floated this snippet around, a React Hook to easily work with the the AbortController: function useAbortController() { const abortControllerRef = React.useRef() const getAbortController = React.useCallback(() => { if (!abortControllerRef.current) { abortControllerRef.current = new AbortController() } return abortControllerRef.current }, []) React.useEffect(() => { return () => getAbortController().abort() }, [getAbortController]) const getSignal = […]

Understanding Default Parameters in JavaScript

In ECMAScript 2015, default function parameters were introduced to the JavaScript language. These allow developers to initialize a function with default values if the arguments are not supplied to the function call. Initializing function parameters in this way will make your functions easier to read and less error-prone, and will provide default behavior for your […]

Pass Data from CSS to JavaScript with CSS Variables

What happens when you combine the fact that part after the : for CSS Custom Properties doesn’t need to be valid CSS with window.getComputedStyle()? You get a way of passing data – including Arrays, Objects, and even JSON – from CSS to JavaScript. Psst… Hey kid… Did you know you can pass data from your […]