Mind Twisters- moved to github Flashcards

1
Q

What is the output ?

var dwayne = {};
var daniel = { firstName: 'Daniel'}
var jason = {key: 'jason'};

dwayne[daniel]=123;
dwayne[jason]=456;

console.log(dwayne[daniel]);

A

dwayne[daniel]) : output is 456

dwayne[daniel]=123; // is { ‘[object Object]’: 123 }

dwayne[jason]=456; //is { ‘[object Object]’: 456 }

daniel and jason are objects. So JS will call .toString function on the objects hence key is ‘[object Object]’

Note: JSON.stringify() and toString() might yield different results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly