← Back to Home

📦 Data Types: Think Containers

Different shaped containers

Data types define what kind of value a variable can hold. Think of them as different types of containers - each designed for specific contents.

📦 The Container Analogy

Just like you use a water bottle for liquids, a box for solids, and a bag for groceries, programming uses different data types for different kinds of information.

Common Data Types

🔢 Numbers

Use for: age, price, quantity, scores

📝 Strings (Text)

Any text enclosed in quotes: "Hello", "john@email.com", "123 Main St"

Use for: names, addresses, messages, emails

✅ Booleans (True/False)

Only two values: true or false

Use for: isLoggedIn, hasPermission, isActive

📋 Arrays (Lists)

Ordered collection: [1, 2, 3] or ["apple", "banana", "orange"]

Use for: shopping cart, todo list, user list

📁 Objects

Key-value pairs: {name: "Alice", age: 25}

Use for: user profiles, product details, settings

❓ Null/Undefined

Represents "nothing" or "not set yet"

Use for: optional fields, missing data

Why Data Types Matter

⚠️ Type Matters!

"5" + "3" = "53" (string concatenation)
5 + 3 = 8 (number addition)

Type Conversion

Sometimes you need to change types:

Real-World Examples

Choosing the Right Type

The bottom line: Data types are like choosing the right container for the job. Use numbers for math, strings for text, booleans for yes/no, and arrays for lists. Pick the right type, and your code will work smoothly!

Data Types Variables Fundamentals