FC0-U71 ยท Software development concepts
Variables, constants and arrays
Storing values that change or stay fixed, and holding ordered collections in arrays with indexes.
Key points
- A variable is a named storage location whose value can change while the program runs (score = score + 1).
- A constant is a named value that is set once and must not change (TAX_RATE = 0.23).
- An array is an ordered collection of items accessed by an index, and in most languages the first index is 0, so a 5-item array ends at index 4.
Source: https://docs.python.org/3/tutorial/introduction.html
Practice questions
In most programming languages, what is the index of the first element of an array?
- 0
- 1
- -1
- It depends on the data type
Show answer
Answer: A. 0
Array indexes normally start at 0, so the first item is at position 0.
Which statements about arrays are correct?
- They hold an ordered collection of items
- An item is reached by its index
- The first index is always 1
- Once created, the values can never be changed
- Each item needs its own separate variable name
Show answer
Answer: A. They hold an ordered collection of items, B. An item is reached by its index
An array stores items in order and you read one by its index. Indexes usually start at 0, items can be updated, and one name covers the whole collection.
True or false: in JavaScript, declaring an array with const means its items can never be changed.
Show answer
Answer: False
False. const prevents reassigning the variable to something else, but the contents of the array can still be changed.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
