Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. JavaScript Objects > Complex Objects Have Dynamic Properties

Complex Objects Have Dynamic Properties

A new variable that points to an existing complex object does not copy the object. This is why complex objects are sometimes called reference objects. A complex object can have as many references as you want, and they will always refer to the same object, even as that object changes.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var objA = {property: 'value'};
var pointer1 = objA;
var pointer2 = pointer1;

// update the objA.property, and all references (pointer1 and pointer2) are updated
objA.property = null;

/* logs 'null null null' because objA, pointer1, and pointer2 all reference 
the same object */
console.log(objA.property, pointer1.property, pointer2.property);

</script></body></html>

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint