Instead of using the indexOf() method to check if an element is in the array, you can use the includes() method.
Find the distance from a given element to the top of the document
Use getVerticalOffset to find the distance from a given element to the top of the document.
Create a custom scrollbar
You can customize the look and feel of the browser’s scrollbar by changing some CSS properties.
Transform all text in a string to uppercase
Use String.toUpperCase() to transform all text in a string to uppercase.
Default Function Parameters
Provide a default value to a function parameter.
Return all the elements of an array except the last one
Use Array.prototype.slice(0, -1) to return all but the last element of the array.
Show a loading indicator when an iframe is being loaded
This post demonstrates a common case where we show a loading indicator while an iframe is being loaded.
Remove leading and trailing whitespace from a string
Remove leading and trailing whitespace from a string.
Compress For Loops
Use the built-in forEach() method to loop through an array with one line of code.
Check if the provided value is of the specified type
Compare the constructor property on the value with type to check if the provided value is of the specified type.