Understanding the Difference Between and Expression and a Statement | Concept

Ole Ersoy
Sep - 27  -  1 min

We have the code console.log("Hola!").

Is this an expression or a statement?

Approach

An expression returns a value. The statement console.log("Hola!") does not return a value so it is not an expression.

The below code illustrates an expression.

const greeting = spanish ? "Hola!" : "Hi!";

If spanish is true greeting is assigned Hola! otherwise Hi!.

The expression part of the statement is spanish ? “Hola!” : “Hi!”.

Demo