I didn't see any related messages that directly answer this question so I'll post below.
I noticed that the regex.test() function in JavaScript does not behave the same as "matches" in Java.
function doit(string)
{
    var finalString = "";  // our result at the end.
    var stringArray = string.split(/\s+/);
    var arrayIndex = 0;
    let regexp = /[A-Z]+/
    // use shortcut evaluation (&&)
    while (arrayIndex < stringArray.length && regexp.test(stringArray[arrayIndex]) )
    {
        finalString += stringArray[arrayIndex] + " ";
        arrayIndex++;
    } // end while
    return finalString
}
If I call "doit()" with "Hello World", the functions returns: "Hello World". Huh?
How is that possible with my [A-Z]+ regular expression?
The regular expression [A-Z]+ in Java means capital letters only and works as expected. In Java, nothing would be returned.
Java: 
stringArray[arrayIndex].matches("[A-Z]+")  // returns nothing as expected.
So, I'm a bit confused about how to match a regex in JavaScript.
Thanks in advance for helping clarify this for me. :)
 
     
    