There are two data types in JavaScript: primitives and objects.
Primitive values are atomic data that is passed by value and compared by value. The following are the primitive types:
boolean
string
number
undefined
null
symbol
Objects, on the other hand, are compound pieces of data that are passed by reference and compared by reference.
typeof
operatorYou can check the type of a value by using the typeof
operator
See typeof
on MDN web docs for more details.
The Boolean type is similar to most other programming languages with two options: true
or false
.
See Boolean
on MDN web docs for more details.
To be discussed shortly.
To be discussed shortly.
The three primitive types string
, number
and boolean
have corresponding types whose instances are objects: String
, Number
, Boolean
.
You can use the instanceof
operator to check the type of an object.
undefined
and null
JavaScript has two “bottom” values!
undefined
.null
value denotes an “intentionally” absent value.Although you can, don’t deliberately set a value to undefined
!
JavaScript has lots of quirks, and a bunch of them are around null
and undefined
(and how they behave, relate, and differ). We will see some of these in later sections. For now, enjoy this!
For more details, Brandon Morelli has a nice article: JavaScript — Null vs. Undefined. For a complete reference, visit null
and undefined
on MDN web docs.
The symbol is a new addition to the JavaScript language, which enables Metaprogramming. It is beyond the scope of this course. You can consult the following resources if you are interested to learn more.