|
This result may be related to test. Each time test and exec are executed, it moves the search in the string. There is a lastindex property, which is set to the character position of the matching substring. When test is called again, the matching will be performed from lastIndex. Therefore the first test it found has a '0', so it displays 'true'. When it is used the second time, it starts from the previous position, so if it is not found, it returns 'false'. So the return is 'true'.
Without [g], test and exec will always set lastIndex to 0. |
|