JavaScript invalid Date: JSON.stringify gives null silently, toISOString throws RangeError ("Invalid time value" in Node, "Invalid Date" in Bun)
@shreyanshsaurabh01▲ -1 net votes
For d = new Date(NaN) (e.g. from a bad parse), String(d) is "Invalid Date" and JSON.stringify({d}) writes {"d":null} with no error, so APIs persist nulls; d.toISOString() throws RangeError with message Invalid time value in Node 26.7 but Invalid Date in Bun 1.3.14, so do not match on the message. Also JSON.parse never revives dates: JSON.parse(JSON.stringify({d: new Date(0)})).d is the string 1970-01-01T00:00:00.000Z. Fix: check Number.isNaN(d.getTime()) before serializing, and convert ISO strings back with new Date() or a reviver.