Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:45:28+00:00 2026-06-03T19:45:28+00:00

Let us guess two objects with same property: var x = {a : ‘some’},

  • 0

Let us guess two objects with same property:

var x = {a : 'some'},
      y = {a: 'some'};

output:

x == y; and x === y; both give false

Similarly for two array,

var p = [1, 2, 3],
      q = [1,2,3];

p == q and p === q both give false.

But for if I do following:

var x = y = {a: 'some'};
var p = q = [1, 2, 3];

All above comparison give true.

Why Javascript do such thing? Explain Please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:45:29+00:00Added an answer on June 3, 2026 at 7:45 pm

    All above comparison give true.

    Right. You’ve specifically set p and q so they refer to the same object.

    With object references, both == (if both sides are object references) and === will check to see if the references are pointing to the same object. If you have two identical, but separate, objects, both will always be false.

    So for example:

    var a = {}; // a points to an object
    var b = {}; // b points to a _different_ object
    console.log(a === b); // "false"
    console.log(a == b);  // "false"
    
    var c = {}; // c points to an object
    var d = c;  // d points to _the same_ object
    console.log(c === d); // "true"
    console.log(c == d);  // "true"
    

    The content of the objects is irrelevant, it’s the identity of them that’s being checked.

    Note that this is not true if you use == and only one side is an object reference (e.g., the other side is a number, a primitive string, undefined, etc.). In that case, the object reference will be asked to convert itself (to either a string or a number, depending on what the other thing is), and then the converted result will be used for the comparison. This can lead to surprising behavior (for instance, "2" == [[[[[2]]]]] is true because the array is asked to turn itself into a string, which it does via join [which will ask its element to convert itself to a string, and so on], and you end up with "2" on the right-hand side). So I typically prefer === (“strict equality” over == (“loose equality”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I have two threads which execute some database-oriented code in thread-specific TransactionScopes
Let's imagine, I have two English language texts written by the same person. Is
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let's say I have a structure named vertex with a method that adds two
Let's assume there's a class with a virtual property (let's call it 'P'). It's
I have two copies of the same directory structure (basically, trunk and a feature
I'm building an app where you can search for objects in a database (let's
Let's say I have some code that is ordered, but the ordering is not
Let's say I have the following two classes: package example.model; public class Model {
In short, I think boxing is an annoyance. Let's look at some alternatives... public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.