Search

Nalezeno "Quick Tips": 131

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 set a default value instead of...

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 loop. To break the forEach loop at any point,...

Use a Submit Button Outside of !


Have you ever felt like you’ve been a professional developer or designer forever, and somehow not known something basic, and borderline hate yourself? That’s me with a trick that was introduced to me by Miguel Piedrafita: 🔥 You can submit forms from a button outside of the form...

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, but we can’t count...

git: Remove Untracked Files


I’ve always said that I know just enough about git to get the job done, but also do something destructive. Nothing embodies that more than my recent mistake. I somehow found a git repository full of untracked files and git stash wouldn’t fix it. Desperation led me to learning how...

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...

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 pasting information? It’s as easy as you’d...

How to Conditionally Add Attributes to Objects


JavaScript is full of tricks that you don’t know you want until you … want … them. Or maybe just until you see them. One trick I recently realized was conditionally adding attributes to React elements. Of course this trick essentially boils down to conditionally adding properties...

How to Create an Async Function


One thing I love about JavaScript is that there are many ways to accomplish the same task, one such example being creating functions. There are several patterns for functions; one of the last you see used is the new Function method: /* new Function(arg1, arg2 (...), body) */ const myFunction =...

Remove the Search Input Clear(x) Icon


I really appreciate the amount of different <input> elements we’ve received over the past decade. These elements don’t just bring a new semantic advantage, but also provide UI helpers, which in many cases are useful. In a recent case, I found a UI element not useful: the x (clear)...

Logical Assignment Operators


I love JavaScript, it’s my favorite programming language, but I love dipping into other languages because they offer a new perspective on coding paradigms. There’ve been syntax additions to JavaScript that I’ve seen I found interesting (think ?? in optional chaining) and now...

Match Emojis with Regular Expressions


When experimenting with unicode property escapes, to identify accented letters in strings, it reminded me of a question I had a few years ago: what is the best way to identify and then replace emojis in a string? I first noticed this practice when using emojis in Facebook — sometimes Facebook...

Match Accented Letters with Regular Expressions


Regular expressions are used for a variety of tasks but the one I see most often is input validation. Names, dates, numbers…we tend to use regular expressions for everything, even when we probably shouldn’t. The most common syntax for checking alphabetic characters is A-z but what...

Binding Arguments with Bind


One of my favorite and most essential Function method is bind, a function we added to MooTools when it wasn’t featured in the JavaScript language itself. We often think of using bind to simply bind a method’s call to its host object, but did you know you can also bind arguments with...

CSS background-repeat: round


The CSS spec is full of gems that sneak their way past most of us web designers and developers. Stuff like :focus-within, prefers-reduced-motion, and prefers-color-scheme suddenly make their way into CSS without us really finding out for months or years. One such example is background-repeat:...

Kotlin Coroutines and Delay


Whenever I suspect that there’s a timing conflict causing a problem with rendering and directives, I usually opt for a JavaScript setTimeout with a delay. The setTimeout code never makes it to production, but it does help me to understand if my code is the problem or if there’s a timing...

How to Fix ESLint Errors Upon Save in VS Code


Two of the most prominent utilities in web development today are ESLint and Microsoft’s Visual Studio Code. I enjoy using both, and I love the integration between both tools, but warnings from ESLint inside Visual Studio Code aren’t fulfilling — I’d rather lint errors...

How to Display Mode-Specific Images


Now that we have most of the basics of HTML and CSS in the browser, we’ve begun implementing new features that I would consider “quality of life” improvements, many of which have been inspired by mobile. One great example is the CSS prefers-color-scheme media query, which allows...

How to Simulate Long HTTP Requests


It happens less frequently these days but there are times when we need to accommodate for a HTTP request timing out. The service could be down, under heavy traffic, or just poorly coded, or any host of other issues. Whenever I need to simulate a long HTTP request, I use a bit of PHP...

Hex Opacity Table


We’ve used hex colors for years but 8-digit hexadecimal is still relatively new. While rgba is simple to understand, 8-digit hex is more difficult, as you need to provide a hex representation of a numeric value. The following is a hexadecimal chart of opacity! 100 FF 99 FC 98 FA 97 F7 96...

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace