The following types encompass every value in JavaScript:
boolean
number
undefined
(which includes the single valueundefined
)string
symbol
(abstract unique "things" that are compared by reference)object
Every object (i.e. everything) in JavaScript has a prototype, which is a kind of object.
The prototype contains functions, which are also a kind of object1.
Objects also have a constructor, which is a function, and therefore a kind of object.
It's all recursive, but the implementation is able to do it automagically because, unlike JavaScript code, it can create objects without having to call JavaScript functions (since objects are just memory that the implementation controls).
Most object systems in many dynamically typed languages are circular2 like this. For example, in Python, classes are objects, and the class of classes is type
, so type
is therefore an instance of itself.
The best idea is to just use the tools that the language provides, and not think too much about how they got there.
1 Functions are rather special because they are callable, and they are the only values that can contain opaque data (their body and possibly a closure).
2 It's actually more of a tortured, branching ribbon bent backwards over itself, but "circular" is close enough. [1]: https://i.sstatic.net/nZAKV.png