4.8 The Big Picture¶
Data and Structure Types¶
JavaScript has 9 standard types categorized as follows:
- Data Types (primitives):
undefined
,Boolean
,Number
,String
,BigInt
, andSymbol
. - Structural Types (objects):
Object
,Array
,Map
,Set
,WeakMap
,WeakSet
,Date
, andFunction
. - Structure Root Primitive:
null
.
Function : a non-data structure
Note
Functions are considered a non-data structure in JavaScript. However, they are objects.
Note
Do not worry if you do not know every type listed above. We will explain it at the right time.
Primitive types¶
Primitive Types have no properties or methods. Their values are immutable; they can not be changed. You can check the type of primitive type using typeOf primitive
.
To access a property or apply a method on a primitive type, The JavaScript engine converts the primitive to its respective object. It accesses the property or applies the method, then it converts the primitive object to its original primitive value.
Primitive Type | Respective Object | Constructor |
---|---|---|
string | String | String() |
boolean | Boolean | Boolean() |
number | Number | Number() |
bigInt | BigInt | BigInt() |
You get primitive value of an object using object.valueOf()
.
Objects¶
An object is a collection of properties. You can create objects with the literal notation {}
. You can also construct an object using the Object
constructor and the keyword new
. For instance; new Object()
.
Built-in Objects¶
Date
, Array
, and Function
are examples of JavaScript built-in objects.
Every object is constructed using a constructor.
Here is a list of built-in objects and their respective constructors:
Built-in Object | Constructor | Object Instance |
---|---|---|
Object | Object() | new Object() |
Date | Date() | new Date() |
Array | Array() | new Array() |
Function | Function() | new Function() |
String | String() | new String() |
Number | Number() | new Number() |
Boolean | Boolean() | new Boolean() |
Structure Root Primitive¶
null
is a built-in JavaScript object. Its value is primitive because it has similar primitive behavior. However, null
is an object and every object is derived from it.
typeof null === "object" // true