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

1. JavaScript Objects > Primitive (a.k.a. Simple) Values

Primitive (a.k.a. Simple) Values

The JavaScript values 5, 'foo', true, and false, as well as null and undefined, are considered primitive because they are irreducible. That is, a number is a number, a string is a string, a boolean is either true or false, and null and undefined are just that, null and undefined. These values are inherently simple, and do not represent values that can be made up of other values.

Examine the code below and ask yourself if the string, number, boolean, null, and undefined values could be more complex. Contrast this to what you know of an Object() instance or Array() instance or really any complex object.

Live Code

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

var myString = 'string'
var myNumber = 10;
var myBoolean = false; // could be true or false, but that is it
var myNull = null;
var myUndefined = undefined;

console.log(myString, myNumber, myBoolean, myNull, myUndefined);

/* Consider that a complex object like array or object can be made up of multiple 
primitive values, and thus becomes a complex set of multiple values. */

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


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




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