JavaScript Tutorials
How to Extend Prototypes with JavaScript
One of the ideological sticking points of the first JavaScript framework was was extending prototypes vs. wrapping functions. Frameworks like MooTools and Prototype extended prototypes while jQuery and other smaller frameworks did not. Each had their benefits, but ultimately all these years later I still...
How to Use window.crypto in Node.js
I've been writing a bunch of jest tests recently for libraries that use the underlying
window.crypto
methods likegetRandomValues()
andwindow.crypto.subtle
key management methods. One problem I run into is that thewindow.crypto
object isn't available, so I need to shim it.To use thewindow.crypto
...Convert Fahrenheit to Celsius with JavaScript
The United States is one of the last bodies that refuses to implement the Celsius temperature standard. Why? Because we're arrogant and feel like we don't need to change. With that said, if you code for users outside the US, it's important to provide localized weather...
Detect System Theme Preference Change Using JavaScript
JavaScript and CSS allow users to detect the user theme preference with CSS'
prefers-color-scheme
media query. It's standard these days to use that preference to show the dark or light theme on a given website. But what if the user changes their preference...How to Use Storage in Web Extensions
Working on a web extension is an interesting experience -- you get to taste web while working with special extension APIs. One such API is
storage
-- the web extension flavor of persistence. Let's explore how you can usesession
andlocal
storage within...Skip or Only Run a Test with JavaScript Mocha
Whenever I start to feel anxiety about a big change I'm making, I start writing more unit tests. I'll write down my fear and then write a test that attacks, and eventually relaxes, that fear. There are two actions that I've been frequently using...
Monitor Events and Function Calls via Console
Despite having worked on the very complex Firefox for a number of years, I'll always love plain old
console.log
debugging. Logging can provide an audit trail as events happen and text you can share with others. Did you know that chrome providesmonitorEvents
and...Specify Node Versions with .nvmrc
I've heavily promoted nvm, a Node.js version manager, over the years. Having a tool to manage multiple versions of a language interpreter has been so useful, especially due to the complexity of Node.js package management.One tip I like to give new developers is adding a...
How to Inject a Global with Web Extensions in Manifest V3
For those of you not familiar with the world of web extension development, a storm is brewing with Chrome. Google will stop support for manifest version 2, which is what the vast majority of web extensions use. Manifest version 3 sees many changes but the largest...
JavaScript Event.defaultPrevented
Whether you started with the old
on_____
property oraddEventListener
, you know that events drive user experiences in modern JavaScript. If you've worked with events, you know thatpreventDefault()
andstopPropagation()
are frequently used to handle events. One thing you probably didn't know: there's adefaultPrevented
...