JavaScript — Statements
Programs read top to bottom
A statement is one instruction. Scripts execute statements in order, one after another:
console.log("First");
console.log("Second");
console.log("Third");
What you see
First
Second
Third
No surprises yet — but this ordering is the foundation for everything (and the source of bugs when scripts run before HTML exists).
Statements end with semicolons… mostly
let a = 3;
let b = 4;
let sum = a + b;
Semicolons mark statement boundaries. Modern JavaScript also inserts them automatically ("automatic semicolon insertion"), so many style guides skip them:
let a = 3 // both styles exist in the wild
Pick a convention, stick to it. The classic hazard of skipping them:
const x = 10
[1, 2].forEach(console.log) // parsed as 10[1,2] → crash!
Rare but real — starting a line with ( or [ right after an unterminated statement bites even experienced devs.
Whitespace is free
Spaces, tabs and newlines don't change meaning:
let name="Ada"; // cramped but valid
let greeting = "Hello"; // readable — do this
Format for the human who reads next. Consistent indentation (2 spaces is the JS convention) turns debugging from misery into scanning.
Blocks group statements
Curly braces bind statements into one unit:
{
let local = "only visible inside";
console.log(local);
}
You'll rarely write bare blocks — but they're the skeleton of every if, for and function:
if (age >= 18) {
console.log("Adult");
console.log("May proceed");
}
The braces make both prints conditional.
Case sensitivity — exact or nothing
JavaScript distinguishes upper from lower case ruthlessly:
let firstName = "Ada";
console.log(firstname); // ReferenceError!
console.log(firstName); // works
Same for keywords: getElementById, not getElementByID. When you meet "X is not defined" errors, first suspect spelling.
Comments
// single line comment
/* multi-line
comment */
/**
* Docblock — convention for describing functions
*/
function add(a, b) {
return a + b;
}
Reserved words can't be names
let let = 5; // SyntaxError
let class = "math"; // reserved — use className instead
Dozens of words (return, new, if, class…) are off-limits as variable names.
Mini Practice
- Log five lines; predict output before running
- Trigger the
[1,2]semicolon crash on purpose; then fix it two ways (semicolon / leading semicolon) - Write an if-block containing two statements; move one outside the braces and compare behavior
- Create
myVarandmyvar; confirm they're different variables - Comment out one line mid-program and verify the flow skips it
Next: syntax → (deepens naming/rules)
Related Topics
Frequently Asked Questions about Statements
What is Statements in JavaScript?
Statements is a fundamental concept in JavaScript. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Statements?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Statements.
Why is Statements important in JavaScript?
Statements is essential for JavaScript development. Understanding this concept will help you write better code and solve real-world problems more effectively.