sahilrajput.com

Statement and Expression in Programming

13 June 2026 (Source: ChatGPT Private)

What is a statement in programming for e.g, in javascript?

In programming, a statement is an instruction that tells the computer to do something.

In JavaScript, these are statements:

let name = "Sahil";      // Variable declaration statement
console.log(name);       // Expression statement
if (name === "Sahil") {  // If statement
  console.log("Hello");
}

Think of it this way:

Examples of expressions:

2 + 3
name
isLoggedIn && isAdmin

Examples of statements:

let x = 5;
x = x + 1;
console.log(x);
return x;
break;

A statement can contain expressions:

let x = 2 + 3;

Here:

A simple analogy:

Is console.log(“Hello”) part of if statement?

Yes.

In this code:

if (name === "Sahil") {
  console.log("Hello");
}

The if statement consists of:

  1. The condition:

    name === "Sahil"
    

    (an expression)

  2. The body:

    {
      console.log("Hello");
    }
    

    (a block containing one statement)

console.log("Hello"); is its own statement, but it is also part of the body of the if statement.

You can think of it hierarchically:

If Statement
├─ Condition: name === "Sahil"
└─ Body (Block Statement)
   └─ Expression Statement
      └─ console.log("Hello")

So console.log("Hello"); is both: