Module 1: Getting Started with JavaScript
Your First JavaScript Program
Write a small program, read its output, and learn statement and comment basics.
A JavaScript program is made from statements and expressions. An expression produces a value; a statement performs an action or controls the flow of execution. Semicolons are often optional because JavaScript has automatic semicolon insertion, but consistent style makes code easier to read.
const name = "Asha";
const completedLessons = 3;
const totalLessons = 10;
console.log(`Welcome, ${name}!`);
console.log(`Progress: ${completedLessons}/${totalLessons}`);
The const declarations create bindings that cannot be reassigned. Template literals use backticks and ${...} to insert evaluated expressions into a string.
Comments#
// A single-line comment
/*
A multi-line comment can explain
a non-obvious decision.
*/
Prefer meaningful names and code that explains itself. Comments are most useful for intent, constraints, and reasons that are not obvious from the code.
Values and output#
console.log can display strings, numbers, booleans, arrays, and objects. You can log several values at once:
const price = 250;
const quantity = 2;
console.log("Total:", price * quantity);
Common beginner mistakes#
- Misspelling a variable name; identifiers are case-sensitive.
- Using a variable before it has been initialized.
- Expecting
"5" + 1to behave like5 + 1without understanding coercion. - Forgetting which environment a browser-only API belongs to.
Practice#
Create a program that stores your name, the course name, and the number of lessons you want to finish this week, then logs a short summary.