11. Introduction to Data Types
Data types define the kind of value a variable can hold. JavaScript is a dynamically typed language, meaning you don't declare the type explicitly (like int or string); the type is determined automatically when the code runs.
Primitive Data Types
Primitives are immutable (cannot be changed) values. There are seven in JS:
- Number: Used for both integers and floating-point numbers.
- String: Used for text, enclosed in quotes.
- Boolean: Logical entity; either
trueorfalse. - null: Represents the intentional absence of any object value.
- undefined: Means a variable has been declared but has not yet been assigned a value.
- Symbol: A unique identifier (advanced, covered later).
- BigInt: For arbitrarily large integers.
Non-Primitive (Reference) Data Type
- Object: Used for complex data structures (including Arrays and Functions).