0

I was working on a project while I came across a strange problem. here is my code

let newEvent = event;
console.log(changes, event, newEvent);
newEvent.title = changes.title;
newEvent.description = changes.description;
console.log(changes, event, newEvent);

The first console.log outputted:

{title: 'Event 2', description: 'blaat'}

{title: 'Event 1', description: ''}

{title: 'Event 1', description: ''}

and this is what I expected, but what is didn't expect was the next console.log which outputted:

{title: 'Event 2', description: 'blaat'}

{title: 'Event 2', description: 'blaat'}

{title: 'Event 2', description: 'blaat'}

I expected the following output:

{title: 'Event 2', description: 'blaat'}

{title: 'Event 1', description: ''}

{title: 'Event 2', description: 'blaat'}

Is there anybody that can help me whit this problem, thanks id advance

Community
  • 1
  • 1
nusje2000
  • 493
  • 9
  • 25
  • 3
    `newEvent` is just a reference to `event` Read [Is JavaScript a pass-by-reference or pass-by-value language?](http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language) – Satpal Apr 12 '17 at 14:00
  • 1
    `let newEvent = new Event()` would do the trick. You are using `newEvent` as a reference to `event`. – Oen44 Apr 12 '17 at 14:03

0 Answers0