Indent a JavaScript string
Indent each line in a string by a specified number of spaces or a custom indentation character.
The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.
Indent each line in a string by a specified number of spaces or a custom indentation character.
Learn all you need to know about the differences between JavaScript's double equals and triple equals operators.
You've probably come across the double negation operator (!!
) before, but do you know what it does?
Figure out the exact number of bytes in a JavaScript string, including Unicode characters.
Aborting a fetch request in JavaScript is a common problem. Here's how to handle it correctly.
A quick, one-liner to generate a random boolean value in JavaScript.
Pad a string on both sides with the specified character, if it's shorter than the specified length.
An Immediately Invoked Function Expression (IIFE) is a JavaScript trick that trips up many developers. Here's what you need to know.
Implement Python's divmod()
built-in function in one line of JavaScript.
Did you know there's a JavaScript value that's not equal to itself?
Use a media query to check if the user prefers a light or dark color scheme.
Easily and reliably calculate the width of the browser's vertical scrollbar with JavaScript.
Learn how to create a generator function that keeps producing new values as long as the given condition is met.
When it comes to immutability, JavaScript strings are often a source of confusion. Yet they're not as complicated as you might expect.
While both the prefix and postfix operators increment a value, the resulting value of the expression is very different.
Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.
Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.
JavaScript distinguishes expressions and statements. Learn their differences in this short article.
Copy the sign of one number to another without changing its absolute value.
Object.is()
and the triple equals operator (===
) can both be used for equality checking in JavaScript, but when should you use each one?
Ever wanted to reload a module in Node.js? Here's how you can do it.
Did you know you can use Chrome Developer Tools to debug your Node.js code? Find out how in this short guide.
Can you tell if two URLs are on the same origin? Here's a very simple way to do so.
Calculate the logarithm of a number or check if a number is a power of a specific base.