JS-016

Beginner3 min~3 min read#expression#values#operators
Expression
Produces a value
Goal
Learn what an expression is and why every expression produces a value.
Explanation
- An expression is any piece of code that evaluates to a single value.
- An expression can be a math calculation, a comparison, or string concatenation.
- JavaScript first evaluates the expression, then uses the resulting value.
- That value can be a number, string, boolean, or any other type.
- Almost every program is built from a large number of expressions.
Analogy
An expression is like a calculator. You enter a calculation and always get a ready result.
Code
console.log(5 + 3);
console.log("Hi" + "!");
console.log(10 > 3);Result: 8 Hi! true
Common mistake
Beginners often think an expression must be math. In reality, any code that produces a value is an expression.
Remember
- ✦ An expression always returns a value.
- ✦ The result of an expression can be used further in the program.
- ✦ 5 + 3, "Hi" + "!", and 10 > 3 are expressions.
Quick Quiz
What does an expression do?