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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:36:20+00:00 2026-06-09T13:36:20+00:00

I am wondering if I can modify the parameter in the function?

  • 0

I am wondering if I can modify the parameter in the function?

  • 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-09T13:36:22+00:00Added an answer on June 9, 2026 at 1:36 pm

    Objects and arrays are passed by reference and changes to the argument you pass to a function will affect the original. All other types behave like they are passed by value and you cannot change the original.

    Javascript does this automatically – you cannot specify that something be passed by value or by reference like you can in some other languages. If you want something passed by reference, put it in an array or object and pass the array/object.

    Example 1 (passing an object):

    function myFunc(myObject) {
        // this changes the original object
        myObject.ready = true;
    }
    
    var obj = {ready: false;};
    myFunc(obj);
    // obj.ready == true - value is changed
    

    Example 2 (passing a string):

    function hello(str) {
        str = str + " and goodbye";
        alert(str);
    }
    
    var greeting = "Hello";
    hello(greeting);
    // greeting == "Hello" - value is unchanged
    

    Example 3 (passing a string in an object):

    function hello(obj) {
        obj.str = obj.str + " and goodbye";
        alert(obj.str);
    }
    
    var o = {greeting: "Hello"};
    hello(o);
    // o.greeting == "Hello and goodbye" - value is changed
    

    Example 4 (passing a number):

    function hello(num) {
        num++;
        alert(num);
    }
    
    var mynum = 5;
    hello(mynum);
    // mynum == 5 - value is unchanged
    

    Note: One thing that is sometimes confusing is that strings are actually passed by reference (without making a copy), but strings in javascript are immutable (you can’t change a string in place in javascript) so if you attempt to modify the string passed as an argument, the changed value ends up in a new string, thus the original string is not changed.

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

Sidebar

Related Questions

was wondering how can I create a sub drop down box upon selecting a
I was wondering how can I track the current logged in user in a
I was wondering how can I control the image on the connect dialog? I
i'm wondering how can I compare in C language, a number I put on
I was wondering how can I do something similar to Facebook when a link
I was wondering how can we can use the python module networkX to implement
I was wondering how can I generate the following array using ranges in ruby
I was wondering how can I list the user tables name with its primary
I am wondering how can I hide/remove a tag after a certain amount of
I'm wondering how can I put a header into my PDF file, cause I've

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.