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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:58:37+00:00 2026-06-11T16:58:37+00:00

I was told on another thread that after the function exits, any modifications made

  • 0

I was told on another thread that after the function exits, any modifications made to its operands from within the function will persist. I always thought that it made a temporary copy of all the values passed into it, and then the only things that persisted were return values and implicitly more broadly scoped variables that were modified.

I suppose thinking back to all the jquery plugins whose source code I’ve peaked at, they all use the construct:

(function($){
  $.fn.foo = function(){ console.log('foo'); };
})(jQuery);

which imply that modifications to the jQuery object even by the internal-scope $ identifier persist after the function exits, or the jQuery plugins would not work. So, this works as the above snippet does:

var x = {n:0};

(function addOneTo(p) {
  p.n = p.n + 1;
})(x);

console.log(x);

But this:

var x = 0;

(function addOneTo(p) {
  p = p + 1;
})(x);

console.log(x);

doesn’t, leaving x unmodified with a value of 0.

Could someone just explain how argument passing works? I thought I knew how it did, but I guess I don’t. Thanks

  • 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-11T16:58:38+00:00Added an answer on June 11, 2026 at 4:58 pm

    Actually in your first example

    var x = {n:0};
    (function addOneTo(p) {
        p.n = p.n + 1;
    })(x);
    console.log(x);
    

    The x is an object and when you used p.n = p.n + 1; it modified the original object’s property because it passed as a reference (p is the same object as x) but in your second example

    var x = 0;
    (function addOneTo(p) {
        p = p + 1;
    })(x);
    console.log(x);
    

    x is passed by a value in to the function and p = p + 1; here p is a new private variable inside that function and it has only the function scope.

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

Sidebar

Related Questions

I was told in a comment in another thread that I should be using
I was told that a function defined as static in one .c file is
Someone told me that another person was hotlinking my CSS file. I was able
In another question I posted someone told me that there is a difference between:
My boss just told me that he learned about fast VB6 algorithms from a
In this answer to another question , I was told that in scripts you
Today i was asked this question about sharing data from a thread t1 that
Someone told me that openGL is for graphic only, and that it's very bad
I was told that using break and continue labels in an OOP language is
A consultant told me recently that he has clients using IIS. Those servers accept

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.