What is a first-class citizen in computer science?
![What is a first-class citizen in computer science?](/_next/image?url=https%3A%2F%2Fpocketbase.douglasmoura.dev%2Fapi%2Ffiles%2Fquq9xznky3sx782%2Fkoteqnmlpuolhco%2Fformiga_UU9O0o3wKu.jpg&w=3840&q=75)
In computer science, a first-class citizen is an entity that supports all operations available to other entities. Some of the available operations are:
- They may be named by variables;
- They may be passed as arguments to procedures;
- They may be returned as the results of procedures;
- They may be included in data structures.
It was the British computer scientist Christopher Strachey (1916-1975) who first coined this notion of first-class citizen status of elements in a programming language in the 1960s.
In JavaScript, for example, functions are first-class citizens, as all of the operations cited above can be applied to them. Let's see some examples:
A simple function definition in JavaScript
Assigning a constant to a function
Passing a function as an argument
Return a function
Including a function in a data structure