These are a collection of tips and tricks you can use to improve the performance and readability of your code.
Infinity is just a number, dude. Most calculations JavaScript lets us do with Infinity will still return Infinity. Some no longer return numbers.
With JavaScript’s built-in formatter for relative timestamps, we can build strings like “2 months from now” without third party libraries.
By combining regular expressions and parseFloat, we can create a helper function that extracts all float values from a text input.
Combining the map function on arrays and type constructors allows us to quickly map values from one type to another.
The ternary operator can be used at many levels. The further we move it into a statement, the more duplication it can save us.
Using .replace() on strings only replaces the first occurrence of a substring by default. We can extend that with a “global” flag on the expression.
Regular JavaScript has no concept of required parameters. We can use default parameter values to emulate this feature.
If an expression returns a Boolean value, we don’t also need to compare that result to true or false.