What are data types?

Before we go on and explore the different data types available in JavaScript, it's worthwhile to discuss what exactly is meant by a data type.

In simple terms,

A data type describes a set of values and the operations possible on those values.

Let's take an example to make intuition of this basic definition.

Consider the integer type — a very common data type in programming languages of all kinds of levels.

We all know that the possible values of integers in mathematics ranges from negative infinity (−∞−∞) all the way to positive infinity (+∞+∞), whereby each value is a whole number (i.e. a number without a fraction). The set could be expressed as ……, −2−2, −1−1, 00, 11, 22, …….

However, in the realms of machines, integers are finite. We can only have a limited range of them. Even if the underlying mechanism of storing integers changes so that we can store arbitrarily long integers, as in Python, we are still limited by the total amount of memory available on the machine for the largest possible integer. In short, there is finiteness to integers in computing.

If we say that the integer type, in a programming language, is unsigned and consumes 4 bytes of memory per value, then the range of values possible is 0 to 4294967295.

Apart from these values, the integer type also represents the possible operations that we can carry out on these values. Common operations include addition, subtraction, multiplication, division, exponentiation, and modulo.

To boil it down, a data type is an abstract idea that helps us group data according to its value and the whole set of operations possible on that data.

In some instances, a data type could represent just one single value without any operations possible to be performed on it. In others, it could represent an almost infinite (but obviously limited by the available memory) set of values with a large number of supported operations.

Now that the definition is clear, it's time to explore the idea of primitives and objects in JavaScript.

Last updated