Syntax, Semicolons & ASI in JavaScript
JavaScript statements usually end with semicolons and blocks wrap in curly braces — familiar C-style surface. The twist is ASI (Automatic Semicolon Insertion): the parser inserts missing semicolons at line breaks in most positions, so code without semicolons usually works — until it doesn't (a line starting with [ or ( can merge with the previous one).
Community practice split for years; the safe modern rule is simple: always write semicolons (or always omit them with a linter enforcing safe style — never mix casually). Comments are // for lines and /* ... */ for blocks, identical to C.
Statements and blocks
Statements end with semicolons; function bodies, loop bodies, and if-branches wrap in { } — whitespace itself means nothing.
ASI fills gaps
The parser auto-inserts semicolons at most line breaks — convenient until a [ or ( opens the next line and fuses two statements.
Pick a semicolon religion
Always-semicolons (safest default) or never-with-linter (StandardJS style) — both fine; accidental mixing is where bugs live.
Comments
// to end of line, /* ... */ across lines — same as C, used for notes and temporary disabling.
let total = 0total += 5;console.log(total); // 5/* multi-line comment */Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.