Comp 110 Expressions and Operators

What is an expression?

  • Expressions always simplify to a single value (only when the line of code is executed)
  • Every expression has a single result type

Examples of expressions

Where do we use expressions?

With an assignment operator!

let <name>: <type> = <expression of same type>;

Singular vs Compound Expressions

Singular Expressions

  • Literal values
    • 1, 3.14, true, "hello!"
  • Variable Access
    • x, myName, courseNumber
  • "unary" operators (-)
    • -x (negation)

Compound Expressions -> utilize operators (listed below) and function calls

Operators

  • Arithmetic
    • +
    • -
    • *
    • /
  • Concatenation
  • Equality
    • ===
    • !==
  • Relational
    • >
    • <
    • >=
    • <=

Also - see the page on conditional operators for more information!