Bitzu

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

Single choice

In most programming languages, what is the index of the first element of an array?

  1. 0
  2. 1
  3. -1
  4. 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.

Select all that apply

Which statements about arrays are correct?

  1. They hold an ordered collection of items
  2. An item is reached by its index
  3. The first index is always 1
  4. Once created, the values can never be changed
  5. 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

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.

Download on the App StoreGet it on Google Play

More FC0-U71 topics in this module