Expressions

The building blocks of programming

In natural language

We start from words

Then we combine …

words to make phrases

phrases to make sentences

sentences to make paragraphs

paragraphs to make essays and books

In programming languages

We start with basic values

Numbers, booleans, strings, and others.

And operators

+, -, *, /, %, &&, [], etc.

Names can also be used as expressions

let students = 29

students ⟹ 29

And a few other things

We’ll discuss those as they come up

Then we combine …

values to make expressions

expressions to make functions

functions to make libraries

libraries to make programs

Literal expressions

2 * 10

Abstract expressions

a * 10

We don’t know exactly what value this expression will produce

But we know what type of value it will be: a number.

In programming languages

We frequently combine expressions to make more complex expressions

grade1 + grade2

(grade1 + grade2) / totalPoints

100 * (grade1 + grade2) / totalPoints

Get comfortable with expressions

Be able to …

Translate from English to expressions

Understand the “meaning” of expressions in code

Identify the type of value an expression produces

Up next

Variables