In JavaScript, statements are instructions that are executed by the browser or Node.js. A statement can be a simple or complex operation that performs an action, such as assigning a value to a variable, calling a function, or controlling program flow with conditional statements.

Declaration Statements

Declaration statements are variables, functions, or classes that are introduced into a program. These statements begin with a keyword followed by its identifier or name.

Variables are containers for storing data values:

var x = 5;
var y = 6;
var X = 4;
var z = x + y;

In this example, x, y, X, and z, are declared with the var keyword.

Note: JavaScript identifiers are case-sensitive. Notice that x is not the same as X.

Expression Statements

Expression statements, such as function calls or assignments, evaluate an expression and generate a value in JavaScript. They can be assigned to a variable or used as part of a larger expression and are then discarded.

// Function call
console.log('Hello World');

The second statement below re-assigns the value 5 to the variable x, while the third statement logs the value of x to the console:

var x = 5;
x = 6;

Conditional Statements

Conditional statements, such as if statements or switch statements, control program flow based on a condition:

// If statement
if (x > 5) {
console.log('x is greater than 5');
// Switch statement
switch (x) {
case 1:
console.log('x is 1');
case 2:
console.log('x is 2');
console.log('x is neither 1 nor 2');

Loop Statements

Loop statements, such as while loops or for loops, repeat a block of code while a condition is true:

// While loop
while (x < 5) {
// For loop
for (let i = 0; i < 5; i++) {

Jump Statements

Jump statements, such as break or return statements, transfer control to another part of the program.

// Break statement
for (let i = 0; i < 5; i++) {
if (i === 3) {
// Return statement
function add(x, y) {
return x + y;

All contributors

Looking to contribute?

Learn JavaScript on Codecademy