3 ms·
At the end of https://leanpub.com/javascript-allonge/read#leanpub-auto-values-and-identity https://leanpub.com/javascript-allonge/read#leanpub-auto-val..., it s
by lxe 13y ago
At the end of https://leanpub.com/javascript-allonge/read#leanpub-auto-values-and-identity https://leanpub.com/javascript-allonge/read#leanpub-auto-val..., it states that when you do this:
var ouroboros = [];
ouroboros[0] = ouroboros;
//=> [ [Circular] ]
Examining ouroboros and ouroboros[0] with '===' will show that they are different.
But isn't that wrong? Comparing a reference of 'ouroboros' to whatever's in 'ouroboros[0]', which happens to be a reference of 'ouroboros' will return true.
Maybe I'm misinterpreting the statement?
- anonymoushn 13y agoIt looks like this text is about the section slightly above: [2-1, 2, 2+1] === [1,2,3] [1,2,3] === [1, 2, 3] [1, 2, 3] === [1, 2, 3]
- ajanuary 13y agoAah, rereading it, it looks like it is. The ouroboros section is an aside about how confusing combining arrays and references can be.
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- roryokane 13y agoYes, I don’t understand what he means either. ouroboros[0] === ouroboros evaluates to `true`.
- toki5 13y agoJust a guess -- perhaps ouroborous[0] = ouroboros; creates a new reference to ouroboros and stores that in ouroboros[0], so comparing ouroboros and ouroboros[0] with === would claim they're the same type but not the same value. Not an expert though, so I could be wrong, but that'd explain the behavior to me.
- raganwald 13y agoThanks https://github.com/raganwald/javascript-allonge/issues/19 https://github.com/raganwald/javascript-allonge/issues/19