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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:52:37+00:00 2026-06-01T04:52:37+00:00

I just can’t understand how variables are passed, why are some passed by reference

  • 0

I just can’t understand how variables are passed, why are some passed by reference while other by value?

Example:

var a=4;
var b=a;
b=b++;
alert(a);//unmodified 4

var c=["t","ttt"];
var d=c;
d=d.sort(function(x,y){return (y.length-x.length);});
alert(c);//modified ["ttt","t"]

Where can I find a list of what variables will work like the first example and which like the second? (booleans, strings, etc… there are too many to test them all by miself)

  • 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-01T04:52:38+00:00Added an answer on June 1, 2026 at 4:52 am

    JavaScript is always pass by value.

    It’s very common to say that objects in JavaScript are pass by reference, however that is not true. In a true pass by reference language, you could pass a reference to an object’s reference, and have it point to another object. This is not possible in JavaScript.

    Take, for example, C#. By default everything in C# is pass by value, just like JavaScript.

    void foo(string s) {
        s = "passbyvalue";
    }
    
    string a = "original value";
    foo(a);
    // a is still "original value"
    

    However, if you alter foo to use pass by reference, the behavior changes:

    void foo(ref string s) {
        s = "passbyreference";
    }
    string a = "original value";
    foo(ref a);
    // a is now "passbyreference"  
    

    In JavaScript, only the first example is possible.

    In JavaScript, everything is pass by value. This includes the object reference (yes, it is confusing). The reference itself is a value (it’s very much like a pointer). It merely contains an id that allows the runtime to look up the object that is most likely stored in its heap. When you pass an object to a function, you are actually copying its reference into the function

    It may be a seemingly small, and even anal, difference. But it’s a key difference. Languages that have true pass by reference such as C# and C++ allow you to do things that are simply not possible in languages like JavaScript. The above trite example is one.

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

Sidebar

Related Questions

I just can't remember the terminology used for this and other related properties. EDIT
I just can't figure out how do I make sure an argument passed to
I just can't understand why is my database (mysql) behaving like this! My console
I just can't find the option anywhere. Is there some way in eclipse to
I just can't figure this out, for some reason this: $string = #mainparent {
I am basically just wondering how can I make this while loop repeat continuously
I just can't get my variables to carry over to the next page. The
I Just can't seem to wrap my head around them. As I understand it's
I just can't insert a CData value into table row. my new table entity
This is a weird behavior that I just can't understand: I access my own

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.