A robust way to compare two arrays (or objects) and check if they’re equal to each other.
Prevent the default action of an event
Use the preventDefault() method. This method works with inline attribute.
Get and Set Scroll Position of an Element
To set or get the scroll position of an element, you use the properties scrollTop and scrollLeft of the element.
Check if a date is between two other dates
Use the greater than (>) and less than (<) operators to check if date is between dateStart and dateEnd.
Get the Children of an Element
To get the children of an element, you use the childNodes property of the element.
Scroll to an element smoothly
This snippet produces a smooth scrolling implementation which also allows us to customize the animation effect and duration.
Scroll to top of the page
Utilizing this snippet, you can add a button at the bottom of page that allows user to scroll to the top quickly.
Check if the browser tab of the page is focused
Use the Document.hidden property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.
Get Siblings of an Element
This snippet gets the next sibling and previous sibling of an element, using the element.nextSibling and element. previousSibling properties.
Generating random numbers with JavaScript
In this snippet, look at how to get a random integer between two numbers.