Expression

An expression is a combination of values, variables, and operators that produces a result. An expression always evaluates to a single value.

Why expressions are important

Expressions are used to:

  • Perform calculations

  • Compare values
  • Create logical conditions
  • Generate results inside programs

Most lines of code contain expressions.

Simple examples

Arithmetic expression:

5 + 3

Result → 8

 

Using variables:

price * quantity

If price = 10 and quantity = 2, the expression evaluates to 20.

Boolean expression

An expression can also return true or false.

 

Example:

age >= 18

This expression evaluates to:

  • true if age is 18 or more
  • false otherwise

Boolean expressions are often used in conditions.

Expression vs Statement

  • Expression → produces a value
  • Statement → performs an action

Example:

5 + 3 ← expression score = 5 + 3 ← statement (assignment)

The expression creates the value.

The statement uses it.

Expressions inside functions

Expressions are often used with return values.

 

Example:

return a + b

Here, a + b is the expression.

Why learning expressions matters

Understanding expressions helps you:

  • Build calculations
  • Write conditions
  • Create dynamic logic
  • Understand how code produces results

Expressions are the core building blocks of programming.

Simple example

Think of an expression like a math formula. You combine numbers and symbols, and you get a result.

Related terms

Source

Simplified from general programming documentation and Wikipedia.

Nach oben scrollen