Understanding data types
In JavaScript, there are several primitive types. We can group them into two groups: before ES6 (undefined
, object
, boolean
, number
, string
, and function
) and after ES6 (bigint
and symbol
). In order to check the type of a variable, we can use the typeof
operator.
undefined
Not all languages have an undefined
type, but JavaScript does. It is used to represent the absence of a value. It is also used as the default value for uninitialized variables.
object
The object
type is used to represent a collection of data. It is a very generic type, and it is used to represent many different things, such as arrays (lists), objects (dictionaries), class instances, and null
.
boolean
The boolean
type is used to represent a logical value. It can be either true
or false
. This type can be generated by using the Boolean
function too, as everything in JavaScript can be converted to a boolean
value.
number
The number
type is used to represent a numeric...