var pattern = /java/i;
pattern.test("JavaScript"); // Returns true
Calling test( ) is equivalent to calling
exec( ) and returning true if
the return value of exec( ) is not
null. Because of this equivalence, the
test( ) method behaves the same way as the
exec( ) method when invoked for a global regular
expression: it begins searching the specified string at the position
specified by lastIndex, and if it finds a match,
it sets lastIndex to the position of the character
immediately following the match. Thus, we can loop through a string
using the test( ) method just as we can with the
exec( ) method.