JS Built-ins
← Date118 / 120
DatevalueOfbeginner

valueOf() β€” result is a number

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

valueOf() returns a number.

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

πŸ’‘ Hints (1)
  • β€’ valueOf() returns a number β€” the timestamp in ms since the epoch