What is a Statement?

So far, we've seen some components that make up the vocabulary for a programming language, such as variables, operators, and keywords. JavaScript uses this vocabulary to form "statements" or instructions that run in a web browser. This article describes several of the types and groups of keywords used in JavaScript statements. We'll drive into JavaScript keywords in the next section.

If you have programmed in another language, you will notice that statements in JavaScript use a similar syntax to Java, C++, or Python. Most statements contain one or several lines of code that perform a task. For example, a "declaration-statement" creates a variable, a "conditional-statement" handles a decision, and a "looping-statement" executes code many times. JavaScript statements written on one line do not require a semicolon (";"), but it is best practice to end each line with one. 

Control flow

Block

A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.

break

Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.

continue

Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.

Empty

An empty statement is used to provide no statement, although the JavaScript syntax would expect one.

if...else

Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.

switch

Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.

throw

Throws a user-defined exception.

try...catch

Marks a block of statements to try, and specifies a response, should an exception be thrown.