Everything that isn't a primitive type is an object type.
Object types are mutable and passed to functions by reference (i.e. modifying the value within a function modifies the original).
There are 3 extremely common built-in object types:
Object is the base class of all object types. Objects are associative arrays (a.k.a maps or dictionaries).
Keys can only be strings (or symbols) — non-string keys will be coerced to strings at runtime.
Array class is a subclass of
Object that handles integer keys specially.
We use array literal syntax to declare arrays:
Functions are objects that can be called. They can assigned to variables and passed as arguments to other functions, just like any other value.
There are two ways to declare functions:
- Arrow (
=>) function expressions
Since all object types are subclasses of
Function values are associative arrays. This means we can assign arbitrary keys and values.
However, we generally shouldn't use them like this it's not their intended purpose.
There are some standard library methods and 3rd party frameworks that do this, so it's more a suggestion than a rule.