Usually a test is chosen to check if some pattern matches at all, but the global flag lets you loop through a string to either count the matches or,like exec, do something with each lastIndex. Another use is to set the lastIndex of the rx yourself before the test is peformed, to ignore matches before some character index.
var count=0, rx=/\s+/g, rx.lastIndex=100;
while(rx.test(string))count++;