What will the output be for console.log(paragraph.match(/[A-Z]/)) where paragraph is 'The quick brown fox jumps over the lazy dog. It barked.'?

Prepare for the Salesforce JavaScript Developer I Certification Exam. Utilize interactive quizzes, flashcards, and detailed explanations for each question. Boost your confidence and ace your exam effortlessly!

In the given question, the expression paragraph.match(/[A-Z]/) is used to search the string contained within the variable paragraph for any uppercase letters (indicated by the regular expression pattern [A-Z]). This pattern effectively tells the JavaScript engine to look for any single character that falls within the range of uppercase letters from A to Z.

The match method returns an array of matches found in the string. If the pattern matches multiple characters, the method will return an array with all those matches. However, if the regular expression is set to find only the first occurrence (which is the default behavior when no global flag g is specified), it will return only the first match it encounters.

In the provided string "The quick brown fox jumps over the lazy dog. It barked.", the first uppercase letter is 'T', appearing at the beginning of the string with the word "The." The match method stops searching after it finds this first match when not using the global flag. As a result, the output of console.log(paragraph.match(/[A-Z]/)) will be an array containing just this first matching uppercase letter.

Thus, the correct output is an array containing "T". This is

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy