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 (a.k.a. Composite) Values

Complex (a.k.a. Composite) Values

The native object constructors Object(), Array(), Function(), Date(), Error(), and RegExp() are complex because they can contain one or or more primitive or complex values. Essentially, complex values can be made up of many different types of JavaScript objects. It could be said that complex objects have an unknown size in memory because complex objects can contain any value and not a specific known value. In the code below, we create an object and an array that houses all of the primitive objects.

Live Code

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

var object = {
   myString: 'string',
   myNumber: 10,
   myBoolean: false,
   myNull: null,
   myUndefined: undefined
};

var array = ['string', 10, false, null, undefined];

/* Contrast this to the simplicity of the primitive values below. In a primitive 
form, none of the values below can be more complex than what you see while 
complex values can encapsulate any of the JavaScript values (seen above). */

var myString = 'string';
var myNumber = 10;
var myBoolean = false;
var myNull = null;
var myUndefined = undefined;

</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 10-Day Trial


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