Pass by Reference Concept
Question
When you pass an object to a function and modify its property, what happens?
Hint
Objects are reference types.
Explanation
Objects (and arrays) are reference types — when passed to a function, the function receives a reference to the same object, not a copy. Modifying a property inside the function affects the original object. However, reassigning the parameter to a new object does not affect the original. To avoid mutation, pass a copy: { ...obj } or structuredClone(obj).
Related Resources
Related Lessons
- JavaScript Objects
Learn about reference vs value.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.