Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


What is the result of using regex /[A-Z]/ with the g flag on the phrase 'The quick brown fox jumps over the lazy dog. It barked.'?

  1. ["T"]

  2. ["T", "I"]

  3. Error

  4. undefined

The correct answer is: ["T", "I"]

The result of using the regex /[A-Z]/ with the g flag on the phrase 'The quick brown fox jumps over the lazy dog. It barked.' accurately returns an array consisting of all uppercase letters found in the string. The regular expression is designed to find any single uppercase letter from A to Z. In the provided phrase, the letter 'T' from "The" and 'I' from "It" are the only uppercase letters present. The g flag signifies that the search should be global, meaning it will continue to search through the entire string for all matches, not stopping at the first match. Therefore, the regex finds both 'T' and 'I' and collects them into an array. The result is hence an array containing these two characters: ["T", "I"]. This captures all instances of uppercase letters throughout the entire string, which confirms that choice B is the correct answer.