Understanding the Difference Between and Expression and a Statement

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation