Use the less than operator (<
) to check if the first date comes before the second one.
const isBeforeDate = (dateA, dateB) => dateA < dateB;
// Example
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
Source
https://www.30secondsofcode.org/js/s/is-before-date