1. Variables

Variables are used to store data. In JavaScript, you declare variables using var, let, or const.

let name = "John";      // Variable that can be reassigned
const age = 30;         // Constant variable that cannot be reassigned
var isStudent = true;   // Older way to declare variables, function-scoped


Why “function-scoped”?

This is a key difference between var and let/const.

function example() {
  if (true) {
    var x = 10;
    let y = 20;
  }
  console.log(x); // ✅ works (function-scoped)
  console.log(y); // ❌ error (block-scoped)
}

2. Data Types

JavaScript has different data types, including numbers, strings, booleans, and arrays.

let number = 42;            // Number
let string = "Hello World"; // String
let isActive = false;       // Boolean
let numbers = [1, 2, 3];    // Array


3. Operators

Operators are used to perform operations on values and variables.

let sum = 10 + 5;           // Arithmetic operator
let isEqual = (10 === "10");  // Comparison operator
let isTrue = (true && false); // Logical operator