12 min +45 XP
Lesson 17Step 1 of 5

Type Checking

Check data types with typeof

What is typeof?

The typeof operator tells you what type of data you're working with. This is super useful for debugging and making sure your code works correctly!

Basic Syntax

javascript
1
2
3
4
5
6
7
8
const age = 12
console.log(typeof age)  // 'number'
 const name = 'Alex'
console.log(typeof name)  // 'string'
 const isStudent = true
console.log(typeof isStudent)  // 'boolean'

Why use typeof?

  • Check if a variable is the type you expect
  • Prevent errors before they happen
  • Debug your code more easily
  • Write safer, more reliable programs