Understanding the Difference Between and Expression and a Statement

Ole Ersoy
Sep 27, 2022

--

Image by Jevgeni Fil from Pixabay

Scenario

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! is assigned.

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

Demo

--

--