Lesson Summary
In this lesson, you were introduced to the concept of an expression. Expressions can vary in complexity depending on what they are used for, from something as simple as “2 + 2” to an expression requiring pages of code and hundreds of smaller parts.
Expressions are constructed using three basic units, namely identifiers, operators and literals:
- Identifiers are names given to expression objects such as variables, constants and functions. They allow you to reference other pieces of code, so rather than having to re-type something every time you need it, you can use an identifier to point to it instead. This has the added advantage of letting you change the information referred to by the identifier once, rather than update every instance of it in the document. Identifiers are subject to naming conventions, which limit the characters that can be used in their name, and prevent them being given the name of an existing operator or built-in identifier.
- Operators are symbols and words used to perform arithmetic, logical or conditional operations on other parts of code. Operators require either one or two operands, depending on their purpose; these operands can be any type of programming object as long as they evaluate to a valid data type.
- Literals are ‘as is’ code which represent literal values, such as numbers, text strings, or the Boolean values True and False. Literals are most commonly used to assign value to an object, or test an object’s value.
<< Previous: Literals | Next: Test Your Knowledge! >>