An expression is a fragment of code that produces a value.
For example, you got literal values like 43 or “happy.” These are always expressions!
Expressions are also considered something in between parentheses.
Binary and unary operators that hold 2 expression values or 1 are also fully considered expressions as well.
This also infers that expressions can contain other expressions, nested within each other.
If you think about expression as part of a sentence, then a statement would be the entire sentence.
If you’re having trouble recognizing a statement, you can tell by the semicolon in front of it.
If it’s got a semicolon in front of it, that entire line is a statement.
How to tell the difference between an expression and a statement
Here’s an example of an expression:
22 is a literal number.
The word happy is also a literal string.
But if you wanted a statement, it looks something like this:
Notice the semicolon to the right of 22? That’s what makes it a statement.
!true; is a statement because it’s also got a semicolon to the right of it.
Side effects: When a statement changes what comes after it
When a statement is used to change what comes after it, the concept is called side effects.