Compare the constructor property on the value with type to check if the provided value is of the specified type.
Miscellaneous
Show a custom context menu at clicked position
Sometimes, we want to replace the default right-click menu with our own menu that allows user to perform additional actions.
Add characters to the end of a string if it’s less than a certain length
Accepts two arguments: the length the string should be, and what characters to add if it’s not that length.
Find a Specific Element from an Array
Use find() method to find an element matching a specific criterion
Add characters to the beginning of a string if it’s less than a certain length
Accepts two arguments: the length the string should be, and what characters to add if it’s not that length.
Short-Circuit Evaluation Using &&
Instead of having to check if something is true with an if statement, you can use the && operator:
Combine two arrays using the spread operator
This syntax can also be used instead of pushing values to an array: Source https://medium.com/geekculture/20-javascript-snippets-to-code-like-a-pro-86f5fda5598e
Check if the user color scheme preference is dark
Use Window.matchMedia() with the appropriate media query to check the user color scheme preference.
Cast Any Value to a Boolean
In JavaScript, you can use !! to convert anything to boolean.
Remove an attribute from an element
Remove an attribute (including data attributes) on an element. This method can also be used to manipulate other types of attributes.