JavaScript 101: data types
Tags: programming, javascript
Published: 2020-06-30 15:50:50

---
title: JavaScript 101: data types
published: true
date: 2020-06-30 15:49:41 UTC
tags: programming,javascript
canonical_url: 
---

In Javascript (or any programming language), a data type is the type of value a [variable](https://dev.to/nduduzo__/javascript-101-variables-22ig) holds, like a **_number_** or a **_string_** for example. There are generally seven data types in Javascript and I’ll “generally” explain all of them here, I must mention though, this will not be a tutorial on data types so if you want an in-depth definition of each data type with examples I recommend you check out [javascript.info](https://javascript.info/).

- **String**
- **Number**
- **Boolean**
- **Object**
- **Array**
- **Null**
- **Undefined**

**The String:** a string is surrounded/enclosed in quotes, there are three types of quotes used in Javascript.

```
const strng = 'this is a string'; //single quotes
const strng = "this is a string"; //double quotes
const strng = `this is a string`; //backticks
```

Javascript treats all the values above the same – they are all _strings_.

**The Number** : the number data type is pretty self-explanatory, its a **number**. Any value that is a number is a _number data type_, its important that the value is **NOT ENCLOSED IN QUOTES** for Javascript to recognize it as a _number data type_ otherwise it will be treated as a _string_.

```
const numb = 25; //this is a number data type
const num = "25" //not a number
```

**The Boolean:** _booleans_ are [logical types](https://dev.to/nduduzo__/the-first-thing-i-learned-in-javascript-1fn3-temp-slug-4242988) – they are values that can only be in one of two conditions: **true** or **false**. There’s massive use for this data type because just like you and I, applications need to make decisions based on given conditions.

```
const isAwake = true;
const isAsleep = false;
```

Again, its important that a _boolean_ is not enclosed in quotes otherwise Javascript treats it as a string.

**The Object:** all other types are called “primitive” because their values can contain only a single thing (be it a _string_ or a _number_ or whatever). In contrast, _objects_ are used to store collections of data and more complex entities, so objects kinda get special treatment.

```
const person = {
   name: "Allison",
   profession: "AI researcher",
   age: 29,
   isMale: false;
   isFemale: true;
   hobbies: ["photography", "piano", "filmmaking", "reading"]
}
```

Above is a simple _Object_ containing different data types defining a **person** , this could be a user on your website or something…

**The Array:** when you want to store lists or a list of data, normally you’d use an _Array._ With _Arrays_ you can manipulate the data inside, manually and automatically.

```
const arr = [1, 2, 3, 4, 5]; //an array of numbers
const arr = ["milk", "cereal", "eggs"]; //an array of strings
const arr = ["coffee", 12, "muffins", 45, 88]; //an array of number and string data types
```

Similar to _Objects_, _Arrays_ can contain multiple data types.

**The Null:** _null_ means nothing, its a value, a value of nothing (the way I like to think of _null_ is that it represents the value of nothingness).

```
const msg = null; //msg represents nothingness
```

Again, its important that _null_ is not enclosed in quotes otherwise Javascript treats it as a string.

**The Undefined:** this one is kinda tricky, usually Javascript will return **undefined** if you’re trying to output something that hasn’t been **defined**. But _Undefined_ itself is a data type in Javascript. You can assign _Undefined_ to a variable (for whatever reason) and it will return **undefined** always, unless updated.

```
const msg = undefined;
```

I hope I “generalized” these well enough without this blog being too long.

Alright cool