Lesson 4.2: Variables, Data Types & Operators
Variables in JavaScript
A variable is a container used to store data that can be used and manipulated later.
1. Declaring Variables
-
var– Old way, function-scoped. -
let– Modern way, block-scoped. -
const– Block-scoped, cannot be reassigned.
2. Data Types in JavaScript
JavaScript has primitive and non-primitive data types.
a) Primitive Data Types
| Type | Example | Description |
|---|---|---|
| String | "Hello" |
Textual data |
| Number | 10, 3.14 |
Numeric values |
| Boolean | true, false |
Logical values |
| Undefined | let x; |
Declared but not assigned |
| Null | let y = null; |
Empty value |
| Symbol | Symbol("id") |
Unique identifier |
| BigInt | 1234567890123n |
Large integers |
b) Non-Primitive Data Types
-
Object – Collection of key-value pairs
-
Array – List of values
3. Operators in JavaScript
Operators perform operations on values or variables.
a) Arithmetic Operators
b) Assignment Operators
c) Comparison Operators
d) Logical Operators
✅ Summary:
-
Variables store data (
var,let,const). -
Data Types: primitive (string, number, boolean, null, undefined, symbol, bigint) and non-primitive (object, array).
-
Operators perform arithmetic, assignment, comparison, and logical operations.
