Objects are different from values we have worked with so far.
Numbers, strings, Boolean values, and undefined
are all primitives. These are the most basic data types available to us, and they are the building blocks for any more complex data structure we want to work with.
The typeof
Operator
We can check the data type of any value with the typeof
operator. Using typeof
will give us a string:
console.log(typeof 42); // "number"
console.log(typeof '42'); // "string"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
We can also use the typeof
operator to check the type of an object:
const person = {
firstName: 'John',
lastName: 'Doe',
};
console.log(typeof person); // "object"
No matter what properties an object has, typeof
will tell us it is an "object"
.