The first time someone told me a value in my code “was a string” or “was a number,” I nodded like I understood. I didn’t. A data type is one of the simplest ideas in coding, and once it clicks, half of your error messages stop feeling random. By the end of this page, you’ll know exactly what type every value in your code is, why “25” behaves completely differently from 25, and how to avoid the type mistakes that trip up almost every beginner — in plain English, with code you can actually run.
Not all data is the same. A name is different from a number. A number is different from a yes or no answer.
Data types tell the computer exactly what kind of information it is working with — so it can handle it correctly.
Get this wrong and your program throws errors. Get it right and everything just works.

What Are Data Types in Programming?
A data type tells the computer what kind of value a variable is holding — text, number, true/false, or nothing at all. Every value in your code has a type, whether you think about it or not.
Why Data Types Matter — Real Life Analogy
Think of a form you fill out online. Each field expects a specific type of data. Put the wrong type in the wrong field — and something breaks. Computers work exactly the same way.
How Computer Uses Data Types
When your program runs, the computer checks what type each value is — then decides what operations make sense. You can multiply two numbers. You cannot multiply two names.
// 50 — numbers multiply
// NaN — can’t multiply names
The Main Data Types Every Beginner Must Know
Learn these five — and you can handle almost any real-world coding situation.
String — Storing Text
Any text wrapped in quotes. A name, a sentence, even a number in quotes. The moment you add quotes — it becomes a string.
let msg = “Hello, World!”; // string
let num = “42”; // also a string — has quotes!
Number — Storing Numbers
Whole numbers, decimals, negatives — all numbers. No quotes needed. The computer treats them as real math values.
let price = 9.99; // decimal
let temp = -5; // negative number
Boolean — True or False
Only two possible values — true or false. Perfect for yes/no situations — is the user logged in? Is the form valid?
let isValid = false; // no
Undefined — No Value Yet
When you declare a variable but forget to give it a value, JavaScript sets it to undefined automatically. The box exists — but nothing is inside yet.
console.log(score); // undefined
Null — Empty on Purpose
Null means you intentionally set the variable to empty. Unlike undefined, null is a deliberate decision — “I know this exists, and I am choosing to leave it empty.”
let data = null; // intentionally blank
Data Types in JavaScript vs Python
Same idea — slightly different syntax. Here’s how each language handles data types.
How JavaScript Handles Data Types
JavaScript figures out the type automatically based on the value. This makes it beginner-friendly — but can cause surprises if you are not careful.
let age = 25; // Number
let active = true; // Boolean
How Python Handles Data Types
Python works the same way — just assign a value and Python figures out the type. Python’s syntax is even cleaner and closer to plain English.
age = 25 # int
active = True # bool
Type Conversion — Changing One Type to Another
Sometimes you have the right data — just in the wrong type.
A user types their age in a form — it arrives as a string. But you need it as a number to do math. That’s where type conversion comes in.
String to Number
Convert text to a number when you need to do math with user input.
let num = Number(str); // 25 — now a real number
let parsed = parseInt(“25px”); // 25 — extracts the number
Number to String
Convert a number to text when you need to display it or combine it with other text.
let text = String(price); // “19.99”
let msg = “Price: $” + price; // “Price: $19.99”
Common Conversion Mistakes
The most common mistake — adding a string and a number without converting first.
How to Check Data Type — typeof
Not sure what type your variable is? Here’s how to find out.
Using typeof in JavaScript
Put typeof before any value — it returns the type as a string instantly.
typeof 25
typeof true
typeof undefined
Using type() in Python
Wrap your variable inside type() — Python tells you the type immediately.
type(25)
type(True)
type(3.14)
FAQs About Data Types
Quick answers to the questions beginners ask most
What are the 5 main data types?
What is the difference between null and undefined?
// forgot to assign
// → undefined
// intentionally empty
// → null
Can a variable change its data type?
data = “Hello”; // now String — valid!
data = true; // now Boolean — still valid
