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 6972247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:56:37+00:00 2026-05-27T16:56:37+00:00

Javascript copies objects by reference, rather than literally. For example: var myObject = {};

  • 0

Javascript copies objects by reference, rather than literally. For example:

var myObject = {};
var myCopy = myObject;

myObject.foo = "bar";

alert(myCopy.foo); //alerts "bar"

But I am really struggling to think of practical, real world reason for this other than giving developers a way to make code slightly more readable (as you can give different uses for the same object different names).

The most likely thing is I have missed the point, so can anyone tell me what that point is?

  • 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-05-27T16:56:37+00:00Added an answer on May 27, 2026 at 4:56 pm

    After writing:

    var myObject = {};
    

    There is an object out in memory somewhere that you can refer to by the name myObject. The following assignment:

    var myCopy = myObject;
    

    …says that myCopy now refers to that same object, wherever it may be. This is the same thing that happens when you give an argument to a function:

    function somefunc(localName) {
        // body
    }
    someFunc(myCopy);
    

    Now there is a variable called localName that is local to someFunc that also refers to that same object out in memory.

    This is the fundamental way in which we pass around references to an object, so that it can be referred to by different names, in different scopes.

    We could copy the entire structure into a new location in memory. There was nothing stopping the designers from creating a language that did that. But it’s less efficient — think of deeply nested objects — and generally not what you want to do. For example, if a function modified one property of an object, it would need to return the entire object for that change to persist outside of the function. And the caller would need to handle that return value, deciding whether the old object needs to be kept or if the newly created, slightly different copy can overwrite it.

    Again, there’s nothing wrong with this design direction in principle; it’s just not how JavaScript was designed.

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

Sidebar

Related Questions

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
I have JavaScript code which copies the value of input file and paste it
JavaScript allows functions to be treated as objects--if you first define a variable as
javascript with> var customer=document.getElementById('custList').value; and that works... Why does it work BUT... var customer=(form1.custList.value);
With the following JavaScript, why does the output contain multiple copies of the same
What happens if a user looks at my JavaScript file, copies the content of
In JavaScript, why would one want to attach properties directly to the constructor? var
I have a question on 'call' in javascript. var humanWithHand = function(){ this.raiseHand =
I know that the prototype property of JavaScript function objects is copied to the
These are the ways of creating javascript objects: function apple(optional_params) { this.type = macintosh;

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.