Javascript - Date to Milliseconds

Introduction

valueOf() method returns the milliseconds representation of the date.

The less-than and greater-than operator is using this method to compare date value.

Demo

var date1 = new Date(2007, 0, 1);          //"January 1, 2007"
var date2 = new Date(2007, 1, 1);          //"February 1, 2007"

console.log(date1 < date2);  //true
console.log(date1 > date2);  //false

Result

The date January 1, 2007, comes before February 1, 2007.

The milliseconds representation of January 1, 2007, is less than that of February 1, 2007.