Types of data
JavaScript has the following types of data that can store values. We will consider three in this module and the other two later.
Covered here | Covered later |
---|---|
numbers | objects |
strings | functions |
Booleans |
In addition, there are the following built-in values:
Value | Data type |
---|---|
null |
object |
undefined |
undefined |
To determine the type of a value, you can use the built-in function typeof
. Notice that whether or not they use decimal points, all numbers are of type number
. Notice also that the value undefined
is of type undefined
, and that (due to a quirk in JavaScript) the value of null
is of type object
.
You can tell by both the colour of the values in the console and the quotation marks that typeof
returns a string.
Note:
Hints:
- undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
console.log(typeof(5));
console.log(typeof(5.0));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX