1. const digits = /\d+/g;
    2. digits.test("Hello world! 123");
    3. // true
    4. digits.test("321"); // !!!!!!surprise
    5. // false
    6. digits.test("321");
    7. // true

    Wield right?

    When a regex has the global flag set, test() will advance the lastIndex of the regex. (RegExp.prototype.exec() also advances the lastIndex property.) Further calls to test(str) will resume searching str starting from lastIndex. The lastIndex property will continue to increase each time test() returns true.

    Note: As long as test() returns true, lastIndex will not reset—even when testing a different string!

    When test() returns false, the calling regex’s lastIndex property will reset to 0.

    How?
    Use String search or match instead.

    1. "Hello world! 123".search(digits) > -1;
    2. // true
    3. "321".search(digits) > -1;
    4. // true
    5. "321".search(digits) > -1;
    6. // true