Getting Started Lesson 4 of 30
JavaScript Syntax, Statements and Comments
The basic grammar of JavaScript — statements, semicolons, code blocks, case sensitivity, naming rules and comments that explain your code.
Every language has grammar rules. In English we end sentences with a period; in JavaScript we end statements with a semicolon. This lesson covers the small rules you need before writing real programs.
Statements
A JavaScript program is a list of statements, instructions that run one after another, from top to bottom.
<p id="out"></p>
<script>
let text = "Una. ";
text = text + "Pangalawa. ";
text = text + "Pangatlo.";
document.getElementById("out").textContent = text;
</script>
Semicolons
Each statement usually ends with a semicolon ;. JavaScript can often guess where a semicolon belongs if you forget it, but the guess is sometimes wrong. Beginners should always write them.
Whitespace and line breaks
JavaScript ignores extra spaces. These two lines do the same thing:
let total=price*qty;
let total = price * qty;
The second one is much easier to read. Put spaces around operators like =, + and *, and indent code inside blocks by 2 spaces.
Code blocks
Curly braces { } group statements into a block. You'll see blocks in functions, if statements and loops:
function greet() {
console.log("Magandang umaga!");
console.log("Handa na ba kayo?");
}
JavaScript is case-sensitive
score, Score and SCORE are three different names. getElementById works, but getElementByID (capital D) causes an error.
Naming rules
Names for variables and functions (called identifiers) must follow these rules:
- They can contain letters, digits,
_and$. - They cannot start with a digit:
2ndPlaceis not allowed,secondPlaceis. - They cannot be reserved words like
let,iforfunction. - No spaces:
final gradeis two words. UsefinalGrade.
JavaScript programmers use camelCase: the first word is lowercase and each new word starts with a capital, like finalGrade, studentName or totalPrice.
Comments
Comments are notes for humans. JavaScript ignores them completely.
<p id="out"></p>
<script>
// This is a single-line comment.
let pesos = 100; // A comment can also go at the end of a line.
/*
This is a multi-line comment.
Use it for longer explanations.
*/
document.getElementById("out").textContent = "Baon: ₱" + pesos;
</script>
Comments are also useful for switching off a line while testing. Put // in front of it, and JavaScript skips it. Programmers call this "commenting out" code.
Keywords you'll meet soon
| Keyword | Meaning |
|---|---|
let, const | Create a variable |
if, else | Make a decision |
for, while | Repeat code (loops) |
function | Create a reusable block of code |
return | Send a value back from a function |
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04