JavaScript

Data Types in JavaScript

Master JavaScript data types! Learn about strings, numbers, booleans, null, undefined, objects, and how to work with each type.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master JavaScript data types! Learn about strings, numbers, booleans, null, undefined, objects, and how to work with each type. This hands-on tutorial focuses on practical implementation of data types in javascript concepts.

Data Types in JavaScript

JavaScript has different types of data. Understanding data types is crucial for writing effective code!

1. What are Data Types? 🎨

What is it? Data types define what kind of value a variable can hold. Think of them as categories of information.

Why use it? Knowing the type helps you understand what operations you can perform. You can't multiply a "word" by 5, but you can multiply a number.

How it works: JavaScript is dynamically typed, meaning you don't have to specify the type when declaring a variable. The engine figures it out automatically.

2. Primitive Data Types πŸ“¦

Primitive types are the basic building blocks. They are immutable (cannot be changed) and stored directly in the Stack memory.

The 7 Primitives:

  1. String: Text data ("Hello")
  2. Number: Integers and decimals (42, 3.14)
  3. Boolean: Logical values (true, false)
  4. Null: Intentionally empty value (null)
  5. Undefined: Variable declared but not assigned (undefined)
  6. Symbol: Unique identifier (Advanced)
  7. BigInt: Very large numbers (Advanced)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Reference Data Types πŸ“š

Reference types are more complex. They are mutable (can be changed) and stored in the Heap memory. The variable only holds a reference (address) to the data.

Common Reference Types:

  1. Object: Collection of key-value pairs
  2. Array: Ordered list of values
  3. Function: Block of code
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Primitives vs Reference Types (Memory) 🧠

This is a critical concept!

  • Primitives are compared by value.
  • Reference Types are compared by reference (memory address).
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Type Coercion πŸ”„

JavaScript tries to be helpful by automatically converting types, but this can lead to bugs.

Implicit Coercion:

  • "5" + 3 -> "53" (Number becomes String)
  • "5" - 3 -> 2 (String becomes Number)
  • true + 1 -> 2 (true becomes 1)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

6. typeof Quirks πŸ›

The typeof operator tells you the type of a value, but it has some historical bugs.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

7. Symbols & BigInt (Advanced) πŸš€

Symbol

Used to create unique identifiers for object properties.

const sym1 = Symbol("id");
const sym2 = Symbol("id");
console.log(sym1 === sym2); // false (Always unique!)

BigInt

Used for numbers larger than 2^53 - 1 (9 quadrillion).

const big = 9007199254740991n; // Notice the 'n' at the end

Practical Example: Data Type Validator πŸ›‘οΈ

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript data types, primitives vs references, type coercion, and memory allocation"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

What does typeof null return?

null
object
undefined
number

Key Takeaways

βœ… Primitives (String, Number, etc.) are stored by value in the Stack.
βœ… Reference Types (Object, Array) are stored by reference in the Heap.
βœ… typeof null is "object" (it's a bug!).
βœ… Type Coercion can be tricky; be explicit with conversions.
βœ… Symbols are unique, BigInt is for huge numbers.

What's Next?

Now that you understand data types, let's learn about Operators & Expressions to manipulate and compare these values!

Keep coding! πŸš€