Aral Code

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.

Example Statements run in order
<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: 2ndPlace is not allowed, secondPlace is.
  • They cannot be reserved words like let, if or function.
  • No spaces: final grade is two words. Use finalGrade.

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.

Example Single-line and multi-line comments
<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

KeywordMeaning
let, constCreate a variable
if, elseMake a decision
for, whileRepeat code (loops)
functionCreate a reusable block of code
returnSend a value back from a function

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Which variable name is NOT allowed?
2. Which is written in camelCase?
3. How do you write a single-line comment?
4. Are total and Total the same variable?

By Sir Reyel · Last updated 2026-12-04