JavaScript statement

Understand the basics of JavaScript statements

If the expression is a single unit of JavaScript that the engine can evaluate, the statement can contain one or more different expressions and be executed by the engine to perform the operation.

The program consists of multiple statements. Statements can span multiple lines.

Just like expressions, JavaScript has a completely different set of statements:

  • Express statement
  • Statement
  • Control flow statement
  • loop statement
  • Miscellaneous statement

Let's delve into the details.

Delimited statement

The statement can end with an optional semicolon;. Using it, you can include multiple statements on one line. I usually don't use a semicolon, but you can use it at the end of the statement.

Express statement

The expression itself is also a statement:

this //the current scope
i //where i is a variable or a constant
1 / 2
i -= 2
i * 2
'A ' + 'string'
[] //array literal
{} //object literal
{a: 1, b: 2}
{a: {b: 1}}
a && b
a || b
!a //reference a property (or method) of an object
new object()
new a(1)
new MyRectangle('name', 2, {a: 4})
function() {}
function(a, b) { return a * b }
(a, b) => a * b
a => a * 2
() => { return 2 }

Statement statement

Using the declaration statement, you can assign a value to the variable name.


var i = 0
let j = 1
const k = 2

//declare an object value const car = { color: blue }

This is the function declaration:

//declare a function
function fetchFromNetwork() {
const fetchFromNetwork = () => {

Control flow statement

You can use a statement to group statements:

  //this is a block
  const a = 1;
  const b = 2;

Using this syntax, as long as JavaScript requires one statement, there can be multiple statements.

Please note that any conditional control flow statement will check the expression and execute a statement or a block based on the expression:

if (condition === true) {
  //execute this block
} else {
  //execute this block

If there is only one statement, you can omit the curly braces:

if (condition === true) /* statement */ else /* another statement */

In the next section, I will introduce all the different control flow structures.

loop statement

The way the loop works is the same asifThe example above.

Some loops check an expression and execute a statement repeatedly until the value of the expression is true.

Others loop through the list and execute a statement (or block) for each element of the list until the list is complete.

See me fullJavaScript loop tutorial.

Miscellaneous statement

return <expression>

This statement returns a value from the function, thus ending the execution of the function.

throw <expression>

Throw an exception (we will see what an exception is later)


The try / catch block is used to catch exceptions. Again, we will see those applied later.

try {

} catch (<expression>) {


use strict

This statement appliesStrict mode.


Add a breakpointDebuggercan use.

Download mine for freeJavaScript beginner's manual

More js tutorials: