JavaScript Data Types
The 8 Built-in Types & How to Use Them
By AI Learning Assistant · JavaScript · ES6 · Fundamentals
🤖 AI-POWERED LESSON
This article is paired with a live AI session. As you read, you will see real questions asked to an AI assistant and the answers that came back showing you exactly how to use AI to master JavaScript data types faster.
Every value in JavaScript is always of a certain type. A variable can hold a string, then later hold a number JavaScript is dynamically typed, meaning variables are not bound to any single data type. There are eight basic data types in total, and understanding when to use each one is the foundation of writing clean, bug-free code.
We will walk through all eight Number, BigInt, String, Boolean, null, undefined, Symbol, and Object and at each stage, see how AI can deepen your understanding instantly.
Number
INTEGERS & FLOATS · INFINITY · NaN
The number type covers both integers and floating-point numbers. It also includes three special numeric values: Infinity, -Infinity, and NaN.
⚠️ THE STICKY NaN PROBLEM
Once a calculation produces NaN, it infects every further mathematical operation. The script never "dies" with a fatal error — it simply returns NaN. This makes it crucial to validate numeric inputs early.
BigInt
ARBITRARY-LENGTH INTEGERS · APPEND n
Regular number types cannot safely exceed ±(253-1). For cryptography, timestamps, or massive IDs, use BigInt by appending n to the end of an integer.
String
QUOTES & TEMPLATE LITERALS · NO char TYPE
JavaScript has no separate char type — only string. Use double quotes, single quotes, or backticks. Only backticks allow embedded expressions via ${...}.
Boolean
true / false · LOGICAL COMPARISONS
The boolean type has only two values: true and false. It is the direct result of all comparison operations and the backbone of conditional logic.
null & undefined
"NOTHING" VS "NOT ASSIGNED"
null represents "nothing," "empty," or "value unknown." undefined means "value is not assigned." By convention, use null when you want to intentionally clear a value, and let JavaScript assign undefined automatically for unassigned variables.
🚫 THE typeof null BUG
The expression typeof null returns "object". This is a officially recognized error in JavaScript, kept for backward compatibility. null is not an object — it is its own separate type.
Object & Symbol
COLLECTIONS & UNIQUE IDENTIFIERS
All other types are called "primitive" because they hold a single value. object is the only non-primitive type — it stores collections of data and complex entities. symbol creates unique identifiers for object properties and is used mostly in advanced scenarios.
LIVE AI LEARNING SESSION
Ask your AI assistant this question ↓
💬 YOU ASK THE AI:
"Why does typeof null return 'object' in JavaScript, and how do I reliably check if a value is null?"
🤖 AI RESPONDS:
This is one of JavaScript's most famous quirks. In the very first implementation of JavaScript, values were represented with a type tag and payload. The type tag for objects was 0, and null was represented with a null pointer — which also had the tag 0. The bug was never fixed because so much existing code depended on it.
To reliably check for null, always use strict equality: value === null. Do not trust typeof for this specific case.
Real-world example:
📝 MY NOTE — IN MY OWN WORDS
The AI explanation finally made the typeof null bug stick in my memory. I now picture JavaScript's early engine as a library where the shelf labeled 0 was shared between "objects" and "null," and they never re-labeled the shelves. From now on, I will always use === null in my validation logic. I also think of primitives as single LEGO bricks and objects as the completed build — that analogy helps me remember why arrays and functions (which are technically objects) behave differently under typeof.
Quick Comparison
TYPE CATEGORY typeof RESULT TYPICAL USE number Primitive "number" Math, counters, coordinates bigint Primitive "bigint" Cryptography, huge IDs string Primitive "string" Text, messages, DOM content boolean Primitive "boolean" Flags, conditions, toggles null Primitive "object" ⚠️ Intentional empty/unknown undefined Primitive "undefined" Unassigned by default symbol Primitive "symbol" Unique object keys object Non-Primitive "object" Collections, complex data 🤖 HOW AI ACCELERATES THIS TOPIC
Not sure what type a variable holds? Paste your code into an AI and ask: "What is the type of this variable at each line, and why?" The AI will trace the execution and explain every reassignment.
You can also ask: "Why is my comparison returning unexpected results?" — and the AI will check if you are comparing different types (like "5" == 5) and explain type coercion vs strict equality (===) in seconds.
AI-Assisted JavaScript Learning · Data Types Fundamentals · JavaScript ES6+
Learn this with a real instructor
Free lessons take you a long way on your own. The full programmes add live classes, assignments, Skill Points and a certificate — built for African students.