JS Built-ins
← Date116 / 120
DatevalueOfbeginner

valueOf() β€” epoch returns 0

πŸ“– 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()

Returns the same primitive value as getTime() β€” milliseconds since the Unix epoch.

Challenge: Verify that new Date(0).valueOf() returns 0.

πŸ’‘ Hints (1)
  • β€’ valueOf() returns the numeric timestamp β€” just like getTime()