The current edition of the ECMAScript spec defines 8 value types:
- Undefined
- Null
- Boolean
- String
- Symbol
- Number
- BigInt
- Object
https://262.ecma-international.org/11.0/#sec-ecmascript-language-types
The typeof operator is a big source of confusion in JavaScript, because what it returns is not always the actual type of the value. The conversion table for typeof (https://262.ecma-international.org/11.0/#sec-typeof-operator) is like this
| Type of val | Result |
|---|---|
| Undefined | undefined |
| Null | object !!! |
| Boolean | boolean |
| Number | number |
| String | string |
| Symbol | symbol |
| BigInt | bigint |
| Object (does not implement [[Call]]) | object |
| Object (implements [[Call]]) | function !!! |
Note the two exceptions marked with !!!
To confuse us further, the language also provides wrapper functions for these 4 primitive types
- Boolean
- Number
- String
- BigInt
These functions
when called with
new, return their argument converted to a corresponding wrapper object (Boolean,Numberetc)when called without
new, return their argument converted to a corresponding primitive value (Boolean, Number etc)
These functions are also called implicitly (in the new or "constructor" mode) when a primitive is used in the "object" context (e.g. "foo".length)