---
title: "JavaScript Statements"
url: https://weworkworldwide.com/tutorials/javascript-statements-3/
description: "In this section we will learn what the statement is and how to use it in JavaScript. Define Statements in JavaScript A computer program is a series of inst"
date: 2026-08-08T13:00:03+00:00
source: https://weworkworldwide.com/llms.txt
---

# JavaScript Statements

In this section we will learn what the statement is and how to use it in JavaScript.

## Define Statements in JavaScript

A computer program is a series of instructions for computers to run. Each of these instructions is called a statement.

A statement is composed of:

-   Values (of type String, Number and other data types mentioned in  
    the *data type section*.)

-   Operators: In later section you’ll see these operators in a  
    greater detail but in short it is mathematical operators like  
    multiplication, subtraction, addition, division etc., comparison  
    operators in order to see if two values are equal or one is greater than  
    the other, and other types of operators that are used for a different  
    matter in a program.

-   Expression: combining values and operators in order to reach a  
    new value is called expression. For example, 2 * 2 is an expression  
    because it has an operator and values and obviously it resolves to a new  
    value. For the majority of times a statement includes expression as  
    well.

Note: But remember a statement can be also assigning just a single value to a variable as well.

## JavaScript Semicolons `;`

In JavaScript in order to separate each statement from the other, we use a semicolon `;` at the end of each statement.

Note: if two statements are in two separate line, then the use of semicolon becomes optional. That means we can ignore the semicolon altogether.

## Example: creating JavaScript Statements

``` line-numbers
<!DOCTYPE html>
<html>
<head>
<title>JS is fun :)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h3>Output:</h3>
<p id = "link">…</p>
<script>
let num = typeof 10
let str = typeof num
document.getElementById("link").innerText = `${num}, ${str}`
</script>
</body>
</html>
```

Here we have 3 statements as each of them is set in a separate line. Here because they are in a separate line, we didn’t use the semicolon. But if they all were in one line, in that situation we needed to separate each statement from the other via the semicolon `;`. Otherwise we could get a compile time error.

Considering the fact that in the future, other developers or even ourselves might come back and read our old source code, it’s a good practice to always add the semicolon at the end of our statements even if they are not necessary. This helps the readability of the source code.

## Example: JavaScript statement without semicolon

``` line-numbers
<!DOCTYPE html>
<html>
<head>
<title>JS is fun :)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h3>Output:</h3>
<p id = "link"></p>
<script>
let name = "John Doe" document.getElementById("link").innerText =`Hi, My name is ${name}`;
</script>
</body>
</html>
```

As you can see this time we didn’t get an output! This is mainly because there are two statements but both are in the same line and we didn’t separate them via a semicolon `;`. In a situation like this, the compiler doesn’t know where one statement ends and the other begins. For this reason, we get a compile time error.

If you open your browser’s *console*, you’ll see the error mentioned below:

Uncaught SyntaxError: Unexpected identifier

Again, this is mainly because the compiler couldn’t separate the two statements from each other.

Now if we add a semicolon between the two statements, the error will be resolved and we get the correct output.

## Example: JavaScript statement with semicolon

``` line-numbers
<!DOCTYPE html>
<html>
<head>
<title>JS is fun :)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h3>Output:</h3>
<p id = "link"></p>
<script>
let name = "John Doe"; document.getElementById("link").innerText = `${name}`;
</script>
</body>
</html>
```

## JavaScript White Space

So far, our examples were designed in a way that each statement takes only one line. But in JavaScript we’re allowed to break a statement to take multiple lines if that statement is lengthy. This is mainly done to increase the readability of a source code.

## Example: JavaScript statement with white space

``` line-numbers
<!DOCTYPE html>
<html>
<head>
<title>JS is fun :)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h3>Output:</h3>
<p id = "link"></p>
<script>
let name = "John Doe";
document.getElementById("link").innerText =
`Hi, My name is ${name}`;
</script>
</body>
</html>
```

The second statement in this example is taking two lines of code but the compiler will ignore this new line space and considers it as only one statement.
