Lesson 2: JavaScript Basics

Variables

Variables store data that your program can use.

Example:

let name = 'Alice'; // Modern way to declare variables
const age = 25; // A value that doesn’t change
var city = 'New York'; // Older way (use sparingly)

Data Types

  • String: Text data. Example: "Hello"
  • Number: Numeric data. Example: 42
  • Boolean: True or false. Example: true
  • Array: List of values. Example: [1, 2, 3]
  • Object: Key-value pairs. Example: {name: 'Alice', age: 25}

Operators

  • Arithmetic: +, -, *, /, %
  • Assignment: =, +=, -=, etc.
  • Comparison: ===, !==, <, >

Example:

let a = 10;
let b = 5;
console.log(a + b); // Outputs 15