JSintroes2021

Modern string methods

Slice, pad, and scan strings without the old workarounds.

A cluster of newer String methods — replaceAll, at, padStart/padEnd, trimStart/trimEnd, and matchAll — replace regex tricks and substring math with named, readable one-liners that also respect Unicode code points.

replaceAll changes every match

JSintro
Press Run to execute

replace stops after the first - (a/b-c-d) while replaceAll rewrites them all (a/b/c/d); the final line shows a global regex collapsing each run of whitespace into one _ (1_2_3_4) — proof the regex form works when the g flag is present.