Articles with the tag #tricks:

Image of code sample for the article: How to remove all HTML tags from a string?

How to remove all HTML tags from a string?

When counting text characters in HTML strings, you usually do not want to include the characters in the HTML markup code. While parsing HTML with RegExp does have its limits, in this case, RegExp works very well. …read more

Image of code sample for the article: How do you debounce in JavaScript?

How do you debounce in JavaScript?

When working with resource-intensive tasks or server calls in JavaScript there is often a need for reducing how often those functions run. It is therefore great to know some patterns for handling those problems. …read more

Image of code sample for the article: How can I add X days to a JavaScript Date object?

How can I add X days to a JavaScript Date object?

One of the more infamous sides of JavaScript has been its date and time constructs. After years of having to use Datejs/Moment.js for many date-handling tasks, I have found more and more that the native Date constructor is almost always good enough, saving many precious bytes to download. …read more

Image of code sample for the article: What are numeric separators?

What are numeric separators?

When working with large numbers it can be hard to read them out, try to read this value for example: …read more

Image of code sample for the article: JavaScript array methods and how to use them

JavaScript array methods and how to use them

Arrays are as central to JavaScript as in many other languages, in this article we will go through the most useful array methods along with creative usage examples. …read more

Image of code sample for the article: How to format numbers

How to format numbers

The native Intl.NumberFormat API lets you format numbers for specific languages without any external dependencies. …read more

Image of code sample for the article: Format

Format "5 days ago" localized relative date strings in a few lines with native JavaScript

The native Intl.RelativeTimeFormat API can generate nicely formatted relative date/time strings without any external dependencies. …read more

Image of code sample for the article: Use more ergonomic custom events

Use more ergonomic custom events

While we have CustomEvent for all of our events that need to carry data the need for the detail property nesting can feel a bit cumbersome. …read more

Image of code sample for the article: 10 great JavaScript tricks that will improve your productivity

10 great JavaScript tricks that will improve your productivity

These top tips and tricks will help you dramatically increase your productivity while coding in any JavaScript project. …read more

Image of code sample for the article: Why should I start using Optional Chaining and Nullish Coalescing operators?

Why should I start using Optional Chaining and Nullish Coalescing operators?

Gone are the days where you had to add incremental nullish (undefined or null) checks when fetching values in nested objects. Let's do more with less code. …read more

Image of code sample for the article: How-to create and use mixins in JavaScript

How-to create and use mixins in JavaScript

Mixins are handy when you want to share a feature across multiple classes without using inheritance as only some of the child classes should have that feature. …read more

Image of code sample for the article: How to use keyword arguments in JavaScript

How to use keyword arguments in JavaScript

Passing an Object named options to a function instead of separate arguments is one of the oldest tricks in the book, by also assigning an empty object by default you also reduce the amount of if statements needed at the top of the function. But a year ago I learned how combining this with object deconstruction made it so much more elegant. …read more

Image of code sample for the article: Rounding a number to a specific precision in JavaScript

Rounding a number to a specific precision in JavaScript

This is a tiny and handy function to round a number to a specific precision: …read more