Multiple choice general knowledge

Once agin, consider the same three variables: someText = 'JavaScript1.2'; pattern = /(\w+)(\d).(\d)/i; outCome = pattern.exec(someText); What does outCome[0] contain?

  1. true

  2. false

  3. null

  4. JavaScript1.2

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

When pattern.exec() matches, it returns an array where index [0] contains the complete matched string. The pattern /(\w+)(\d).(\d)/ matches 'JavaScript1.2' entirely, so outCome[0] is 'JavaScript1.2'. Subsequent indices contain captured groups: [1]='JavaScript', [2]='1', [3]='2'.