Knowledge Organiser: Variables and Constants
Key Terms
- Variable: A named memory location that stores a value which can change during the program
- Constant: A named value that is set once and cannot be changed during the program
- Assignment: Giving a value to a variable using = (e.g. score = 10)
- Naming convention: Rules for how variable names should be formatted (camelCase, UPPER_CASE)
- Reserved word: A keyword the language uses (if, while, for) — cannot be used as a variable name
Must-Know Facts
- Variables can be reassigned; constants cannot change after being set
- Variable names are case sensitive: Score and score are different
- Names must start with a letter or underscore, not a number
- No spaces in variable names — use camelCase or snake_case instead
- Constants are often written in UPPER_CASE by convention (e.g. VAT_RATE)
- Constants prevent accidental changes and make code easier to update
Key Concepts
- Use variables for: scores, counters, user input — anything that changes
- Use constants for: PI, tax rates, fixed limits — things that never change
- Declare constant: const PI = 3.14159
- Good name example: playerScore (meaningful) not x (meaningless)
Common Mistakes
- Using meaningless variable names: Names like x, temp, or a are not acceptable in exam pseudocode — use meaningful names like playerScore or totalCost
- Trying to change a constant's value: Constants cannot be reassigned after being set — attempting to do so is a logic/runtime error and defeats the purpose of using a constant
- Starting a variable name with a number: Variable names must begin with a letter or underscore — 1score is invalid; score1 is valid
- Putting spaces in variable names: Spaces are not allowed — use camelCase (playerScore) or underscores (player_score) instead of spaces
- Using a reserved word as a variable name: Words like if, while, for, and print are reserved by the language and cannot be used as variable names