JavaScript Data Types
Not all information is the same! Discover how JavaScript works with text, numbers, true-or-false values, and more. Learn to recognize what kind of data you’re using and why it matters.
const value = "Hello!";
console.log(
typeof value
);
What Are Data Types?
Imagine filling out a registration form. Your name is text, your age is a number, and a checkbox might indicate whether you agree to the terms. These values represent different kinds of information.
JavaScript uses data types to describe what kind of value it’s working with. Understanding the difference helps you write code that behaves the way you expect.
const name = "Alex";
const age = 25;
const isStudent = true;
console.log(name);
console.log(age);
console.log(isStudent);
let can hold a string now and a number later. The value determines its type.Work With Text
A string is a sequence of characters. Names, messages, email addresses, and labels are all common examples.
Strings can use single quotes, double quotes, or backticks.
const firstName = "Alex";
const city = 'Los Angeles';
const greeting = `Hello, ${firstName}!`;
console.log(greeting);
Backticks create template literals. They let you insert values directly into text using ${...}.
"25". JavaScript treats it as text, not as a number.Count, Measure, and Calculate
JavaScript uses the number type for ordinary integers and decimal values. You can add, subtract, multiply, and divide them.
const price = 19.99;
const quantity = 3;
const total = price * quantity;
console.log(total);
Notice that the numbers don’t have quotation marks. Writing "19.99" creates a string instead.
JavaScript also has a bigint type for integers larger than the range that regular numbers can represent precisely.
Make True-or-False Decisions
A Boolean can have only two values: true or false. It’s useful for checking conditions, remembering whether something is enabled, or tracking whether a task is complete.
const isLoggedIn = true;
const hasFinishedLesson = false;
console.log(isLoggedIn);
console.log(hasFinishedLesson);
Don’t put quotation marks around Boolean values. true is a Boolean, while "true" is a string.
Understand null and undefined
Sometimes a value isn’t available yet. JavaScript has two common ways to represent this situation.
let favoriteColor;
const selectedCourse = null;
console.log(favoriteColor);
console.log(selectedCourse);
undefined often means a value hasn’t been assigned. null is usually used when you deliberately want to represent the absence of a value.
There’s one unusual JavaScript behavior worth remembering: typeof null returns "object". This is a long-standing quirk of the language, not evidence that null is an ordinary object.
Discover What Kind of Value You Have
JavaScript provides the typeof operator to identify a value’s type. It’s especially useful when you’re learning or debugging.
console.log(typeof "Hello");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof undefined);
The result of typeof is itself a string containing the type name.
typeof 100 and typeof "100". They look similar, but one is a number and the other is text.Meet Objects, Arrays, and Symbols
As your programs grow, you’ll want to organize more complex information. JavaScript provides several additional types and structures.
const student = { name: "Alex", age: 25 };
const scores = [80, 90, 100];
const uniqueId = Symbol("student");
console.log(typeof student);
console.log(typeof scores);
console.log(typeof uniqueId);
Objects organize information using named properties. Arrays hold ordered collections of values and are a special kind of object. Symbols are unique primitive values, often used as property keys.
You’ll explore arrays and objects in their own lessons. For now, focus on recognizing strings, numbers, Booleans, and missing values.
Build a Data Type Inspector
Create a small webpage that displays several values and identifies their JavaScript data types.
Your Mission
- Create a string containing your name.
- Create a number representing your age or favorite number.
- Create a Boolean showing whether you’re learning JavaScript.
- Use
typeofto identify each value’s type. - Display the values and their types on the webpage.
- Run your code and compare the results.
null. What does typeof report? Can you explain why the result is surprising?Explore JavaScript Data Types!
Edit the values, run your code, and watch the live result identify each data type. Try strings, numbers, Booleans, and missing values.
What You’ve Learned
You Know Your Data!
You’ve learned that JavaScript can work with many kinds of values, and that understanding those differences helps you write reliable programs.
- How strings represent text.
- How numbers support calculations.
- How Booleans represent true-or-false values.
- How
nullandundefineddiffer. - How
typeofidentifies a value’s type. - How objects and arrays organize more complex information.
Next up: Operators — learn how to calculate, compare, and combine values in JavaScript!
Your Learning Journey
0 / 17 CompletedKeep going! Every completed lesson brings you closer to mastering JavaScript.
Nice Work!
You've explored strings, numbers, Booleans, missing values, and more. You can now recognize different JavaScript data types and inspect them with typeof. You're building a strong foundation!


