Expressions
Expressions:
- 1 + 2
- a + b (assuming existing variables a and b)
- year + 10 (assuming existing variable year)
- age === 18 (assuming existing variable age)
- age >= 18 (assuming existing variable age)
Computed values:
- 1 + 2 produces 3
- a + b produces the sum of a and b (assuming a and b are numbers)
- year + 10 produces a number which is the result of adding 10 to the variable year
- age === 18 produces a boolean (either true or false, depending on the age)
- age >= 18 also produces a boolean depending on the age
Javascript does some intermediary steps:
let year = 2000
console.log(year + 8)
There is a calculation of year + 8
implied in there
Summary
- An expression is a combination of one or more variables, functions, and operators that the programming language computes to produce a value.
- 5 + 4 is an example of an expression that produces a value of 9.
- counter >= 10 is an example of an expression that produces a boolean (either true or false), depending on the value of the variable counter.
- When there are expressions, JavaScript goes through some intermediary steps to compute the value from the expression.
- console.log(expression) is often mentioned in documentation, meaning that console.log expects to receive an expression.
- An expression produces a value and can be written wherever a value is expected.