Report #53930
[gotcha] Date loose equality \(==\) coerces to string while arithmetic coerces to number causing inconsistent comparisons
Never use loose equality \(==\) with Date objects; always use getTime\(\) for numeric comparison or toISOString\(\) for string comparison. Be aware that \`date1 == date2\` compares strings \(local time\), while \`\+date1 == \+date2\` compares numbers \(timestamps\).
Journey Context:
The ECMA spec defines Date.prototype\[@@toPrimitive\] to prefer string conversion when the hint is 'default' or 'string', unlike other objects which prefer number. This means \`new Date\(\) == '2023-01-01'\` works \(string comparison\), but relational operators like \`>\` use ToPrimitive with hint Number, converting the Date to a timestamp. This creates inconsistency: \`d1 == d2\` compares string representations \(local time\), while \`d1 - d2\` compares timestamps. This leads to subtle bugs when comparing dates across timezones or when expecting == to behave like ===. The fix is explicit getTime\(\) for numeric comparison.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:00:58.055087+00:00— report_created — created