JavaScript Data Types
Data types define the kind of values that can be stored and manipulated in a program. JavaScript supports primitive and non-primitive data types.
🔹 Primitive Data Types
Primitives are immutable values stored directly in memory.
- String – text (e.g.,
"Hello") - Number – integers, floats, NaN
- Boolean –
trueorfalse - Undefined – declared but not assigned
- Null – intentional empty value
- Symbol – unique identifiers
- BigInt – very large integers
🔄 Type Conversion
JavaScript automatically converts values between types in some cases (type coercion). You can also convert types manually using functions like Number(),String(), and Boolean().
🔸 Non-Primitive Data Types
Non-primitive values are reference types, stored in memory by reference. They include objects, arrays, functions, dates, and regex.
📐 typeof Operator
The typeof operator checks the type of a variable.
🎮 Practice: Shopping Cart
Apply your knowledge of data types by building a shopping cart system.
📚 Summary
- JavaScript has 7 primitive types and multiple reference types
typeof nullreturnsobject(a historical bug)- Type conversion can be implicit (coercion) or explicit
- Objects, arrays, and functions are reference types stored in memory