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
Marcelo Petry -
Teri Eyenike -
Pramod Dutta -
Sachin Sharma -
Once suspended, akshaydatacode will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, akshaydatacode will be able to comment and publish posts again.
Once unpublished, all posts by akshaydatacode will become hidden and only accessible to themselves.
If akshaydatacode is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Akshay Mandliya.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag akshaydatacode:
Unflagging akshaydatacode will restore default visibility to their posts.
Latest comments (6)
As
c
is no primitive,d = c
sets the value ofd
to the same reference pointer that referencesc
.That means
c.greeting = ...
means "lookup the object referenced by c and mutate its value".As
c
andd
are 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 ;)
So this would be a example of "Pass by reference"?
A. Hello
correct answer
A: Hello
correct