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 will be logged when executing the function getPersonInfo with tagged template literals?

  1. "Lydia" 21 ["", " is ", " years old"]

  2. ["", " is ", " years old"] "Lydia" 21

  3. "Lydia" ["", " is ", " years old"] 21

The correct answer is: ["", " is ", " years old"] "Lydia" 21

When the function getPersonInfo is executed with tagged template literals, it processes the template string along with the provided values in a specific way. Tagged template literals allow a function to take a string template and the values that are interpolated within the template, and then manipulate or log those values in a customized manner. In this scenario, if the function is designed to log the passed values as well as the segments of the string, the expected output would involve both the string parts and the interpolated values. When using tagged template literals, the first argument received by the function is an array of the string literals, followed by the values as additional arguments. Given this understanding, the structure of the logged output aligns with the choice that specifies the sequence of the extracted string array followed by the values. The first part is indeed the array of string parts, and the subsequent parts will reflect the values passed into the template. Therefore, when invoking the function with those particular arguments, the resulting output would have the array of strings preceding the actual values. This matches perfectly with the selected choice, which presents the array of strings first, followed by the other values.