Skip to the TL;DR
In recent weeks I've been reading through JavaScript Allongé by Reginald Braithwaite (an excellent look at the fundamentals of J...
For further actions, you may consider blocking this person and/or reporting abuse
Same box vs same stuff in the boxes. Great analogy.
Thank you Nick! 😁
Loving these graphics! Do you make them yourself for these articles?
Thank you very much, Joel! 😊 Yes, I do - any chance I get to draw nerdy pixel art, I jump on lol
Please never stop! 😊
Great post but two notes:
First => on my personal experience js checks if two objects are the same; I mean if they have the same reference. Like:
Const b = {
value:1
};
Const a = b;
a === b // true
I didn't test that for arrays. And you mentioned that js checks to see if the two thing are equal (in value ? ) sounds to me like js is checking their references. Am I right ?
Second => I think the place of TL;DR should be at the top of this post.
Happy coding.
Hi Ahmad - this is correct! For data structures, it does check to see if the two things being compared point to the same reference in memory - for primitives, it compares the items by value. I'd originally had a bit in the article about reference vs identity, but I chopped it out because it was getting convoluted 😳And I think you're right, the TL;DR would be better suited at the beginning. Thanks for your input 🙌
I guess isn't Javascript's == operator supposed to be an "is this the same stuff in the box" check? There's all this implicit typecasting going on, but at its heart, it's an equality check designed to determine if two variables contain the same value. So I'm not sure you can draw the conclusion of philosophical differences in language design when Javascript has an operator with the same intent as in Ruby.
Hi Tim, good point! However, if you try out
[1,2,3] == [1,2,3]
in your console, you'll see it returnsfalse
. JS's double-equals will coerce types, but it won't perform a recursive equality check the way it does in Ruby. 😵Thanks for the post, as a current Rubyist who is always curious about learning more JS this would have been a total head scratcher for me!
Thank you very much for writing this up, Anna. It was very succinct and I loved your illustrations. XD (And the Ditto class. Lol!)
Thank you Tammy! I'm glad you liked it 😁
You wrote the whole post just to show off your amazing pixel art skills right?!
Loved them.
😁😁😁 made my day! Thanks Nahuel!