Salesforce JavaScript Developer Practice Exam

Question: 1 / 400

What will the output of the following code be: let array1 = ['one', 'two']; let array2 = ['three', 'four']; array1.push(...array2); console.log(...array1);?

one two

one two three four

In the given code, the `array1` is initialized with the elements 'one' and 'two', while `array2` contains 'three' and 'four'. The key operation here is the `push` method, which is called with the spread operator (`...array2`). This operator expands the contents of `array2` and adds them as separate elements to `array1`.

After executing `array1.push(...array2)`, `array1` will then contain four elements: 'one', 'two', 'three', and 'four'. When logging `...array1` to the console, the spread operator is again used, which takes each element of `array1` and outputs them as individual arguments. Therefore, the console output will display each element in `array1` separated by a space.

Thus, the output of the code will be "one two three four", confirming that the selected answer is accurate.

Get further explanation with Examzify DeepDiveBeta

[one, two, three, four]

["one", "two", "three", "four"]

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy