Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce JS-Dev-101 Exam - Topic 5 Question 14 Discussion

01 function changeValue(obj) {02 obj.value = obj.value / 2;03 }04 const objA = {value: 10};05 const objB = objA;0607 changeValue(objB);08 const result = objA.value;What is the value of result after the code executes?
C) 5
A) low
B) 10
D) undefined

Salesforce JS-Dev-101 Exam - Topic 5 Question 14 Discussion

Actual exam question for Salesforce's JS-Dev-101 exam
Question #: 14
Topic #: 5
[All JS-Dev-101 Questions]

01 function changeValue(obj) {

02 obj.value = obj.value / 2;

03 }

04 const objA = {value: 10};

05 const objB = objA;

06

07 changeValue(objB);

08 const result = objA.value;

What is the value of result after the code executes?

Show Suggested Answer Hide Answer
Suggested Answer: C

objA is { value: 10 }.

objB = objA; both variables reference the same object.

changeValue(objB);:

obj.value = obj.value / 2; // modifies the shared object

So:

objA.value becomes 10 / 2 = 5.

Thus result is 5.


Contribute your Thoughts:

0/2000 characters
Genevive
1 day ago
I'm not entirely sure, but since objB is a reference to objA, I guess the value would be 5 after the function runs.
upvoted 0 times
...
Bobbie
7 days ago
I think the function changes the value of the object directly, so objA should also be affected.
upvoted 0 times
...

Save Cancel