JS Built-ins
← Date119 / 120
DatevalueOfbeginner

valueOf() β€” positive for modern dates

πŸ“– Usage Example
const d = new Date('2024-01-15T00:00:00.000Z')
d.valueOf()  // β†’ 1705276800000
d.valueOf() === d.getTime()  // β†’ true

Use valueOf() to get the millisecond timestamp of a Date; it equals getTime() and is called automatically in arithmetic expressions.

Date.prototype.valueOf()

For any date after 1970, valueOf() returns a positive number.

Challenge: Verify that new Date('2024-01-15T00:00:00.000Z').valueOf() > 0.

πŸ’‘ Hints (1)
  • β€’ Dates after 1970 have positive timestamps