What will the console log when executing: function showContact(firstName, lastName, ...titles) { console.log(firstName + ' ' + lastName + ', ' + titles[0] + ' and ' + titles[1]); } showContact('Sue', 'Johnson', 'Developer', 'Architect');?

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!

The function showContact is designed to accept a variable number of arguments. The first two parameters, firstName and lastName, capture the first two arguments passed to the function, which in this case are 'Sue' and 'Johnson'. The rest of the arguments are collected into an array called titles using the rest parameter syntax (...titles).

When the showContact function is invoked with the arguments 'Sue', 'Johnson', 'Developer', and 'Architect', the variable titles will contain an array with the values ['Developer', 'Architect'].

In the console.log statement, the function constructs a string by concatenating firstName, lastName, and referring to specific elements of the titles array. The first element, titles[0], is 'Developer', and the second element, titles[1], is 'Architect'. Therefore, the final output of the console.log will be:

"Sue Johnson, Developer and Architect"

This construction shows how to effectively use both standard parameters and the rest parameter to handle variable argument counts in JavaScript functions, leading to the correct answer.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy