Q: 6
Refer to the code below:
Function changeValue(obj) {
Obj.value = obj.value/2;
}
Const objA = (value: 10);
Const objB = objA;
changeValue(objB);
Const result = objA.value;
What is the value of result after the code executes?
Options
Discussion
C result ends up 5. Trick answers get tossed if exam follows JS object reference logic.
Probably C. Both objA and objB point to the same object, so changing objB affects objA.value too. Pretty sure unless we're supposed to read into capitalization typos in the function name. Anyone disagree?
B, had something like this in a mock and the capitalization made it return NaN.
A is wrong, B. Similar code sometimes shows up on practice tests and the inconsistency in capitalization could trip things up.
C is correct for this, since objA and objB reference the same object. But if the question had asked for what would happen if objB = {...objA} was used instead, then result would stay 10. Are we supposed to assume no shallow copy here?
B tbh, because the typo with 'Obj' looks like a trap. Seen similar questions where that's enough for NaN.
C , unless they're trying to trick with the 'Obj' typo. In exam reports, when both variables reference the same object, changing one affects both. But if strict about case-sensitivity, maybe NaN? Still, in most exams, C is selected.
B , saw a question kinda like this pop up in a sample exam and the typo in capitalization made it throw NaN. Official guide practice tests are good for catching stuff like that, so I'd check there if unsure.
I remember a similar scenario from labs, in exam reports, C is usually picked for this kind of object reference setup.
C , since both objA and objB point to the same object in memory. So changing objB will also change objA. Saw a similar question in some practice sets, always came out as 5 unless a copy is made.
Be respectful. No spam.