Data Types and Strings
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.
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+
Complete this lesson
Mark as complete to track your progress