In JavaScript, the reference of an object is a pointer or reference to the memory location of an object. When you assign or pass an object what you are passed is not the actual object but a reference to the object.
Example:
let obj1 = { name: 'Alice' };
let obj2 = obj1; // obj2 holds the reference to the same object
obj2.name = 'Bob';
console.log(obj1.name); // Output: 'Bob'
Key Points:
All objects are passed by references and not by values.
Modifying the object via one reference causes changes for all other references of the same object.
Basic data types, numbers, or strings, are passed and stored in the way of value, not references.
This is why objects in JavaScript behave differently than primitives when assigned or passed in code. Explore more about
objects in javascript
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In JavaScript, the reference of an object is a pointer or reference to the memory location of an object. When you assign or pass an object what you are passed is not the actual object but a reference to the object.
Example:
Key Points:
This is why objects in JavaScript behave differently than primitives when assigned or passed in code.
Explore more about objects in javascript