JavaScript Object Hierarchy
Most JavaScript objects inherit properties and methods from Object.
The Object hierarchy shows how built-in JavaScript object types are related.
- What inherits from Object?
- Why is Array an object?
- Why is typeof Array "function"?
- Where does toString() come from?
- What is the relationship between Error and TypeError?
Object is the Root Object
Most built-in JavaScript objects inherit from Object.
All objects inherit common methods such as:
toString()valueOf()hasOwnProperty()isPrototypeOf()
Built-in Object Types
JavaScript has 10 Built-In object types
Object
├─ Function
├─ Array
├─ Date
├─ RegExp
├─ Error
├─ Promise
├─ Map
├─ Set
├─ WeakMap
└─ WeakSet
Function Objects
Functions are also objects.
All object constructors are Function objects.
Example
(typeof Object) // function
(typeof Array) // function
(typeof Date) // function
Try it Yourself »
Constructors and Objects
Constructors create objects.
| Constructor | Creates |
|---|---|
Object() |
Object |
Array() |
Array |
Date() |
Date |
RegExp() |
RegExp |
Error() |
Error |
Promise() |
Promise |
Map() |
Map |
Set() |
Set |
Learn More:
Array Objects
Array objects inherit from Object.
Example
const cars = ["Volvo", "Saab"];
(cars instanceof Object) // true
Date Objects
Date objects inherit from Object.
Example
const d = new Date();
(d instanceof Object) // true
Error Objects
Error objects inherit from Object.
JavaScript also provides specialized error types.
Object
└─ Error
├─ AggregateError
├─ EvalError
├─ RangeError
├─ ReferenceError
├─ SyntaxError
├─ TypeError
└─ URIError
Learn More:
Primitive Values Are Not Objects
Primitive values do not inherit from Object.
| Primitive Type | Object ? |
|---|---|
| string | No |
| number | No |
| boolean | No |
| bigint | No |
| symbol | No |
| undefined | No |
| null | No |
Learn More:
Hierarchy Overview
Primitive Types
string
number
boolean
bigint
symbol
undefined
null
Object Types
Object
├─ Function
├─ Array
├─ Date
├─ RegExp
├─ Error
├─ Promise
├─ Map
├─ Set
├─ WeakMap
└─ WeakSet