JavaScript syntax is the set of rules that define how JavaScript programs are written and executed.

1. JavaScript Statements

A statement is an instruction executed by the browser.

console.log("Hello World");
  • Statements usually end with a semicolon (;)
  • Semicolons are optional but recommended

2. JavaScript Case Sensitivity

JavaScript is case-sensitive.

let name = "John";
let Name = "Doe";

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

👉 name and Name are different variables

3. Variables in JavaScript

Variables store data.

Declaring Variables

var x = 10;     // old (function scoped)
let y = 20;     // block scoped
const z = 30;   // constant (cannot be reassigned)

Rules

  • Variable names must start with letters, _, or $
  • Cannot start with numbers
  • No spaces allowed

4. JavaScript Comments

Single-line Comment

// This is a comment

Multi-line Comment

/*
  This is a
  multi-line comment
*/

Comments improve code readability.

Categorized in:

Javascript,