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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:25+00:00 2026-05-28T22:53:25+00:00

Even as a somewhat seasoned JS dev I find myself constantly suprised at shallow

  • 0

Even as a somewhat seasoned JS dev I find myself constantly suprised at shallow vs. deep copies of objects.

Are there any rules of thumb for when JavaScript values are copied by reference and not by value for the major object types? For example, I know string values are always copied by value not reference.

  • 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-28T22:53:26+00:00Added an answer on May 28, 2026 at 10:53 pm

    In JavaScript, all objects are stored and passed ‘by reference’.

    var a = { v: 'a' }, b = { v: 'b' };
    a=b;
    b.v='c';
    

    a and b will reference the same object; a.v == 'c' and b.v == 'c'.

    Primitive datatypes (string, number, boolean, null, and undefined) are immutable; they are passed by value.

    var a = 'a', b = 'b';
    a=b;
    b='c';
    

    Since we’re dealing with primitives, a == 'b' and b == 'c'.


    Pedants will tell you that JavaScript isn’t pass-by-reference in a classical sense, or that it’s a “pure pass-by-value” language, but I think that complicates things for practical purposes. No, you can’t directly modify an argument passed to a function as if it were a variable (which would be true if the language were true pass-by-reference), but you also don’t receive a copy of an object passed as an argument (as you would if it were true pass-by-value). For most purposes (from the standpoint of the language’s user, you), objects passed to a function are references, since you can modify that object and it affects the caller’s object. See also the fantastic answers to this question.

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

Sidebar

Related Questions

Is there a way to halt execution, somewhat like SIG_ABRT, but immediately , even
I'm somewhat new to C/C++, and I find myself spending exorbitant amounts of time
My question is somewhat similar to this one. We want to know if there's
I am somewhat desperate as i dont even know how its possible that i
This is a somewhat philosophical issue. I have a .net (but could be any
I am somewhat curious for iOS apps development with Xcode, even though we specifically
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even when BorderStyle is set to 0, it is possible to force a window
Even after all the hotfixes and updates that are supposed to fix this, my

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.