Basic Javascript — Variables.
Hi 👋
I have many years of experience as a programmer, but I have taken the task of relearning the basics of JavaScript to share my expertise and teach you in a very easy-to-understand way.
To begin with, let’s talk a little about what JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive, it is very popular, cross-platform, and simple to learn since its syntax is not strongly typed, which means that it is not necessary to declare the type of variables to be used because JavaScript is smart enough to detect what type of data we are using, it is not necessary to install anything to use it, since it runs in the browsers we use daily, such as Google Chrome, Edge, Firefox, etc.
Get DavidNazareno’s stories in your inbox
Join Medium for free to get updates from this writer.
Well, since we are talking a bit about JavaScript, let’s start by explaining what is a variable and its types.
A variable is a space in memory that is used to store data, in the case of programming and basic data it can be a text, number, etc.
Imagine a closet where you keep your clothes, well you have a space where you keep shirts, shoes, cold weather coats, etc.
That is a variable, they are like the spaces in your closet where you keep things.
Types of variables
To declare a variable it is necessary to assign a value, in JavaScript and many languages in general the = is used to assign.
var > In the early days of JavaScript, the Var instruction was used to declare variables.
var myNameVar = 0;var | is an instruction that is not so common to use anymore because it allowed users to declare variables with the same name and replace their value, these practices in code are not very good, so the current recommendation is not to use it.
var myNameVar = 0;
var myNameVar = 4;let | Through JavaScript was gaining fame, a new update was released to ECMAScript 6 where they added new features and among those added the new instruction let, this instruction allows you to create variables, but now with the goal of creating variables with unique names, which are not replaceable, allowing to have a more organized and more functional code, let was added as an alternative to var, which is recommended to use.
/*As it is not possible to declare two variables the same with the
let instruction, this would generate an error.*/
let myNameVar = 0;
let myNameVar = 4;
/*To solve this error, the variables have to have different names*/
let myNameVar2 = 4;
const | The const instruction allows you to declare variables as their name says constants, which means that they are immutable, that their value cannot change, it will remain forever with their initial value.
const myNameVar = 0;
/* If you try to assign a value to this constant
you will get an error, since it is an immutable value.*/I will continue to upload more content and study at the same time, I thank you for reading and hope you have learned something.








