Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Empty statement

BaselineWidely available

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

js
;

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:

js
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:

js
if (condition);      // Caution, this "if" does nothing!  killTheUniverse(); // So this always gets executed!!!

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-empty-statement

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp