JavaScript Syntax

JavaScript Tutorial

What is JavaScript Syntax?

JavaScript syntax refers to the set of rules that define how JavaScript programs are written and understood by the browser.

Just like grammar in a language, syntax tells JavaScript how to read and execute code.


 Basic Rules


1. JavaScript Statements

Each instruction is called a statement and usually ends with a semicolon (;).


2. JavaScript Variables

Variables store data. Examples:


3. JavaScript Identifiers (Names)

Names of variables, functions, etc.

Rules:

  • Must start with a letter, _ or $

  • Cannot start with a number

  • Case-sensitive (ageAge)

Example:


4. JavaScript Comments

Comments are ignored by the browser.


 


5. JavaScript Keywords

Keywords are reserved words (cannot be variable names):

let, var, const, if, else, function, return, class, etc.

Example:


6. JavaScript Values

Two types:

TypeExample
Literal values50, 3.14, "hello", true, false
Variablesx, name, price

Example:


Example with Output


 

Output:

Result: 15

Case Sensitivity

JavaScript is case-sensitive:


Summary Table

FeatureExample
Statementlet x = 10;
Variableconst name = "Sam";
Comment// hello
Case-sensitivecount ≠ Count

You may also like...