What is a first-class citizen in computer science?
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