What is a data type — and why JavaScript thinks null is an object

Open your browser console and type typeof null. The answer: "object". Even though null means "nothing" and isn't an object at all.
That's not your mistake, and it's not the console's. It's a bug in the language itself, living in JavaScript since 1995. Nobody dared to fix it: millions of sites would break. Funny? Sure. But this joke shows exactly why types exist.
What a data type is
A data type is a label on a value. It tells the program what the thing is and what you're allowed to do with it.
Here's the tricky part. In a computer's memory everything is stored the same way — as zeros and ones. The same sequence of bits can mean the number 65. Or the letter "A". The bits don't know what they are. Only the type knows.
Hence a simple rule: the type decides how a value is read and which actions are allowed. Numbers can be divided. Text can be glued together. Lists can be looped over. Try dividing text by three and you get nonsense.
Which types exist
Every language has a slightly different set, but the core is the same. Here are the main ones you'll meet in any AI-written code:
- Number (
number) —42,3.14,-7. You do math with it. - String (
string) — text in quotes:"Hello". More in the article on strings. - Boolean (
boolean) — onlytrueorfalse. Every check rests on it, see booleans. - Emptiness —
nullandundefined. "There's no value." The difference is in the article on null. - Array — an ordered list:
[1, 2, 3]. - Object — a set of labeled fields:
{ name: "Anya", age: 12 }.
The first four are called primitive: they hold one value. Arrays and objects are composite: they hold other values inside, each with its own type.
How to find out the type
JavaScript has the typeof operator for that. It returns the type's name as a string:
typeof 42 // "number"
typeof "42" // "string"
typeof true // "boolean"
typeof undefined // "undefined"
typeof [1, 2] // "object" ← surprise
typeof null // "object" ← that famous bug
See the two traps? To typeof, an array is also an "object". So arrays get checked separately: Array.isArray(list). And null is caught with a direct comparison: value === null.
Python is more honest. It has type(), and it doesn't lie: type(None) returns NoneType, and type([1, 2]) returns list.
Why types break code
Most weird beginner bugs are an argument about types. The program thinks it has one thing, but something else arrived.
Three typical scenarios:
- Everything from a form is a string. The user typed age
12, but the code got"12". Add one and you get"121". The fix is turning it into a number, see how to convert a string to a number. - The API returned something else. You expected an array, but got an object with an array inside. The code calls
.map()and crashes. - Emptiness on input. A field was left blank,
nullarrived. Then the code tries to read a property from it and gets an error.
In all three cases the code is written correctly. It's just written for a different type.
Strict and loose languages
JavaScript is a loose language. It quietly tries to fit types together on its own. Write "5" * 2 and you get 10 — it turned the string into a number itself. But "5" + 2 gives "52": here it glued them. Handy, until it breaks.
Python is stricter. "5" + 2 simply crashes there with an error: "can't add a string and a number". Annoying, but honest — the bug is visible right away.
And then there's TypeScript: the same JavaScript, but with types checked before the code runs. Your editor underlines the mistake while you're still typing. The difference is in TypeScript vs JavaScript.
How this helps you
When AI-written code behaves strangely, ask one question: "what type is this actually?" Not "what should be here", but what arrived.
You can check in a second — add a line before the suspicious spot:
console.log(typeof data, data)
And you'll see immediately: expected a number, got a string. Expected an array, got an object. Half of the mysteries get solved at this step.
How many types does JavaScript have?
Eight: number, bigint, string, boolean, undefined, null, symbol and object. Arrays, functions and dates are all kinds of object.
Can you change a value's type?
Not the value itself, but you can get a new one of another type. Number("42") turns a string into a number, String(42) does the reverse. This is called type conversion.
Does a beginner need to learn every type?
No. The six from the list above are enough. You'll rarely meet the rest — and you'll recognize them by name when you need to.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





