An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
July 15, 2021 04:44 am GMT
Original Link: https://dev.to/soorajs98/javascript-question-day-3g2h
JavaScript question Day 5
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
Answer: A
In JavaScript, all objects interact by reference when setting them equal to each other.
First, variable c
holds a value to an object. Later, we assign d
with the same reference that c
has to the object.
When you change one object, you change all of them.
Original Link: https://dev.to/soorajs98/javascript-question-day-3g2h
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To