Javascript: Deep Comparison

I was checking this question Javascript Deep Comparison
The solution of the question asker did not convince me so I tried to analyze the problem and came up with that

var obj = {here: 2};
console.log(deepEqual(obj, obj));
// → true
console.log(deepEqual(obj, {here: 1}));
// → false
console.log(deepEqual(obj, {here: 2}));
// → true
function deepEqual(a,b)
  if( (typeof a == 'object' && a != null) &&
      (typeof b == 'object' && b != null) )
     var count = [0,0];
     for( var key in a) count[0]++;
     for( var key in b) count[1]++;
     if( count[0]-count[1] != 0) {console.log('1');return false;}
     for( var key in a)
       if(!(key in b) || !deepEqual(a[key],b[key])) {console.log('2');return false;}
     for( var key in b)
       if(!(key in a) || !deepEqual(b[key],a[key])) {console.log('3');return false;}
  console.log('a:'+a+' b:'+b);
  return a===b;
obj === { here:2 }

This code fails the last test ( console.log(deepEqual(obj, {here: 2})) ) but the logic of considering objects deeply equal if they have respectively equal keys and values despite being different instances in memory does not convince me. Is there’s a problem with my ‘solution’ or the mistake lies in the presumptions of the exercise? Is the code mentioned in the question I linked valid?

Resources that hikinthru forgot to mention ( )

90 thoughts on “Javascript: Deep Comparison”

  1. I’ve been browsing online more than three hours today,
    yet I never found anny intereating articloe like yours.
    It’s pretty worth enough for me. In mmy opinion,
    if all web owners and bloggeres made good content as you did, thee
    net will be a lot more useful than ever before.|
    I couldn’t refrain rom commenting. Well written!|
    I will right away sdize your rss as I can’t find your e-mail subscription hyperlink or newsletter service.
    Do you have any? Please allow me recognise in order that I could subscribe.
    It iss appropriate time to make some plans foor the
    future and it’s tiome to be happy. I’ve read thjis post and
    if I could I want to suggdst you few interesting things or advice.
    Maybe you can write next articles referring to thi article.
    I want too read more things about it!|
    It iis perfect time to make a few plans for the longer term and it’s time to be happy.
    I have learn this submit and iff I may I want to recommend you few fascinating
    things or suggestions. Maybe you could write next
    articles regarding this article. I want to learn even morre issues approximately it!|
    I’ve been browsing on-line greater than three hours these days,
    yet I by no means discovered aany interesting article likke yours.
    It iss beautiful value sufficient for me. In myy view, if all siye ownesrs and
    bloggers made just rioght content ass you probably did, the internet ill likely be a lot more helpful than ever before.|
    Ahaa, its nice dialogue concerning thi article here at this blog, I have read all
    that, so at this time me also commenting at this place.|
    I am sure this piece of writing has touched all the internet
    visitors, its really really good paragraph on building
    up new blog.|
    Wow, this post is nice, my younger sister iss analyzing these things, thus I am going too
    let know her.|
    bookmarked!!, I like your website!|
    Way cool! Somme very valid points! I appreciate
    you penning tuis write-up and also the restt of the website is
    also very good.|
    Hi, I do believe this is an exellent website. I stumbledupon it 😉 I wwill revisit once again since I book marked it.
    Money and freedom is the best way to change, may you be rich and continue to guide other people.|
    Woah! I’m really digging tthe template/theme of this
    blog. It’s simple, yet effective. A lot of times it’s difficult
    to gget that “perfect balance” between superb usability and visual
    appeal. I must say you’ve done a fantastic job with this.
    Also, the blog loas extremely fast for mme on Chrome. Excellent Blog!|
    Thrse are truly wonderful ideas in concerning blogging. You have touched some good factors here.

    Any way keep up wrinting.|
    I really like wht you guys are up too. This kind of clever
    work and exposure! Keep up the terrific works guys I’ve incorporated you
    guys to our blogroll.|
    Hey there! Someone in my Myspace group shared this site
    with us so I came to give it a look. I’m definitely enjoying the information. I’m bookmarking annd will be tweeting this
    to my followers! Superb blog and excellent style and
    I really like what you guys are usually up too.
    This kind of clever work and exposure! Keeep up the
    great works guys I’ve includsed you guys to my
    own blogroll.|
    Hello would you mind stating whic blog platform you’re using?
    I’m planning to start my own blog soon but I’m having
    a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I aask is because your design and sttyle seems different then most
    blogs and I’m looking for something completelyy unique.
    P.S Apologies for getting off-topic but I had too ask!|
    Helo would you mind letting me know which web host you’re using?
    I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most.
    Can you recommend a good web histing provider at a reasonable price?

    Thank you, I appreciate it!|
    I really like it when indiiduals get together and share ideas.
    Great blog, continue the good work!|
    Thank you for the auspicious writeup. It in fact was a amusement acdount it.
    Look advaanced to more added agreeable from you!
    By the way, hoow could we communicate?|
    Hi there just wanted to give you a quick heads up. The text in your
    content seem too be runmning off thhe screen in Ie.

    I’m not sire iff this is a format ssue oor something to do with web browser compatibility but I figured I’d post tto let you know.
    Thhe style andd design look great though! Hope yyou gett the
    problem resolved soon. Kudos|
    This iis a tkpic which is near to my heart… Many thanks!

    Where are your contact details though?|
    It’s very straightforward too find ouut any matter on web aas compared to textbooks,
    as I found this piece of writing at tthis website.|
    Does your site haave a contact page? I’m having problems
    locating itt but, I’d like too shoot you ann email.
    I’ve got some recommendations for your blog you might be
    interested in hearing. Either way, great websxite
    and I look forward to seeing it improve over time.|
    Greetings! I’ve been readinng your weeb site for some time now and finally got the bravery
    to go ahead and give you a shout out from Houston Texas! Just wanteed tto say keep upp the excellent work!|
    Greetings from Los angeles! I’m bored tto tears at work so I decided to check out your website on my iphone during lunch break.
    I enjoy the information you present here and can’t wait to take a look
    when I get home. I’m amazed at how fast your blog loaded on my mobile ..

    I’m not even using WIFI, just 3G .. Anyways, superb site!|
    Its such as you larn my thoughts! You seem to knmow a lot approximately this, such as you
    wrkte the e-book in itt or something. I think that you just ccan do with some p.c.
    to power the message home a litrtle bit, however other than that, this is excellent blog.

    A great read. I will definitely be back.|
    I visited various blogs but the audio qjality for audio songs current at this web
    site is truly fabulous.|
    Hello, i read your blog occasionally and i ownn
    a similar onne and i was just curious if you get a lot of spam comments?
    If so how do you stop it, any plugin or anything you caan suggest?
    I get so much lately it’s driving me mad so any help is very much appreciated.|
    Greetings! Very useful advice in this particukar article!
    It is the little changes that will mske the mot significant changes.

    Thanks a lot for sharing!|
    I seriously love your website.. Great colors & theme. Did you develop this website yourself?
    Please reply back as I’m attempting to create my very own website and would like to fiond out where
    you ggot this from or what the theme is named. Many thanks!|
    Howdy! This blog post could not bee written anny better!
    Looking throujgh this article reminds mee of my previous
    roommate! He constantly kept talkibg about this. I am going to send this information to him.

    Fairly certain he’ll have a good read. Thank you for sharing!|
    Amazing! Thiss blog looks just like my oldd one!
    It’s on a entirely different subject bbut it has pretty much the same page layout and design. Excellent choice of colors!|
    There is certainly a lot to find outt about this topic.
    I like all of the points you have made.|
    You havee made some decent points there. I looked on the
    web for additional information about the issue and found most individuals will go along with your views on this web site.|
    Hi there, I check your blogs on a regular basis.
    Your humoristic style is witty, keep up the good work!|
    I just ccould not depart your site prior to suggesting that I
    actually loved the usual information an individual supply
    in your guests? Is going to be again steadily in order to check up on new posts|
    I wanted to thank you for this great read!! I definitely loved every bit of it.
    I’ve got yyou book-marked to look at new stufff youu post…|
    What’s up, just wanted to trll you, I enjoyed this blog post.
    It was helpful. Keep on posting!|
    Hi there, I enjoy reading all of your post.
    I like to write a little comment to support you.|
    I always spentt my half an hour to read this website’s articles
    everyday apong with a mug off coffee.|
    I all the time emailed ths web site post page to all my associates, as if like to read it next my
    contacts will too.|
    My programmer is trying to convince me to move to .net frolm PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using Movable-type on a varietry of websites
    for about a year and am nervous about switching too another platform.

    I have heard great things about Is there a way I can import
    all my wordpress posts into it? Any kjnd oof help would be really appreciated!|
    Howdy! I could have sworn I’ve visited this blog before but aftesr browsing through manny of thhe articles I realized it’s new to me.
    Anyways, I’m definitely happy I came across it and I’ll be book-marking it and
    checking back regularly!|
    Wonderful work! This is the type of info that are
    meant to bee shared across the net. Shame on the seekk
    engines for nnot positioning this post higher!
    Comme on over and discuss with my site . Thanks =)|
    Heya i am for the first tjme here. I came across this board and I find
    It really useful & it helped me out a lot. I hope to give somethng back and help others like youu helped me.|
    Greetings, There’s no doubt that your web site could be having web brrowser compaztibility issues.
    Whenever I look att your website in Safari, itt looks fine
    but when opening in Internet Explorer, it’s got some overlapping issues.
    I simply wantted to give you a quik heads up! Apart from that,
    great site!|
    Someone necessarily lend a habd to make signmificantly artiicles I’d state.

    This is the very first time I frequented your web page and so far?
    I amazed with the analysis you made to create this particulaar
    put up incredible. Excellent task!|
    Heya i’m ffor the first time here. I found this board and I find
    It truly helpful & it helped me out a lot.
    I hope to offer one thing again and aid others like
    you aided me.|
    Hey there! I simply wish to offer you a big thumbs up forr your great info you’ve got here on this post.
    I will be coming back to your blog for more soon.|
    I always used to read piece of writing in news papers but now as I am a user of web therefore from now I am using net for posts, thanks to web.|
    Yourr method of describing alll in this post iss actually good,
    every one be ale to easily be aware of it, Thanks a lot.|
    Hi there, I dkscovered your site bby wway of Google whilst searching foor a similar topic, your web site got here
    up, it looks good. I have bookmarked it inn my google bookmarks.

    Hi there, just changed into alert to your blog via Google, and found that it’s really informative.
    I am gonna be careful for brussels. I’ll appreciate if you happen to continue this in future.
    A lot of people might bbe benefited from ypur writing. Cheers!|
    I’m curious to find out what blog system you’re working
    with? I’m having some small security problems with my
    latest blogg and I would like to finnd something more secure.
    Do you hav any solutions?|
    I am extremely impressed with yoour writing skills as well
    as with the layout on yyour weblog. Is this a paid theme or did you customize it yourself?
    Anyway keep uup the nice quality writing,
    it’s rare to see a nice blog like this one these
    I am really inspired along with your writing abilities as weol as with the layout for your blog.
    Is that this a paid theme or did you customize itt your self?

    Either way stay up the excellent quality writing, it is uncommon to seee a nice blog like this one nowadays..|
    Hi, Neat post. There’s an issue with your site in web
    explorer, could check this? IE nonetheless is the marketplace chief and
    a biig element of people will leave out your wonderful writing because of this problem.|
    I’m not sure where you’re getting your information,
    but great topic. I needs to speend some time learnibg more or
    understanding more. Thanks for fantastic information I wass looking for this info for my mission.|
    Hello, i think that i saw you visited myy weblog so i
    came to “return the favor”.I’m trying to find things to enhance
    my website!I suppose its ok to use some of your\

  2. I have observed that in digital cameras, unique sensors help to focus automatically. These sensors with some surveillance cameras change in contrast, while others use a beam involving infra-red (IR) light, especially in low lighting. Higher standards cameras from time to time use a mixture of both devices and will often have Face Priority AF where the digital camera can ‘See’ your face and focus only upon that. Many thanks for sharing your ideas on this site.

  3. i need an emergency loan bad credit, i need a loan now with bad credit. i need an emergency loan bad credit i need loan i need a loan today i need loan to start the business, cash advance loans near me, cash advance, cash advances, today advance loans near me. Investment lending to money, accepts deposits.