mc0de
JavaScript · Lesson 03 of 17

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.

JavaScript Strings & Numbers Booleans typeof
● ● ●   data-types.js
const value = "Hello!";

console.log(
  typeof value
);
CONSOLE OUTPUT
> Ready to inspect…
01 / Getting Started

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.

Different kinds of values
const name = "Alex";
const age = 25;
const isStudent = true;

console.log(name);
console.log(age);
console.log(isStudent);
Console output
Alex 25 true
Remember: JavaScript variables don’t have fixed types. A variable declared with let can hold a string now and a number later. The value determines its type.
02 / Strings

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.

Creating strings
const firstName = "Alex";
const city = 'Los Angeles';
const greeting = `Hello, ${firstName}!`;

console.log(greeting);
Console output
Hello, Alex!

Backticks create template literals. They let you insert values directly into text using ${...}.

Try this: Put a number inside quotation marks, like "25". JavaScript treats it as text, not as a number.
03 / Numbers

Count, Measure, and Calculate

JavaScript uses the number type for ordinary integers and decimal values. You can add, subtract, multiply, and divide them.

Working with numbers
const price = 19.99;
const quantity = 3;
const total = price * quantity;

console.log(total);
Console output
59.97

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.

Good to know: Some decimal calculations produce tiny rounding differences because JavaScript stores most numbers in binary floating-point format. We’ll explore calculations further in the Operators lesson.
04 / Booleans

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.

Boolean values
const isLoggedIn = true;
const hasFinishedLesson = false;

console.log(isLoggedIn);
console.log(hasFinishedLesson);
Console output
true false

Don’t put quotation marks around Boolean values. true is a Boolean, while "true" is a string.

05 / Missing Values

Understand null and undefined

Sometimes a value isn’t available yet. JavaScript has two common ways to represent this situation.

Missing and empty values
let favoriteColor;
const selectedCourse = null;

console.log(favoriteColor);
console.log(selectedCourse);
Console output
undefined null

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.

06 / Checking Types

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.

Using typeof
console.log(typeof "Hello");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof undefined);
Console output
string number boolean undefined

The result of typeof is itself a string containing the type name.

Try it: Compare typeof 100 and typeof "100". They look similar, but one is a number and the other is text.
07 / Beyond the Basics

Meet Objects, Arrays, and Symbols

As your programs grow, you’ll want to organize more complex information. JavaScript provides several additional types and structures.

More JavaScript values
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);
Console output
object object symbol

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.

🚀 mC0de Challenge

Build a Data Type Inspector

Create a small webpage that displays several values and identifies their JavaScript data types.

Your Mission

  1. Create a string containing your name.
  2. Create a number representing your age or favorite number.
  3. Create a Boolean showing whether you’re learning JavaScript.
  4. Use typeof to identify each value’s type.
  5. Display the values and their types on the webpage.
  6. Run your code and compare the results.
Extra challenge: Add a variable containing null. What does typeof report? Can you explain why the result is surprising?
💻 Interactive JavaScript Sandbox

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.

Live Result
Lesson 03 Recap

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 null and undefined differ.
  • How typeof identifies 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 Completed

Keep 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!