Mastering Primitive Data Types in JavaScript
Learn the essentials of JavaScript primitive data types: strings, numbers, and booleans. Master type checking and concatenation for your web projects.
Previously in this course, we covered Variables and Data Containers, where we learned how to allocate memory for our data using let and const. Now that we have the containers, we need to understand exactly what we are putting inside them.
In JavaScript, data is categorized into different types. Understanding these is the difference between writing code that works and code that crashes silently. We will focus on the three most common primitive data types: strings, numbers, and booleans.
What are Primitive Data Types?
A "primitive" is the simplest form of data in JavaScript. It is not an object and has no methods of its own. Think of them as the atoms of your application.
1. Strings
Strings are sequences of characters used for text. You define them by wrapping your text in single quotes ('), double quotes ("), or backticks (`).
JAVASCRIPTconst taskName = "Buy groceries"; // Double quotes const status = CE9178">'pending'; // Single quotes
2. Numbers
JavaScript does not distinguish between integers (whole numbers) and floating-point numbers (decimals). Both are simply number.
JAVASCRIPTconst todoCount = 5; const temperature = 72.5;
3. Booleans
Booleans represent logical entities and can only have two values: true or false. These are critical when we start writing logic for our to-do list (e.g., "Is this task complete?").
JAVASCRIPTconst isCompleted = false;
Working with Types: Concatenation and Checking
String Concatenation
Concatenation is the process of joining two strings together using the + operator. If you use + with a string and a number, JavaScript will "coerce" the number into a string and join them.
JAVASCRIPTconst task = "Finish lesson"; const id = 3; const label = "Task " + id + ": " + task; // Result: "Task 3: Finish lesson"
Checking Types with typeof
As you build more complex applications, you might lose track of what a variable contains. The typeof operator is your best friend for debugging.
JAVASCRIPTconsole.log(typeof "Hello"); // "string" console.log(typeof 42); // "number" console.log(typeof true); // "boolean"
Advancing the Project
In our running project—the interactive dashboard—we need to track task status and descriptions. Let's initialize our state variables:
JAVASCRIPT// dashboard.js const taskTitle = "Complete the project"; const taskPriority = 1; const isDone = false; console.log("Task:", taskTitle, "| Type:", typeof taskTitle); console.log("Priority:", taskPriority, "| Type:", typeof taskPriority); console.log("Status:", isDone, "| Type:", typeof isDone);
Hands-on Exercise
Open your browser console (as learned in our first lesson) and perform the following:
- Create a variable called
userNameand assign it your name. - Create a variable called
ageand assign it your age. - Create a variable called
isOnlineand assign ittrue. - Use
console.logto print the type of each variable usingtypeof. - Create a string that says "User [name] is [age] years old" using concatenation.
Common Pitfalls
- Strings vs. Variables: Beginners often write
console.log("taskTitle")instead ofconsole.log(taskTitle). The former prints the literal word "taskTitle"; the latter prints the value stored in the variable. - The "Number" String: If you wrap a number in quotes (e.g.,
"10"), it becomes astring, not anumber. You cannot perform mathematical operations on it without first converting it. - Case Sensitivity:
trueandfalsemust be lowercase.TrueorTRUEwill cause a ReferenceError.
FAQ
Q: Why does typeof return "number" for decimals?
A: JavaScript uses the IEEE 754 standard for all numbers, meaning there is no separate "integer" type.
Q: Can I use + to add two numbers?
A: Yes! When both operands are numbers, + performs addition. When at least one is a string, it performs concatenation.
Q: Are there other primitive types?
A: Yes, such as undefined, null, symbol, and bigint, but we will cover those as they become relevant to our project.
Recap
We've identified the three core primitives: strings (text), numbers (integers/decimals), and booleans (logical states). We learned that typeof is our primary tool for verifying data, and concatenation allows us to combine strings dynamically.
Up next: Basic Arithmetic and Operators, where we will learn how to perform math on our variables and handle more complex string formatting.
Work with me

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

AI Automation & Agentic Workflow Development
Automate the repetitive work eating your time — content pipelines, data workflows, and agentic AI tasks that run themselves.