1. What's the output?
let c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
- A:
Hello - B:
Hey! - C:
undefined - D:
ReferenceError - E:
TypeError
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (6)
As
cis no primitive,d = csets the value ofdto the same reference pointer that referencesc.That means
c.greeting = ...means "lookup the object referenced by c and mutate its value".As
canddare only references to the same object, the Output is, of course,'Hello'.Everyone confused by this behavior should start looking into the basics of a functional programming style ;)
A: Hello
correct
So this would be a example of "Pass by reference"?
A. Hello
correct answer