Identifiers
An Identifier is a unique name used to refer to a single entity within the programming environment. The easiest way to think of an identifier is that it is a natural language translation of an instruction to your computer. The instruction might be to fetch information, or to perform a complex series of instructions that would otherwise take up far more space than the identifier alone.
There are several entity types that can be referenced using an identifier, some of which we will discuss in more detail below.
- Variables are ‘containers’ designed to store a value that can be accessed and modified by computer code during the code’s execution. Each variable has a unique name that can be used to call it anywhere in an application.
- Constants are containers defined the same way as variables, although they differ from variables in that once the code defining them is compiled there is no way to modify their value.
- Functions (also known as procedures or subroutines) are self-contained instructions that perform specific tasks.
- Labels are used to mark sections of your source code. They are used primarily by programmers for debugging purposes, although some outdated programming methods (such as GOTO statements) utilise labels.
The example below contains most of these identifier types:
if( CurrentMonth = "January", Correct, Incorrect );
Let's break down this expression to look at what each part does:
- if is a function that checks another expression and then returns one of two values depending on the result. A semicolon is used after the function because semicolons are used to denote line-breaks in the expression engine.
- CurrentMonth is a variable that holds a value. In this example, this stored value is being compared against the literal string "January".
- Correct and Incorrect are both constants, which have been assigned a static value.
As such, this expression will return the value assigned to the Correct constant if the value of the CurrentMonth variable is "January"; otherwise, it will return the value assigned to Incorrect instead.
<< Previous: What is an Expression? | Next: Identifier Naming Convention >>