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
  • Booleantrue or false
  • Undefined – declared but not assigned
  • Null – intentional empty value
  • Symbol – unique identifiers
  • BigInt – very large integers
JavaScript Editor

🔄 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().

JavaScript Editor

🔸 Non-Primitive Data Types

Non-primitive values are reference types, stored in memory by reference. They include objects, arrays, functions, dates, and regex.

JavaScript Editor

📐 typeof Operator

The typeof operator checks the type of a variable.

JavaScript Editor

🎮 Practice: Shopping Cart

Apply your knowledge of data types by building a shopping cart system.

JavaScript Editor

📚 Summary

  • JavaScript has 7 primitive types and multiple reference types
  • typeof null returns object (a historical bug)
  • Type conversion can be implicit (coercion) or explicit
  • Objects, arrays, and functions are reference types stored in memory