Skip to main content
D
JavaScript
JavaScript typeof

JavaScript typeof

JavaScript typeof identifies the data type of a variable.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript uses the `typeof` operator to figure out what kind of data a variable holds. Because JavaScript variables can hold anything, developers use this tool to check the data type before running specific functions.

Example

Example
1/* this checks data types */
2typeof "John"; // Returns "string"
3typeof 3.14; // Returns "number"
4typeof true; // Returns "boolean"

Key Points

  • `typeof` returns the data type as a lowercase string.
  • It identifies strings, numbers, booleans, and objects.
  • Arrays return as "object" because they are a special object type.
  • Undefined variables return as "undefined".

Up Next

Continue your journey with the next topic.

Go to JS Scope