Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
Essential JavaScript
Introduction
JavaScript Basics
Numbers
Strings
Logic
Variables
Loops
Objects
Arrays
Going Further
Objects vs Primitives
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"
.
Learning Goals
I know which data types are primitives
I can check the type of a value with the
typeof
operatorI know what the
typeof
operator returns for objects
Code Editor
Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.
Console Output
0 output lines