Introduction

A collection groups related values in a particular order. Indexes start at zero in these languages. Check whether a collection is empty before accessing its first value, and avoid changing its length while iterating unless you intend to.

Syntax & example

const foods = ["pasta", "rice", "soup"];
console.log(foods.at(-1));

Expected output

soup

Common mistakes

  • Using a variable before assigning a value to it.
  • Mixing text and numbers without converting deliberately.
  • Skipping an empty input or a boundary value when testing.

Practice

Create a collection of three favorite foods and display the last one.

13px
main.jsYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-82 lines