const s='##-#';
const r=/#/g; r.lastIndex=1;
r.exec(s) .index=1 .lastIndex updated
r.test(s) true .lastIndex updated
s.replace(r, 'x') "xx-x" .lastIndex reset
s.replaceAll(r, 'x') "xx-x" .lastIndex reset
s.match(r) ["#","#","#"] .lastIndex reset
s.matchAll(r) [["#"],["#"]] .lastIndex unchanged
const r=/#/y; r.lastIndex=1;
r.exec(s) .index=1 .lastIndex updated
r.test(s) true .lastIndex updated
s.replace(r, 'x') "#x-#" .lastIndex updated
s.replaceAll(r, 'x') TypeError
s.match(r) .index=1 .lastIndex updated
s.matchAll(r) TypeError
const r=/#/yg; r.lastIndex=1;
r.exec(s) .index=1 .lastIndex updated
r.test(s) true .lastIndex updated
s.replace(r, 'x') "xx-#" .lastIndex reset
s.replaceAll(r, 'x') "xx-#" .lastIndex reset
s.match(r) ["#","#"] .lastIndex reset
s.matchAll(r) [["#"]] .lastIndex unchanged
(Older versions of .matchAll()
don’t throw a TypeError
if /g
is not set.)