Data Types
JavaScript has numbers, strings (text in quotes), and booleans (true/false). You don't declare the type; JavaScript figures it out.

Appy Says…
JavaScript has seven primitive types — and getting them confused is the source of more bugs than almost anything else. Know your types and you'll understand why '5' + 5 === '55' but '5' - 5 === 0. Yes, really.
What are Data Types in JavaScript?
Every value in JavaScript has a type that determines what you can do with it. JavaScript has 7 primitive types plus the Object type (which includes arrays and functions).
- •
string— text:'hello',"world",`template` - •
number— integers AND decimals:42,3.14,-7 - •
boolean—trueorfalse - •
undefined— variable declared but not assigned - •
null— intentional absence of a value - •
bigint— integers too large fornumber:9007199254740993n - •
symbol— unique identifier (advanced) - •Check type:
typeof value→'string','number', etc.
Think of it like Minecraft item categories
In Minecraft, tools, blocks, food, and weapons are different categories — a sword won't go in the food slot. Data types are JavaScript's categories. You can add numbers, concatenate strings, and toggle booleans — but mixing them without care gives weird results.
How It Works
- •1. JavaScript is dynamically typed — a variable can change type
- •2.
typeof 42→'number';typeof 'hi'→'string' - •3. Type coercion: JS auto-converts types in operations —
'5' + 5→'55'(number becomes string) - •4. Use
===(strict equality) to compare type AND value:5 === '5'→false - •5.
==(loose equality) converts types first:5 == '5'→true(avoid!) - •6. Convert explicitly:
Number('5'),String(42),Boolean(0)
Real-World Examples
- •A form returns numbers as strings — use
Number(input.value)before maths - •TikTok's view count is a
number; the display text (e.g. '1.2M') is astring - •Checking 'is the user logged in?' returns a
boolean - •
nullis returned by APIs when a field has no value (e.g. no profile picture URL) - •
undefinedappears when you access a property that doesn't exist on an object
Key Facts
- •
typeof nullreturns'object'— this is a famous JavaScript bug kept for historical reasons - •Falsy values:
0,'',null,undefined,NaN,false— all evaluate to false in conditions - •
NaN(Not a Number) is actually of typenumber—typeof NaN === 'number' - •TypeScript was created mainly to add static types to JavaScript — type safety is that important
Watch Out!
Never use == (loose equality) — it performs type coercion in surprising ways. Always use === (strict equality). 0 == false is true and '' == false is true — these will silently break your logic.
Remember
Always use === not ==. When mixing types, convert explicitly with Number(), String(), or Boolean().
What You Learned
- •7 primitive types: string, number, boolean, null, undefined, bigint, symbol
- •Use
===for strict comparison; usetypeofto inspect types - •Unlocks: avoiding type-coercion bugs, safe form handling, confident API data parsing
Key Facts
- →
typeof nullreturns'object'— this is a famous JavaScript bug kept for historical reasons - →Falsy values:
0,'',null,undefined,NaN,false— all evaluate to false in conditions - →
NaN(Not a Number) is actually of typenumber—typeof NaN === 'number' - →TypeScript was created mainly to add static types to JavaScript — type safety is that important
Real-World Examples
Remember
Always use === not ==. When mixing types, convert explicitly with Number(), String(), or Boolean().
Quick Quiz
What type is true?