This is one of the most important things if you arrive at JS world: there are only two (2) main types of values:
For both primitives and objects there are sub-types, let's expand our vision a little more:
There is no specific reason in the order for JS, I just order it that way because is the way I use to remember all of them: BUSN (boolean, bigint, undefined, string, symbol, null, number)
What about objects?
Well, we can say that everything else is an object or derive from an object.
Functions like arrays are a special kind of object (sub-types).
Datatypes
You can check the type of a value using the typeof
operator.
There are two "wild" data types that can be confused:
functions and null
As I mention before functions are special kind of object. In this particular case function is a shorthand response; at the end of the day, the Function constructor is derived from Object constructor.
The case of the null, well this is a little tricky one... I'm going to let that homework for you.
Conclusion
- There are 2 main value types in JS: primitives and objects.
- There are 9 sub-types: (BUSN) boolean, bigint, undefined, string, symbols, numbers, null, objects and functions.
The latest ECMAScript standard defines nine types.
That's All Folks, hope you learn and enjoy it.
Top comments (0)