Spot the bug in timestamp serialization

from Date
Node 24 beginner 4 min 1 issue to find

Find why invalid input reaches toISOString and throws.

JavaScript
function serializeTimestamp(value) {
  const date = new Date(value);
  if (!date) return null;
  return date.toISOString();
}

console.log(serializeTimestamp('not-a-date'));
Open in playground
Report an error