Javascript Data Types - The Beginners Guide To Javascript(Part 1)
Tags: javascript, beginners, tutorial, programming
Published: 2022-04-23 02:14:27

## Intro To Javascript

_"Any application that can be written in Javascript, will eventually be written in Javascript"_ - Atwood's Law

Javascript's rise in popularity and the flexibility to create mobile, web, desktop, front-end, and back-end applications has made it one of the most popular programming languages in recent years. Paired with its loosely-typed syntax makes it an easy language for beginners to learn.

If you didn't understand anything above, don't stress, understanding the lingo is only one part of becoming a Software Engineer, and you will pick it up over time. I'm glad you are here and taking the first steps of learning a programming language. Enough small talk let's get right into it!

## Variables

Variables are a critical part of every application. Variables allow us to store/hold and reuse data throughout our applications. This data is stored in a "slot" in your computer's memory(RAM). The variable is a reference to this point/slot in memory. Javascript currently has three ways of declaring a variable. `var`, `const`, and `let`

```javascript
const name = "Cameron";
let age = 25;
var status = "Codding...🧑🏼‍💻";
```

The main difference between `var` and `const | let` is scope. Scope is an important concept to understand but can be hard to grasp. Not to worry, we will cover scope in the future.

The difference between `let` and `const` is that `let` _lets_ you reassign the data that variable points to in memory. With `const` the data can only be assigned once.

```javascript
const name = "Cameron";
let age = 24;

age = 25; // OK ✅
name = "David"; // ERROR ❌
```

When naming a variable in Javascript its convention to use lowerCamelCase. Variables cannot start with a number but can contain numbers.

Variables are also case-sensitive.

```javascript
const carEngineRunning = true

const car3 = "Subaru WRX" // OK ✅
const 3rdCar = "Subaru WRX" // ERROR ❌
```

So when do I use `const`, `let`, or `var`?

_"`const` until you can't"_ - Cameron's Law of Const

You have seen three different types of data stored in variables, including _Booleans_, _Strings_, and _Numbers_. Javascript has 7 _Primitive Data Types_(Booleans, Null, Undefined, Numbers, BigInt, Strings, and Symbols) and _Objects_. Let's get into the meat and potatoes and take a look at each of these Data Types.

## Primitive Types

### Boolean Type

`Booleans` can have two values `true` or `false`

```javascript
const isOnline = true;
const hasUnreadMessages = false;
```

### Null Type

`Null` has only one value `null` we use `null` to specify that a variable has no "real" value.

```javascript
const goldCoins = null;
```

### Undefined Type

`Undefined` is assigned to variables that have never been assigned.

```javascript
let gasPoint;

console.log(gasPoint); // undefined
```

### Numeric Types

Unlike other programming languages, Javascript doesn't differentiate between integers(1, 15, 24) and floating-point/decimals(3.14, 1.23, 0.99), and all of the examples are considered Numeric Types

```javascript
const age = 24;
const balance = 1204.32;
```

### BigInt Types

A BigInt value can hold a massive integer value but it is not commonly needed or used. we will not cover it here now, but it's good to know it exists.

### String Types

A string is textual data and is normally wrapped in single or double quotes.

```javascript
const name = "Cameron";
```

### Symbol Types

Symbol types are unique and immutable(can not be changed) values that may be used as the key of an Object property. Their use is rare in general Javascript programming.

## Objects

Most programming languages have different Types that hold/store more complex data structures. Javascript only has one, _Objects_.

Objects are collections of zero or more key:value pairs known as properties. We will cover _Objects_ in-depth in the future. With that said, here is how we may represent a user/person as an _Object_.

```Javascript
const user = {
    firstName: "David",
    lastName: "Green",
    age: 27,
    favColor: null,
    savingsBalance: 23576.92
}
```

Wow, that was a lot of information, and we have learned a lot.

- We learned a little about Computer Science and how applications store data in our computer's memory.
- We talked about why variables are so important.
- We touched on each of the different Data Types in the Javascript langue.

Don't be afraid to re-read this blog post if needed. This is the beginning of a blog post series and, we will be covering the Javascript language in-depth.