JS Syntax

JavaScript syntax defines how code is structured and executed. Learn the basic rules for writing clean and valid JavaScript.

On this page

JavaScript Statements

A JavaScript program is made up of statements. Each statement tells the browser to perform an action.

let x = 10;
let y = 20;
console.log(x + y);

JavaScript Keywords

Keywords are reserved words with special meaning in JavaScript. Examples include let, const, if, function, and return.

Case Sensitivity

JavaScript is case-sensitive. Variable and function names must match exactly.

let name = "John";
let Name = "Jane";

console.log(name); // John
console.log(Name); // Jane

Semicolons

Semicolons are optional in many cases, but using them consistently is recommended to avoid edge cases.

let a = 5
let b = 6
console.log(a + b)

Whitespace and Line Breaks

JavaScript ignores extra whitespace. You can format your code to improve readability.

let total = 10 + 20;
let result = total * 2;

Code Blocks

Code blocks are defined using curly braces { }. They group multiple statements together.

if (true) {
  console.log("This is a block");
}

Comments

Comments help explain code and are ignored by JavaScript.

// Single-line comment

/*
  Multi-line
  comment
*/

Identifiers

Identifiers are names used for variables, functions, and objects. They must start with a letter, underscore (_), or dollar sign ($).

let _value = 10;
let $price = 20;

Next Step

Now that you understand JavaScript syntax rules, continue with JS Variables to learn how data is stored and managed.

JS Syntax Examples (8)