Ch 4 · Data Types — Kinds of Values · JavaScript
Topic 4 of 13 in JavaScript — Complete Tutorial (Beginner) — 5 lessons.
What is a Data Type and Why Does it Matter?
Every piece of information stored in a program belongs to a category. A number like 42 is very different from a word like "Alice", even though the computer stores both in memory. JavaScript uses the concept of a data type to keep these categories separate. A data type tells you what kind of value a variable holds — and knowing the type helps you understand what you can do with it. You can add two numbers, but adding a number to a sentence does something quite different.
The number Type in Depth
In JavaScript, all numbers — whole numbers, decimals, negative numbers, and even very large ones — share a single type called number. There is no separate "integer" type or "decimal" type like in some other languages. This keeps things simple: every calculation between numbers produces another number. JavaScript can handle anything from your age (12) to the distance to the moon (384_400 km) to a pencil price with paise (0.50) — they are all just numbers.
The string Type in Depth
A string is any sequence of characters — letters, digits, spaces, punctuation, symbols, even emojis — wrapped inside quotation marks. Strings are how your program works with all human-readable text. Every name, sentence, message, email address, product label, or button caption in a program is a string. You can create strings using double quotes, single quotes, or backticks. All three work identically for plain text, but backticks unlock a special feature called template literals, which let you embed variables and expressions directly inside the text using the ${ } syntax.
The boolean Type in Depth
A boolean is the simplest possible data type — it has exactly two possible values: true and false. Nothing else. No "maybe", no "sometimes", no 0.5. Booleans are the language of decisions in programming. Every time your program needs to choose between two paths — should I run this code or skip it? — it relies on a boolean value to make that choice. When you write an if statement, the condition inside the brackets must evaluate to either true or false.
undefined, null, and typeof
JavaScript has two special values that both represent "nothing", but they mean slightly different things. undefined means a variable has been declared but no value has been given to it yet — the box exists but is empty. JavaScript sets this automatically. null, on the other hand, is a value you assign deliberately to say "this is intentionally empty right now." For example, a winner variable might start as null before a game finishes, then get a real name once someone wins.
All topics in JavaScript Beginner
- Introduction to Programming & JavaScript
- Your First JavaScript Program
- Variables — Your Data Containers
- Data Types — Kinds of Values
- Operators & Expressions
- Conditional Statements
- Loops & Iterations
- Functions
- Arrays — Lists of Data
- Objects & Classes
- Strings — Working with Text
- Error Handling
- Mini-Projects & Practice