JavaScript Tutorials
navigator.clipboard API
Interacting with a user's host clipboard is something web developers have wanted for both good and evil purposes. On the good side, it's nice to allow users to easily copy text like wallet addresses or branch names; for evil, copying malicious text that the user...
Return a Default Value with Promises Using catch
Last week I tweeted all of you looking for your best JavaScript Array and Promise tricks, and as always, it didn't disappoint -- I learned quite a bit!Today's JavaScript Promise trick is brought to you by Claudio Semeraro: how to use
catch
to...Break a forEach Loop with JavaScript
I've written a number of blog posts about JavaScript tricks: Promise tricks, type conversion tricks, spread tricks, and a host of other JavaScript tricks. I recently ran into another JavaScript trick that blew my mind: how to break a
forEach
React.isValidElement
Knowing what input type you've received is hugely important in JavaScript, which is a big reason for Flow and TypeScript's rise. One such case where it's useful to know what an object represents is if the input is a string or a React element.To detect...
Detect Generator Functions with JavaScript
In the current JavaScript climate of new syntaxes, features, and using loads of external libraries, it seems harder than ever to be sure what your functions are being given or even what the data represents. Of course, we've come up with Flow and TypeScript to help...
Node isConnected
Every so often I discover a property in JavaScript objects that I didn't know existed, oftentimes using another trick to accomplish the same functionality. One such property I just learned about was
isConnected
, a node property that attached to a context (i.e.document
).Here's how to...Limit Promise Concurrency with pool
Methods like
Promise.all
,Promise.allSettled
,Promise.race
, and the rest are really excellent for managing multiple Promises, allowing for our apps to embrace async and performance. There are times, however, that limiting the number of concurrent operations may be useful, like rate limiting or simply not wanting...cookieStore: Async Cookie API
One pattern in the JavaScript API world that web development veterans will notice is that we've been creating new methods to accomplish what older, grosser APIs once achieved.
XMLHttpRequest
became thefetch
API, some APIs like Battery became async, and there are dozens of other examples.How to Prevent Pasting into an Input
Every once in a while I get to a website that doesn't allow me to paste into a form input. In most cases it's something to do with login credentials (username and or password) and auth codes. So how are they preventing me from...
How to Detect When a Sticky Element Gets Pinned
The need for
position: sticky
was around for years before it was implemented natively, and I can boast that I implemented it with JavaScript andscroll
events for ages. Eventually we gotposition: sticky
, and it works well from a visual perspective, but I wondered how...