JavaScript Statements and Program Structure

JavaScript Statements and Program Structure

Building Blocks of JavaScript Programs

Author
Nguyen Bao Huy
15:42:00 08/02/2026
2 min read
0 comments

JavaScript Programs

computer program is a list of "instructions" to be "executed" by a computer. In a programming language, these programming instructions are called statements. A JavaScript program is a list of programming statements. In HTML, JavaScript programs are executed by the web browser.

JavaScript Statements

JavaScript statements are composed of: Values, Operators, Expressions, Keywords, and Comments. This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":

javascript
document.getElementById("demo").innerHTML = "Hello Dolly.";

Most JavaScript programs contain many JavaScript statements.

The statements are executed, one by one, in the same order as they are written.

Semicolons

Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement:

javascript
let a, b, c;  // Declare 3 variables
a = 5;        // Assign the value 5 to a
b = 6;        // Assign the value 6 to b
c = a + b;    // Assign the sum of a and b to c

When separated by semicolons, multiple statements on one line are allowed:

javascript
a = 5; b = 6; c = a + b;
On the web, you might see examples without semicolons.
Ending statements with semicolon is not required, but highly recommended.

JavaScript White Space

JavaScript ignores multiples spaces. You can add white space to your script to make it more readable. The following lines are equivalent:

javascript
let person = "Hege"; 
let person="Hege";

A good practice is to put spaces around operators ( = + - * / ):

javascript
let x = y + z; 

JavaScript Line Length and Line Breaks

For best readability, programmers often like to avoid code lines longer than 80 characters. If a JavaScript statement does not fit on one line, the best place to break it is after an operator:

javascript
document.getElementById("demo").innerHTML = "Hello Dolly!";

JavaScript Code Blocks

JavaScript statements can be grouped together in code blocks, inside curly brackets {...}. The purpose of code blocks is to define statements to be executed together. One place you will find statements grouped together in blocks, is in JavaScript functions:

javascript
function myFunction() {
  document.getElementById("demo1").innerHTML = "Hello Dolly!";
  document.getElementById("demo2").innerHTML = "How are you?";
}

JavaScript Keywords

JavaScript statements often start with a keyword to identify the JavaScript action to be performed. Our Reserved Words Reference lists all JavaScript keywords.

Here is a list of some of the keywords you will learn about in this tutorial:

KeywordDescription
varDeclares a variable
letDeclares a block variable
constDeclares a block constant
ifMarks a block of statements to be executed on a condition
switchMarks a block of statements to be executed in different cases
forMarks a block of statements to be executed in a loop
functionDeclares a function
returnExits a function
tryImplements error handling to a block of statements
JavaScript keywords are reserved words. Reserved words cannot be used as names for variables.
Author avatar

Nguyen Bao Huy

Lead Fullstack & AI Solutions Engineer

Specializing in Next.js App Router, React 19, TypeScript, and modern design systems. Passionate about creating seamless user experiences.

Discussion

0

No comments yet

Be the first to share your thoughts, question a concept, or provide additional tips!

Leave a Reply

Share your insights, questions, or solutions with the developer community.

Your avatar
0 / 500 characters