0.1 What is JavaScript & Writing Variables
Welcome to JavaScript! JavaScript is the programming language that powers interactive web pages, web servers, mobile apps, and modern applications worldwide.
1. How JavaScript Code Executes
JavaScript reads and executes your instructions line-by-line from top to bottom. Each instruction is called a statement, usually ending with a semicolon ";" .
// This is a single-line comment (ignored by JavaScript)
/* This is a
multi-line comment */
console.log("Hello, Beginner!"); // Prints message to console
/* This is a
multi-line comment */
console.log("Hello, Beginner!"); // Prints message to console
2. Variables: Declaring vs Assigning
A variable is a named container in memory used to store data values. Creating a variable involves two parts:
- Declaration: Telling JS to reserve a memory slot (e.g.
let score;) - Assignment: Storing a value inside that slot (e.g.
score = 100;)
You can combine both steps: let score = 100;
3. `const` vs `let` vs `var`
JavaScript provides three keywords to declare variables:
const(Constant): Value **cannot** be reassigned after declaration.let(Block-scoped): Value **can** be reassigned anytime later.var(Legacy): Old ES5 keyword with function-scoping bugs (avoid in modern JS!).
📌 KEY POINTS TO REMEMBER
- Default to `const` for all variables unless you know the value will change later. Use
letwhen reassignment is required. - Naming Rules: Variable names are case-sensitive (
userAge≠userage). UsecamelCase(e.g.totalStudentCount). - Illegal Names: Cannot start with a number (e.g.
123nameis invalid) and cannot contain spaces or reserved JS words likeletorfunction.
⚡ Interactive Visual: Variable Inspector
Click buttons to simulate variable declarations and reassignments in memory:
State: Ready. Click a button above.