Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Object equals other object Date: Mon, 16 Sep 2019 11:56:35 +0200 Lines: 49 Message-ID: References: <197fb351-f6f8-4f0c-9abf-6470d376edf9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net IIeqw150nWzJgnrSPuAVOwGM+FilNlsJLgaLBqUIgcsbQ6SnYA Cancel-Lock: sha1:eP7+3qiOyorWzzNkYAq3n6h1NYI= In-Reply-To: <197fb351-f6f8-4f0c-9abf-6470d376edf9@googlegroups.com> Content-Language: en-US Xref: csiph.com comp.lang.javascript:37268 On 16.09.19 11:54, Julio Di Egidio wrote: > On Monday, 16 September 2019 11:49:52 UTC+2, Arno Welzel wrote: >> On 16.09.19 10:30, Andrew Poulos wrote: >> >>> On 16/09/2019 5:00 pm, Evertjan. wrote: >>>> Andrew Poulos wrote on 16 Sep 2019 in >>>> comp.lang.javascript: >>>> >>>>> If I have >>>>> >>>>> let a = { "c": 1 }, >>>>> b = { "c": 1 }; >>>>> >>>>> then >>>>> >>>>> console.log(a === b); // false. >>>>> >>>>> My question is, why was it decided that JavaScript is to return false >>>>> even if the two objects have the same number of properties, all the >>>>> properties are named the same, and all the properties values are >>>>> identical? >>>> >>>> Two DIFFERENT objects can never "be" the same. >>> >>> Yes, but why can't two objects that have exactly the same properties and >>> corresponding property values be considered the same? If I JSON >>> stringify both of them then they magically become the same, so why not >>> before? >> >> Because "===" does not convert object properties to a value for comparison. >> >> "a === b" is only true if a and b are exactly same thing and not just >> the same value after some conversion. >> >> If you only want to compare values, use "==". > > Just try this: alert({}=={}) This is not what I talked about. > Ah, the fucking hubris... Not helpful as usual. -- Arno Welzel https://arnowelzel.de