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!”
.