This book is currently a work in progress. Content is being actively developed.
Chapter 3: Object Values
Now that we’re comfortable with the built-in primitive types, we turn our attention to theobject types in JS.
Rather than repeat that book’s content, here we’ll focus our attention on how the object value-type behaves and interacts with other values in JS.
Types of Objects
Theobject value-type comprises several sub-types, each with specialized behaviors:
Plain Objects
General-purpose key-value collections
Fundamental Objects
Boxed primitives (String, Number, Boolean)
Built-in Objects
Date, Error, Map, Set, etc.
Arrays
Numerically indexed collections
Regular Expressions
Pattern matching objects
Functions
Callable objects
Plain Objects
The general object value-type is sometimes referred to as plain ol’ javascript objects (POJOs). Plain objects have a literal form:{ .. } curly braces, is a collection of named properties. Properties can hold any values, primitives or other objects.
The same object could also be defined imperatively using the new Object() constructor:
Methods Available on Plain Objects
Plain objects have access to these methods viaObject.prototype:
toString() / toLocaleString()
toString() / toLocaleString()
Convert object to string representation
valueOf()
valueOf()
Returns the primitive value of the object
isPrototypeOf(object)
isPrototypeOf(object)
Check if this object is in another object’s prototype chain
hasOwnProperty(prop)
hasOwnProperty(prop)
Check if object has a property (deprecated - use
Object.hasOwn() instead)propertyIsEnumerable(prop)
propertyIsEnumerable(prop)
Check if a property will show up in
for...in loopsFundamental Objects
JS defines several fundamental object types, which are instances of various built-in constructors:new String()new Number()new Boolean()
Prototypes
Instances of the fundamental object constructors are[[Prototype]] linked to their constructors’ prototype objects:
String.prototype
Defines
length property and string-specific methods like toUpperCase(), slice(), etc.[[Prototype]] delegated access to its respective prototype properties/methods. Moreover, corresponding primitive values also have such delegated access, by way of auto-boxing.
Automatic Objects
I’ve mentioned auto-boxing several times (in Chapters 1 and 2, and a few times so far in this chapter). It’s finally time for us to explain that concept.Auto-boxing is the temporary conversion of a primitive to its object wrapper to enable property/method access.
How Auto-Boxing Works
How Auto-Boxing Works
- You access a property/method on a primitive value
- JS temporarily wraps the primitive in its corresponding fundamental object
- The property/method is accessed on that object
- The result is returned
- The temporary object is discarded
Which Primitives Auto-Box?
Which Primitives Auto-Box?
string→new String()number→new Number()boolean→new Boolean()symbol→ internal Symbol wrapperbigint→ internal BigInt wrapper
null and undefined do NOT auto-box — they have no corresponding fundamental objects.[[Prototype]] link to their respective fundamental object’s prototype.
Other Built-in Objects
In addition to fundamental object constructors, JS defines a number of other built-in constructors that create further specialized object sub-types:Date
new Date() - Date and time objectsError
new Error() - Error objectsCollections
Map, Set, WeakMap, WeakSet - Keyed collections
Typed Arrays
Int8Array, Uint32Array, etc. - Indexed collections
Buffers
ArrayBuffer, SharedArrayBuffer - Structured data
Arrays
Arrays are objects that are specialized to behave as numerically indexed collections of values, as opposed to holding values at named properties like plain objects do. Arrays have a literal form:new Array() constructor:
Array Methods
Mutating Methods
Mutating Methods
These methods modify the array in place:
push()/pop()- Add/remove from endunshift()/shift()- Add/remove from beginningsplice()- Add/remove at any positionsort()- Sort elementsreverse()- Reverse orderfill()- Fill with value
Non-Mutating Methods
Non-Mutating Methods
These methods create and return a new array:
concat()- Merge arraysslice()- Extract portionmap()- Transform elementsfilter()- Select elementsflat()- Flatten nested arrays
Query Methods
Query Methods
These methods compute and return a result:
indexOf()/lastIndexOf()- Find indexincludes()- Check if value existsfind()/findIndex()- Find elementsome()/every()- Test elementsreduce()- Reduce to single value
Regular Expressions
Regular expressions are covered in detail in other resources. This section is TODO for the book.
Functions
Functions are covered extensively in the “Scope & Closures” book of this series. This section is TODO.
Proposed: Records/Tuples
At the time of this writing, a (stage-2) proposal exists to add Records and Tuples to JS.
- Immutable - Cannot be modified after creation
- Treated as primitive values - For assignment and equality comparison
- Syntax - Use
#prefix before{ }or[ ]delimiters - Contents - Can only contain primitive values (including other records/tuples)
Summary
Objects in JavaScript come in many forms:- Plain Objects - General-purpose key-value collections
- Fundamental Objects - Wrappers for primitives (rarely used directly)
- Arrays - Numerically indexed collections
- Functions - Callable objects
- Built-in Objects - Date, Error, Map, Set, and more
Continue to Chapter 4
Learn about coercion - how JavaScript converts between value types

