The valueOf()
method for the Date type doesn't return a string.
It returns the milliseconds of the date.
It works with operators, such as less-than and greater-than.
Consider this example:
let date1 = new Date(2019, 0, 1); // "January 1, 2019" let date2 = new Date(2019, 1, 1); // "February 1, 2019" console.log(date1 < date2); // true console.log(date1 > date2); // false
The date January 1, 2019, comes before February 1, 2019.
The milliseconds representation of January 1, 2019, is less than that of February 1, 2019.
Return the primitive value of a Date object:
var d = new Date(); var n = d.valueOf(); console.log(n);/*from w ww. j av a2 s .co m*/