Member-only story
25 JavaScript Tricks You Need To Know About
Including some useful bits of code and utilities

While coding, you will notice that there are some things you stumble upon over and over, and normally they beg for that quick solution. A lot of these things do not even need you to install a library to solve them. These are my top 25 collected over the years.
1. Type check utility
JavaScript is not a strongly typed language and to get that your best solution is TypeScript which I recommend but, sometimes all you need is a simple type check which JavaScript allows you to do with the “typeof” keyword.
The problem with “typeof” is that if you use it for some primitives and functions it works great but for arrays and objects it becomes hard to know the difference since they are both considered “objects”

2. Check for empty
Sometimes you just need to know if something is empty and depending on what you are checking, you need to use different methods like, checking the length, size, or if it contains any child elements. This util unifies all of that allowing you to check the size of String, Object, Array, Map, and Set.

3. Get any list last item
Other languages make this a method or function you can call on the array, but for JavaScript, you need to do some work.

4. Random number generator with a range
If sometimes you need to generate random numbers but you want these numbers to be in a range, you need this small utility.