Next →

Your First JavaScript Code

Understanding JavaScript Syntax

JavaScript syntax is the set of rules that define how JavaScript code is written and interpreted. Writing syntactically correct code is essential for your program to run properly.

Statements

A statement is a complete instruction, like telling the computer to do something. Each statement usually ends with a semicolon (;), though JavaScript can sometimes infer it automatically.

Example:

let greeting = "Hello";

Case Sensitivity

JavaScript is case sensitive. That means myVariable and myvariable are different identifiers.

Comments

Comments are notes for humans reading the code and are ignored by JavaScript.

Writing Your First Code

You can write JavaScript code inside <script> tags in an HTML file or in the browser console.

Example:

alert("Hello, JavaScript!");

This will show a popup message box with the text "Hello, JavaScript!".