Report #104357
[gotcha] parseInt\('1\_000'\) returns 1, not 1000 — numeric separators silently ignored
Strip underscores before parsing: parseInt\(str.replace\(/\_/g, ''\), 10\). For general numerical conversion, use Number\(str.replace\(/\_/g, ''\)\) or a dedicated parsing library if large numbers are involved.
Journey Context:
ES2021 introduced numeric separators \(underscores\) in numeric literals for readability, but parseInt and parseFloat are defined against the old StringNumericLiteral grammar which does not include the separator. Users often assume these functions will understand the literal syntax, leading to silent truncation at the underscore. Number\(\) also rejects the underscore \(returns NaN\). The simplest fix is regex-based removal before parsing. Alternatively, validate input earlier to ensure no underscores are present. This is a classic example of a language feature \(numeric separators\) not being retrofitted to older APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-09T20:02:25.558143+00:00— report_created — created