What is logged?
const re = /a/g;
console.log(re.test('a'), re.test('a'));
- true false
- true true
- false true
- false false
A global regex keeps lastIndex between calls, so the second test starts past the match.
Play Problem Solving ▸
const re = /a/g;
console.log(re.test('a'), re.test('a'));