Pass by reference means that when you pass an object to a function, any modifications made to the object inside the function will affect the original object outside the function.
For example, consider the following code:
In this code, we have an object
person with a
age property. We then define a
celebrateBirthday function that takes a
person parameter and increments their age by 1.
When we call
person object is passed to the function by reference. Any changes made to the
person object inside the function will affect the original
person object outside the function.
celebrateBirthday(person), we can see that the
age property of the
person object is incremented by 1, resulting in an output of
Declare a new variable called
updatedPerson and assign it the value of the
updatePerson function passing the
updatedPerson object as an argument.
updatedPerson object to the console.
Sign up to start coding
Already have an account?