JavaScript Tutorials
Background Sync with Service Workers
Service workers have been having a moment. In March 2018, iOS Safari began including service workers -- so all major browsers at this point support offline options. And this is more important than ever -- 20% of adults in the United States are without Internet at...
Nested Destructuring
Destructuring in JavaScript can initially feel confusing but the truth is that destructuring can make your code a bit more logical and straight forward. Destructuring does look a bit more complex when you're looking for a property several objects deep, so let's have a look...
Force Download with JavaScript
Force download scripts have been an important part of internet usability for a long time. I can attest to that by the number of times I've implemented this feature on the server side and the popularity of my PHP Force Download post, even to this...
JavaScript waitForever
Writing mochitests for new features in DevTools can be difficult and time-consuming. There are so many elements interacting in an async manner that I oftentimes find myself using the debugger to debug the debugger! In the case where it's unclear what interaction isn't working properly, I...
Get Viewport Lines and Columns in CodeMirror
CodeMirror is an amazing utility for presenting code in a browser environment. Syntax highlighting, widgets, and a number of advanced functions make it a unique, useful tool. When using CodeMirror inside the Firefox DevTools debugger, I found that adding hundreds of column breakpoint widgets to very...
Object.fromEntries
The
Object
object has been buffed with useful methods over the past few years.Object.keys
,Object.values
,Object.freeze
, andObject.assign
all address frequently desired functionality. One of the newObject
methods isfromEntries
, which accepts a Map or map-like array nesting and converts it to a useful object literal! Convert Map...How to Get and Set CSS Variable Values with JavaScript
CSS variables are a very welcome addition to the language, despite them being incredibly basic. Sure we could use SASS or stylus but languages should never count on developers relying on frameworks and toolkits to accomplish what we know we need. And just like every other...
Aliases with JavaScript Destructuring
Destructuring in JavaScript has totally changed the way JavaScript is written these days; code is more concise to write but but, from a visual standpoint, the syntax of the language has changed so much. Any good developer knows, however, that change is the constant we live...
Object.freeze: Immutable Objects
One of my favorite part of JavaScript has always been mutability of objects. I loved that MooTools and likewise frameworks could modify native prototypes to enhance them with functionality we knew the language need; in fact, I credit MooTools with pushing the web forward. There are cases...
Array and Boolean
One of the annoyances of old-school JavaScript was side effects; then
Array.prototype
got methods likefilter
,map
, andforEach
so we didn't need to burn variables before looping over values. I can't explain how happy I am that the JavaScript language continues to evolve. Every once in a...