Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ourouborean example is confusing #19

Open
raganwald opened this issue Oct 3, 2013 · 1 comment
Open

Ourouborean example is confusing #19

raganwald opened this issue Oct 3, 2013 · 1 comment

Comments

@raganwald
Copy link
Owner

At the end of 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?
reply


anonymoushn 1 day ago | link

It 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]
reply


ajanuary 1 day ago | link

Aah, rereading it, it looks like it is. The ouroboros section is an aside about how confusing combining arrays and references can be.
reply


toki5 1 day ago | link

Just 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.
reply


roryokane 1 day ago | link

Yes, I don’t understand what he means either.
    ouroboros[0] === ouroboros
evaluates to `true`.
reply
@fgshprd
Copy link

fgshprd commented Oct 4, 2013

I'm reading this in Chrome, and it seems that the 'aside' sections don't have any css associated with them that would distinguish them from the regular flow of text. This is why this example is confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants