_) to numeric values to make them more readable.
The idea of separating large numeric values with a special character might sound familiar on account of it being a syntax present in multiple other languages, such as Java, Python, Ruby etc. From what I can tell, numeric separators are at their best when creating shared constants that will not change and are very large, have many repeated digits and/or can be ambiguous.
Apart from readability, numeric separators don’t really offer anything else. For the sceptics among us that don’t really see a lot of readability value either, I’d like to show two rather convincing sample cases:
const msInOneYear = 31536000000; const price = 4200; const msInOneYear = 31_536_000_000; const price = 42_00;
Finally, as far as caveats go, you only need to remember that numbers cannot start or end with a numeric separator and that you can’t have two or more numeric separators in a row.