Home JavaScript JavaScript Syntax

JavaScript Syntax

Beginner ⏱ 6 min read Updated: Jul 2026
  • JavaScript syntax defines the rules for writing JavaScript code
  • It tells the browser how JavaScript statements should be written
  • JavaScript syntax includes variables, values, operators, functions, and statements
  • Correct syntax helps JavaScript programs run without errors

What is JavaScript Syntax?

JavaScript syntax is the set of rules that defines how JavaScript programs are written. Just like every language has grammar rules, JavaScript also has specific rules that developers must follow to write correct code.

JavaScript code is made up of statements. Each statement performs a specific task, such as creating variables, displaying output, or executing functions.

JavaScript Statements

A JavaScript statement is a single instruction that tells the browser to perform an action. Statements are usually separated by a semicolon (;).

Example

let message = "Hello JavaScript";
console.log(message);
        
Result
Hello JavaScript

JavaScript Variables

Variables are used to store data values. JavaScript provides three keywords to declare variables: var, let, and const.

Example

let name = "Shivam";
const age = 21;
console.log(name);
console.log(age);
        

JavaScript is Case Sensitive

JavaScript is a case-sensitive language. This means uppercase and lowercase letters are treated as different characters.

Example

let name = "Alex";
console.log(name);
console.log(Name);
        
💡 Note: In the above example, name and Name are different because JavaScript treats uppercase and lowercase letters differently.

JavaScript Comments

Comments are used to explain JavaScript code. They are ignored by the browser and do not affect program execution.

Example

// This is a single line comment
let value = 10;
        

JavaScript Functions

Functions are blocks of reusable code designed to perform a specific task.

Example

function greet() {
    console.log("Hello World");

greet();
        

JavaScript Code Blocks

JavaScript code blocks are written inside curly braces { }. They group multiple statements together.

Example

if (age >= 18 ) {
    console.log("Adult");
}
        

Important JavaScript Syntax Rules

Semicolon (;)

Used to separate JavaScript statements.

Curly Braces { }

Used to define code blocks.

Quotes

Used to create string values.

Case Sensitive

Uppercase and lowercase are different.

💡 Note: Learning JavaScript syntax is the first step toward creating interactive websites and modern web applications.