🧩 Chapter 2: Variables, Data Types, and Operators
🔹 1. Variables
Used to store data values.
Syntax:
let name = "John";
var age = 18;
const PI = 3.14;
var → old, function-scopedlet → block-scopedconst → for constants (cannot be changed)
🔹 2. Data Types
Primitive Data Types:
- String →Â
"Hello" - Number →Â
10,Â3.14 - Boolean →Â
true /Âfalse - Undefined → variable declared but no value
- Null → no value
- Symbol → unique identifier
- BigInt → very large numbers
Non-Primitive:
- Objects, Arrays, Functions
🔹 3. Operators
A. Arithmetic Operators
+, -, *, /, %, ++, --
B. Assignment Operators
=, +=, -=, *=, /=, %=
C. Comparison Operators
==, ===, !=, !==, >, <, >=, <=
==compares value===compares value + type (strict equality)
D. Logical Operators
&& (AND), || (OR), ! (NOT)
E. String Operators
+ → used for concatenation
Example:
let fullName = firstName + " " + lastName;
F. Ternary Operator
let result = (age >= 18) ? "Adult" : "Minor";
🔹 4. Type Conversion
Number("10"); // Converts string to number
String(10); // Converts number to string
