Variables with Kitties and Memes
Tags: javascript, beginners, programming, tutorial
Published: 2022-11-09 17:15:22

Hello fellow programmers and welcome to variables (please pronounce with italiano accent)
In this short and butiful blog we'll discuss what they are, what they do, and why they do what they do.
_Everything I say is regarding JavaScript, so most probably it won't work for other programming languages_

**Let's start**
First of all, what are variables? 
The best desribtion would be to think of them as a box, in which I can put anything. And by anything I mean ANYTHING, starting with numbers and ending with "war and peace" (or a kitty)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9h6e1ilszhd80fxy4zt.jpg)

In order to put something in the above mentioned box, first we write the type of the variable, then the name of the variable and what it contains, if it does. We can declare and assign them. Declaring means creating them, assigning means giving them a value which they will hold untill I change it. Here is the format we use 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2bkiowbq32xcr9rw9yl.png)

As you can see we assigned a variable to a variable, by doing that the first variable will get the value of the second one. And we can print them to make sure everything is correct (to print anything we use "console.log()").

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpvhb1hw1mack7fnpifr.png)



There are three types of variables

1 . **Var**
 
Is used through the whole programm and can be changed or assigned.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lfzyumnjiavobn5b1ci7.png)

2 . **let**

Is used only within the scope of where its declared. Meaning unlike **var** it can't be used everywhere.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98upgluhfno1ka88mt8w.png)

3 . **const**



As you can guess from the name this one never changes

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gf85c7a5a4lw5rgjx0jl.png)



In our variables we can do basic math. Here are examples

1 . Addition

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utv2bv5f2m8bb4gaec76.png)

2 . Subtraction

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgklz4ezaa5iei51c5kr.png)

3 . Multiplication 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6qmml72dbzl49k458c4.png)

4 . Division

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oikxyneknq3t450kbuts.png)

5 . Remainder

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mu2mv07qehq8pjaaw200.png)


**Some things to keep in mind**

When naming a variable you can't use key terms (like var or function), and also they can't start with numbers, can't have space in them and most symbols won't work(only exception "_" and "$"). Therefore as much as I want to I can't name my variable 
"69 & 420" 



**Now, this part is unnecessary** if you only need varibles, but still pretty interesting and will be useful for the post about functions. 
Arrays!!! They are like next level variables, so I thought it wouldn't hurt to talk about them.
Variables are boxes, however they are very small boxes because they can store only one value at a time. Array is a biiig box, so it can store more than one thing at a time (few kitties instead of one)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohyrae8iw6gqvqtzvhy5.png)


To make an array, we first make a variable then after "=" we put square breckets []. And whatever we want to put in the array, we put inside of it and separate with a comma. Here are some example


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7lxncuas1oqziwr8oez.png)

As you can see, we can put strings and numbers here. However we can also put an array inside, so it will look like this 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npa9drauxal4xtiir2ol.png)

This is called a nested array or a multidimensional array.
Now let's see what we can do with them. First of all, each element of an array has its index, which is basically their number (note that computers start counting from 0 so the first element will have an index of 0). To show the index of an array write the array's name and put [] these next to it (ourArray[]). When we want to see a particular element we can use indexes to print them. To do that we must make a new variable and assign them to the index of the element we want

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4h36r5wcyw430twxorb3.png)

As you can see, first we wanted to print the first element, so we used the index 0. Then we wanted to print the second element of the inside array, so we used two brackets, the first one meaning the number of the outside array and the second one being the index of the element from the small array. 

**That's all for now <3
Senk yu**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gubuzb13k8ljrl5b7kb.png)