Posted on

Types of types in coding

In the world of coding, types define a scope around what can be used to express a value.

If this first line already confused you, I have done well.

What is a Type? 

Type’s can be numbers, words, objects, arrays, floats, etc.

But what does that mean?

It means a computer application limits what can be stored and referenced in the future by other parts of the application. Differing languages such as JavaScript, Python, C, PHP allow for either strict typing or loose typing.

So what is Strict Types vs Loose Types

Strict Types is when a variable must be a certain type. E.g. ‘18’ is not the same as 18. In JavaScript for example, if you put talking marks around a value, you are expressing it as a String. But in the reverse, if you want to explicitly state that it is a number, you would write 18. Which would make it an integer.

Here are a list of the most commonly used Types in JavaScript;

  • String

This type is used for everything from words, sentences and paragraphs. Basically anything that probably isn’t being used to mathematically be calculated.

  • Int

Numbers are stored in Integers. These can be used to calculate equations such as addition, subtraction, division, multiplication, etc.

  • Arrays

Arrays are used to store a list of values that are grouped together. This is handy for when you need to iterate (go through systematically) the list to display it.

  • Float

Floats are used to store values that require more precision. Integers do not reflect after the decimal points. So Floats are required to be used when working with numbers that are smaller than 1. E.g. 0.314345345345

But why?

Computers have limited memory, be it storage or RAM. By defining types you are permitting the application to only consume an upper limit of memory for that particular variable that you have declared.

In the future, I will discuss a language called TypeScript which enforces strict Types in the development stage to limit issues before they happen in the user’s browser.