Data Types

Christine_Yang's avatar
Published Feb 16, 2022Updated Apr 22, 2023
Contribute to Docs

Data is foundational in programming and is classified into different types to indicate how it can be interpreted, compiled, and used in software. For the most part, data types are categorized into two groups: primitive or composite values.

Primitive Data Types

Primitive data types are the building blocks for any variable or data structure in a program. They usually contain a single value such as a character, byte, or digit. A few examples of primitive types are listed below:

Data Type Description
Number Includes -1, 0, 1, and 3.14(numbers with decimals treated as a separate type in some languages).
String Sequences of characters surrounded by single quotes (''), double quotes (""), and/or backticks (``), depending on the language (e.g. "Codecademy is awesome! 🖥️⌨️" ).
Boolean Holds a logical value of true or false.

Composite Data Types

Composite data types can be composed of multiple of the same or different primitive data types, sometimes referred to as members, elements, or items. The following are examples of well known composite types:

Data Type Description
Array Collections of values that are usually defined with [] brackets and referenced by index starting at 0.
Object Groups of related data that are usually organized as property-value pairs.
Class Templates for objects that may contain properties or methods.

Other Common Data Types

Data types have gone beyond just composites and primitives and include ones with unique qualities such as the following:

Data Type Description
Null null or nil represents the absence of a value.
Undefined Represents a value that has not yet been defined.
Function Depending on the language, functions can be utilized as variables and arguments for other functions.
Void Sets a function to have side effects but return no specific result. Common in C-based languages.
Complex Number Type representation for complex numbers, sometimes with i or complex.

Data Types in Different Languages

The way that data types look and work may vary from one programming language to another:

Data Types

Boolean
Represents the logical values of true and false.
Number
Represents many numeric values.
String
Stores a sequence of indexed characters that can be of any length and is contained within a pair of single or double quotes.
Void
Denotes functions that have side effects but do not return an actual result.

All contributors

Contribute to Docs

Learn more on Codecademy