Expression

noun

say it: “ek-SPRESH-un” /ɪkˈsprɛʃən/

A piece of code that works out to a value, such as price * 2 or name.upper(); statements are built from expressions.

What is an expression?

An expression is a small piece of code that produces a value. But without another expression the result is usually meaningless. You generally combine multiple expressions to create a statement.

// examples of 3 different expressions
13 + 4 * 2 - 7

// expressions are evaluated in this order
4 * 2  // first
13 + 8 // second
21 - 7 // third

// this statement performs the arithmetic
// and stores the value
let calculation = 13 + 4 * 2 - 7

In a sentence

  • “The expression 3 + 4 * 2 works out to 11.”
  • “Inside an f-string's braces you can put any expression, such as {price * qty}.”

Level: Novice · More General terms at this level

Updated