Salesforce JavaScript Developer Practice Exam 2025 – 400 Free Practice Questions to Pass the Exam

Question: 1 / 400

What is the output of the following code when executed? const value = { number: 10 }; const multiply = (x = { ...value }) => { console.log((x.number *= 2)); }; multiply(); multiply(); multiply(value); multiply(value);

20, 40, 80, 160

20, 40, 20, 40

20, 20, 20, 40

To understand the output of the code, we need to examine how the function `multiply` and the spreading operator work in JavaScript, specifically how the default parameter and object mutability are interacting in this scenario.

Firstly, the `value` object is initialized with a property `number` set to `10`. When the `multiply` function is called without arguments, it uses the spread operator to create a shallow copy of `value`. This means that on the first call of `multiply()`, a new object is created with a `number` property initialized to `10`. Importantly, this new instance is not linked to the original `value` object, allowing it to be modified independently.

On the first call of `multiply()`, the new object's `number` property is multiplied by `2`, resulting in `20`. This value is then logged to the console. The second call of `multiply()` behaves the same way, again creating a new object with `number` set to `10`, and after multiplying it by `2`, it logs `20` again.

On the third call, `multiply(value)` is executed. Here, you are passing the original `value` object. In this instance, the `number` property of

Get further explanation with Examzify DeepDiveBeta

NaN, NaN, 20, 40

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy