VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-statements/

⇱ JavaScript Statements - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Statements

Last Updated : 11 Jul, 2025

JavaScript statements are programming instructions that a computer executes. A computer program is essentially a list of these "instructions" designed to perform tasks. In a programming language, such instructions are called statements.

Types of Statements

1. Variable Declarations (var, let, const)

In JavaScript, you can declare variables using var, let, or const. let and const are used in modern JavaScript for block-scoped variables, while var is function-scoped and generally considered outdated.

2. Assignment Statement

An assignment statement is used to assign a value to a variable. You can assign any type of value, including strings, numbers, and objects, using the assignment operator =.

3. Expression Statements

An expression in JavaScript is any valid unit of code that resolves to a value. When an expression is executed, it can perform an action (e.g., calculation, function call) and return a result. An expression can also be used as a statement.

4. Control Flow Statements

Control flow statements are used to control the order in which statements are executed in a program. Examples include if, else, switch, while, and for loops.

5. Function Declarations

A function declaration is a statement that defines a function in JavaScript. Functions are reusable blocks of code designed to perform specific tasks.

6. Return Statement

The return statement is used to exit a function and optionally pass a value back to the calling code.

7. Throw Statement

The throw statement is used to create custom errors in JavaScript. It is often used in conjunction with try...catch to handle errors.

8. Try...Catch Statement

The try...catch statement is used to handle exceptions in JavaScript. The code inside the try block is executed, and if an error occurs, the code inside the catch block will handle the error.

9. Break and Continue Statements

The break and continue statements are used within loops. break exits the loop, while continue skips to the next iteration.

Some commonly used keywords are:

Keyword

Description

var

Used to declare a variable

let

Used to declare a block variable

const

Used to declare a block constant

if

Used to decide if certain block will get executed or not

switch

Executes a block of codes depending on different cases

for

Executes a block of statements till the condition is true

function

Used to declare a function

return

Used to exit a function

try

Used to handle errors in a block of statements

break

Used to terminate a loop

continue

Used to continue a loop

Comment