Nino
Nino

Reputation: 441

Is it possible to see if two Javascript objects that are printed on the console are the same instance (preferably in Chrome)

When I run the following code in Chrome I would like to see that a and b are referring to the same object but c is not. Is there a way?

let a = {x:1,y:2,z:3};
let b = a;
let c = {x:1,y:2,z:3};

console.log(a);
console.log(b);
console.log(c);

Upvotes: 1

Views: 49

Answers (1)

AGamePlayer
AGamePlayer

Reputation: 7736

Use "store as global variable" feature.

Right click on the {x: 1, y: 2, z: 3} text on each output, and click "Store as global variable". You will get 3 variables:

temp1, temp2, temp3.

And then, try these:

temp1 == temp2
// output true
temp2 == temp3
// output false

Tip: you can access any (even those in a very deep callback) variables in this way as long as you use the console to output them.

Upvotes: 3

Related Questions