Check if a number is inside a given range with JavaScript
Check if the given number falls within the specified numeric range.
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.
Check if the given number falls within the specified numeric range.
Find the nth or every nth element of a JavaScript array.
Having trouble with inconsistent line endings in your strings? Normalize them with this handy JavaScript function!
Encode and decode strings with Base64 in JavaScript easily with these code snippets.
Using Document.elementFromPoint()
to easily get the element at a specific point on the page.
Avoid the naive approach and use a more robust method to edit URL parameters in JavaScript.
Learn the difference between cookies, local storage and session storage and start using the correct option for your needs.
A short guide on how to correctly construct a URL in JavaScript.
Recursive code tends to be inefficient or in need of optimization. Learn a couple of tricks we use to speed up our recursive functions.
There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
Learn everything you need to know about the conditional (ternary) operator and how to use it in JavaScript.
Learn how to get elements from the start or end of a JavaScript array by condition, using Array.prototype.slice()
.
Use a regular expression to remove HTML/XML tags from a string.
Test if a string's start or end partially matches another string.
Smooth-scrolls to the top of the page.
Remove non-printable ASCII characters from a string in JavaScript.
Combining Math.random()
and a few simple math operations, you can generate an array of random integers in a specified range.
Pure functions are a very important concept to know, especially if you're interested in functional programming.
Convert a number in bytes to a human-readable string.
Learn how to work with HTML element classes in JavaScript, from simple class checks to adding, removing and toggling classes.
A short introduction to the functional programming paradigm.
Learn how to work with whitespaces in JavaScript strings, using these simple yet powerful regular expression techniques.
Dynamically adding object properties can be pretty slow in some cases. Here's how to optimize it.
Calculate the number of days in a month for a given year using JavaScript.