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?
The Root Object
Most built-in JavaScript object types inherit from Object.
Object
Objects inherit common methods such as:
toString()valueOf()hasOwnProperty()isPrototypeOf()
Built-in Object Types
Most built-in JavaScript objects inherit from Object.
Object
├─ Function
├─ Array
├─ Date
├─ RegExp
├─ Error
├─ Promise
├─ Map
├─ Set
├─ WeakMap
└─ WeakSet
Function Objects
Functions are objects.
All constructors are Function objects.
Example
document.getElementById("demo").innerHTML =
typeof Object + "<br>" +
typeof Array + "<br>" +
typeof Date;
The result is:
function
function
function
Constructors and Objects
Constructors create objects.
| Constructor | Creates |
|---|---|
Object() |
Object |
Array() |
Array |
Date() |
Date |
RegExp() |
RegExp |
Error() |
Error |
Promise() |
Promise |
Map() |
Map |
Set() |
Set |
Array Objects
Array objects inherit from Object.
Example
const cars = ["Volvo", "Saab"];
document.getElementById("demo").innerHTML =
cars instanceof Object;
The result is:
true
Date Objects
Date objects inherit from Object.
Example
const d = new Date();
document.getElementById("demo").innerHTML =
d instanceof Object;
Error Objects
Error objects inherit from Object.
JavaScript also provides specialized error types.
Object
└─ Error
├─ AggregateError
├─ EvalError
├─ RangeError
├─ ReferenceError
├─ SyntaxError
├─ TypeError
└─ URIError
See the Error Hierarchy reference page.
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 |
See Primitive vs Objects.
Hierarchy Overview
Primitive Types
string
number
boolean
bigint
symbol
undefined
null
Object Types
Object
├─ Function
├─ Array
├─ Date
├─ RegExp
├─ Error
├─ Promise
├─ Map
├─ Set
├─ WeakMap
└─ WeakSet