Welcome to my Website v2!


Variables

Have you ever been confused when learning something new? You hear a term and learn what it is only for another practitioner to call it something else and explain it differently; Just enough to make it confusing. As an beginner-intermediate programmer, I know how to make a program do what I need it to by talking to it in it’s language. While this post is meant for all curiously on my site, it’s targeted towards all programmers of all knowledge levels. It is my hope that I can clear up some confusion for the beginners and learn from any experts that may be perusing this blog. Without further ado, lets dive into terminology!

Var

What is a variable? In mathematics, you could define it as “a quantity that may assume any of a set of values.” In programming, this definition works somewhat the same thing. I like to think of variables as containers with a descriptive name of what they contain. Back to mathematics, look at this problem, x + 1 = 10; What is x? In math we’d solve for x whereas in programming, we create a variable called “x” and set it to a value. Let’s start with the classic variable var.


        var x = 9; // x stores a number with a value of 9
        Console.log(x + 1); // if the variable x is 9 and programming smiles on us, we should see 10 in the console log.
        //Console.log shows in the console in the developer tools in chrome (press F12, then select the console tab)

This variable, var, is a global variable meaning that it can be used anywhere but also that it can redeclared as something else later. In the first part, we gave x a value of 9. With it being var, we can change it to whatever we’d like if we wanted to use the variable x. By using the keyword var again, lets change the value of x to 19.


    var x = 9;
    Console.log(x + 1); //this will write 10 in the console
    
    var x = 19;
    Console.log(x + 1); //this same code will write 20 because we redefined the x variable

That’s a light touch on the var keyword and as of 2015, is no longer best practice to use. With ES6 or the 6th edition of Javascript, var while still being used has been replaced for the more favorable const and let keywords. On the surface, these perform the same operations that var does however const cannot be redeclared like we did earlier. The let keyword follows the same operation as var but isn’t global.

more to come during this journey!