Comp 110 Compound Data Types

Compound Data Types

A compound data type is a data type that you can construct using TypeScript's built-in primitive data types. For a refresher on primitives (string, boolean, number), check out the simple data types page.

A compound data type can hold multiple independent values. The compound data types we will work with most this semester are lists, arrays and classes. The ability of the programmer to make use of the tools that TypeScript provides to create new abstractions and objects in code is super powerful - the sky is the limit in terms of the things you can create.

A real life example....

Let's think about the student ticket lottery for the UNC vs. Duke basketball game. Each student that enters the lottery has a unique name, PID and senior status. These three values can be represented by primitive data types. 

  • Name --- string
  • PID --- number
  • Senior status --- boolean

However, each of these values are associated with a single student and they should be kept together. This is where a compound data type would come into play. For example, a Student data type could be constructed that would be made up of a string, number and boolean. The construction of compound data types is extremely beneficial in organizing related data in your programs. We will get lots of practice with this later on in the semester!