I'm new to JavaScript and I thought objects are passed by reference.
The output I expected was:
{ one: 1 } { one: 1 }
{ two: 2 } { two: 2 }
Output obtained:
{ one: 1 } { one: 1 }
{ two: 2 } { one: 1 }
When b
is referencing address of a
, why is b
still { one: 1 }
var a = {one:1}
var b = a
console.log(a,b)
a = {two:2}
console.log(a,b)