JavaScript Struggles - Part 5 | Data Types
Tags: javascript, webdev, beginners, tutorial
Published: 2022-06-29 10:11:51

**Hey there! 👋🏻**
We're now going to explain the data types of JavaScript, I'm only going to talk this time about the data types itself, ⚠️ <u>I'm not going to explain the (truthy & false) subject now</u> ⚠️.

**This's just a basic view of the data types of <mark>JavaScript</mark>.**

---

### Data types:-
- [Undefined](#undefined)
- [Null](#null)
- [Number](#number)
- [String](#string)
- [NaN](#nan)

---

## Undefined <a name="#undefined"></a>

`Undefined` is actually a **data type** in <mark>JavaScript</mark>.
Even though that is weird, but you'll get used to it.

it's the **<u>default</u>** data type if you didn't assign anything in the variable.

```js
var varName; 

console.log(typeof varName); // outputs: undefined
```

---

## Null <a name="#null"></a>

Null is a data type that have to be assigned.
The best use of it is to find the [`undefined`](#undefined) variables.

> Also important to know that null is an `object` so whenever you want to check the data type of a variable that contains a `null` it'll return "object".

```js
var nullVariable = null;
var nothingHere;

console.log(nullVariable == nothingHere); // that will output true
```

But the confusing sometimes, but no worries I covered it already on a [previous post](https://dev.to/abdelrahman_dwedar/javascript-struggles-part-2-numbers-4f2l#null)   

--- 

## Number <a name="#number"></a>

The data type `number` is so familiar for most developers, it have a number. :)

Simple right?

But sometimes JavaScript has to be JAVASCRIPT, and add some weird things around it.
It's considered **bad at math**, or to be more specific; it's actually <u>bad at float-point</u>

**Which I'll cover in upcoming post, so <mark>stay tuned<mark>.**

---

## String <a name="#string"></a>

`String` is actually so simple.

It's just like the string of any other language but with some features.

There's 3 ways of using string in JavaScript:
- Single quote [`'string'`](#single)
- Double quote [`"string"`](#double)
- And the [backticks](#backticks)

### Single quote `'string'` <a name="#single"></a>

The single quotes is used just as the normal string.

```js
let stringVar = 'Hello world!';
```

### Double quote `"string"` <a name="#double"></a>

This is the normal string itself!! 
I think it doesn't need an explanation.

### Backticks <a name="#brackticks"></a>

What is even backticks?
It's the string that uses \` instead of " or '

It's actually the best practice in my opinion <u>for <mark>JavaScript</mark></u> at it provides the furmated string feature with it as you use it, also enables using multiple lines (it doesn't apply on web as you need to use `<br />`).

~~~js
let furmattedString = `the answer is ${5 + 5}`;

console.log(furmattedString); // the answer is 10

let multilineString = `Hello there!
I'm Abdelrahman!`;
console.log(multilineString);
/*
Hello there!
I'm Abdelrahman!
*/

~~~


---

## NaN <a name="#nan"></a>

I've already explained `NaN` in [previous post](https://dev.to/abdelrahman_dwedar/javascript-struggles-part-2-numbers-4f2l#nan) 
So let me be the lazy developer I am and not repeat that again :yawning_face:

---

<p align="center"><b><u>That's all for now! I hope you gain anything new from this post. :smile:</u></b></p>