• ELI5
  • Programming
  • Primitive types

ELI5 - Primitive data types in programming

Explain to me Like I'm 5 years old - Primitive data types in programming.

Last updated May 24, 2021

Article

Introduction

New ELI5 series

Welcome to this first post of the new ELI5 series where I'm teaching myself various topics centered around coding and development in general and then explaining them to you in the most simple way for you to understand.

The Pretender

"Keep you in the dark, you know they all pretend".

I certainly was one of those people and I was embarrassed by it.

Primitive data types were the kind of simple programming concepts I did not learn in school and couldn't be bothered to look into until I stumbled over that particular term over and over when learning more advanced stuff like front-end frameworks.

There is no shame in not knowing everything but you can't keep procrastinating and pretending like you know when you do not.

What are primitive data types?

First, primitive data types are not data types that have not been properly civilized which would not make any sense anyway.

Fundamental building blocks

Primitive data types or primitive types as they are often called, are the basic building blocks of all programming languages. You could see them as simple bricks. A brick in itself is not of much use unless you are a rioter. But by assembling a multitude of those simple bricks, you can build a wall, which is still very basic but already much more useful than a single brick. You could then go on and build multiple walls and connect them together to eventually build a house which we humans have been doing for thousands of years.

That is exactly what we are doing as developers/programmers/engineers when we write code and manipulate data to get something useful out of it.

What characterizes primitive data types

Primitive data types are built-in types provided by a programming language, such as PHP and JavaScript as their basic building blocks as previously explained. They:

  • Are provided by the programming language
  • Have built-in support
  • Hold simple values like characters and numerics although some objects compositing primitive values can also be considered primitives themselves
  • Are the fastest language constructs
  • In most languages, they cannot be extended

Primitive types in PHP

Although PHP is a weakly typed language, it still uses types behind the scenes, even if you're not actively typing your variables.

Primitive data types in PHP include:

  • Strings (string) like "C" and "I love PHP"
  • Booleans (bool) like true and false
  • Integers (int) like 0, 1, 999, -1 etc...
  • Floating-point numbers (float) like 19.95 and 10.00

Those first four are in a subdivision called scalar types.

The next subdivision is called compound types:

  • Arrays ([]) like ["Elon", "Jordan", "Tanya"] and [1, 2, 3, -1, 999]
  • Objects ({}) like { first_name: "Elon", last_name: "Musk", hobby: "Trolling Twitter" }
  • Callable
  • Iterable

The last two I will not explain as they would require an entire article to do so, but I provided you with a link to the PHP documentation if you're interested.

Primitive types in JavaScript

JavaScript is also a weakly typed language like PHP.

Primitive data types in JavaScript include:

  • Strings (String) like "C" and "Why isn't this TypeScript?"
  • Numbers (Number) like 0, 1, -1, 999 but also 19.95 and -10.00
  • Booleans (Boolean) like true and false
  • Big Integers (BigInt) like 9007199254740991 and 0x1fffffffffffff which is a special notation
  • Symbols

The last one is a bit peculiar, so I provided you a link to the documentation if you're interested in it.

Closing word

That's the end of this short article and I hope you could learn something. There is of course much more to learn about primitive data types, of course, depending on the languages you use but that's the gist of it.

Resources


Author

Célien Boillat

Full stack web developer