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

  • Home
  • SEARCH
  • 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 8305233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:03:23+00:00 2026-06-08T18:03:23+00:00

Lets say you have this object: mainObj = { foo1: ‘bar1’, foo2: ‘bar2’, foo3:

  • 0

Lets say you have this object:

mainObj = {
   foo1: 'bar1',
   foo2: 'bar2',
   foo3: 'bar3'
}

Now I want to make a close of this object by doing cloneObj = mainOb. Now we have two identical objects.

When I change the value of mainObj.foo1 = 'lolcats' after I made the clone then for some reason cloneObj.foo1 = 'lolcats'

I tested this in Chrome’s console on a much more complex object. I know for certain that there’s nothing in my script that would keep making the two objects sync up. I even made sure of this by creating random names for the cloneObj.

Is this behavior done on purpose or am I experiencing some sort of bug? Or am I just missing something very fundamental here?

  • 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-08T18:03:26+00:00Added an answer on June 8, 2026 at 6:03 pm

    You didn’t clone the initial object when you just did cloneObj = mainOb, you are actually passing a reference to mainOb that can be accessed via the cloneObj variable name. You therefore have two variable names referencing the SAME object.

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

Sidebar

Related Questions

Lets say I have this: <object class=MyClass type=text/html data=/Whatever/1?renderpartial=1></object> <object class=MyClass type=text/html data=/Whatever/2?renderpartial=1></object> And,
How use this functionality that org.eclipse.ui.decorators provides? Lets say I have some object in
Lets say i have this code : Integer[] a= new Integer[5]; System.Out.println(((Object)a).toString()); the output
Lets say I have a structure like this: Object A contains an instance of
Lets say I have an object foo =[ob1, obj2, obj3 ... obj100 ...] Now
Lets say i have this member: @property (retain, nonatomic) Student *student; @synthesize student; Now
Lets say I have this assignment : $(myObj).val('1') now lets say I want to
Let's say I have an object - a User object in this case -
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have this code: <?php class hello { var $greeting = hello;

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.