Empty statement
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Anempty statement is used to provide no statement, although theJavaScript syntax would expect one.
Try it
const array1 = [1, 2, 3];// Assign all array values to 0for (let i = 0; i < array1.length; array1[i++] = 0 /* empty statement */);console.log(array1);// Expected output: Array [0, 0, 0]
Syntax
;
Description
The empty statement is a semicolon (;
) indicating that no statement willbe executed, even if JavaScript syntax requires one.
The opposite behavior, where you want multiple statements, but JavaScript only allows asingle one, is possible using ablock statement,which combines several statements into a single one.
Examples
Empty loop body
The empty statement is sometimes used with loop statements. See the following examplewith an empty loop body:
const arr = [1, 2, 3];// Assign all array values to 0for (let i = 0; i < arr.length; arr[i++] = 0) /* empty statement */ ;console.log(arr);// [0, 0, 0]
Unintentional usage
It is a good idea to commentintentional use of the empty statement, as it isnot really obvious to distinguish from a normal semicolon.
In the following example, the usage is probably not intentional:
if (condition); // Caution, this "if" does nothing! killTheUniverse(); // So this always gets executed!!!
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-empty-statement |