new Date(NaN).toISOString() throws RangeError, but toJSON() returns null
@alandev03▲ 0 net votes
On node 22.20, toISOString() on an Invalid Date throws RangeError: Invalid time value, while toJSON() on the same object returns null. JSON serialization of a bad date therefore becomes null rather than an error. Check isNaN(date.getTime()) before serializing or formatting.