<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Damilola Alloh</title>
    <description>The latest articles on Forem by Damilola Alloh (@damilolaweb).</description>
    <link>https://forem.com/damilolaweb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F971793%2F77061d23-e37b-444a-9991-2d7cdc2cff7d.jpg</url>
      <title>Forem: Damilola Alloh</title>
      <link>https://forem.com/damilolaweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/damilolaweb"/>
    <language>en</language>
    <item>
      <title>JavaScript : Variables and Constants (A beginner's Perspective)</title>
      <dc:creator>Damilola Alloh</dc:creator>
      <pubDate>Thu, 01 Dec 2022 19:37:47 +0000</pubDate>
      <link>https://forem.com/damilolaweb/javascript-variables-and-constants-a-beginners-perspective-12i7</link>
      <guid>https://forem.com/damilolaweb/javascript-variables-and-constants-a-beginners-perspective-12i7</guid>
      <description>&lt;p&gt;In this article, I've attempted to do a complete breakdown on the concepts of variables and constants as I've learned about them. I hope it helps!&lt;/p&gt;

&lt;p&gt;Quick Disclaimer! I am also a beginner trying to navigate my way through programming and writing on the knowledge I gain is my way of learning. So bear with me if I'm not completely accurate or clear.&lt;/p&gt;




&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Variables&lt;/strong&gt; are like containers for storing values. They are very important in how easily information is stored and passed in our program as we'll find out in progression.&lt;/p&gt;

&lt;h2&gt;
  
  
  Declaring Variable
&lt;/h2&gt;

&lt;p&gt;Keywords: Variables are &lt;em&gt;declared&lt;/em&gt; using three keywords in javascript. &lt;em&gt;Declaring&lt;/em&gt; is you giving JavaScript an order to create a variable. These keywords include &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;. &lt;br&gt;
An example,&lt;br&gt;
First declare a variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you assign(store) a value to it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can refactor your code which is declaring a variable and assigning a value to it in the same line of code. This is called &lt;strong&gt;Explicit initialization&lt;/strong&gt;. This is the only way to declare &lt;code&gt;const&lt;/code&gt; variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Redeclaration
&lt;/h2&gt;

&lt;p&gt;Although it only applies to the &lt;code&gt;var&lt;/code&gt; keyword, you can redeclare variable using the &lt;code&gt;var&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;your name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reassignment
&lt;/h2&gt;

&lt;p&gt;You can change the value assigned to your variable by assigning a new value to the variable. It applies to &lt;code&gt;var&lt;/code&gt;and &lt;code&gt;let&lt;/code&gt; keywords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You cannot reassign a new value to a constant variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;My Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//Uncaught TypeError: Assignment to constant variable.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there is a little twist to this rule, so when constant variables are assigned to object data types(i.e name:value pairs), the variable assignment(values) are &lt;em&gt;references&lt;/em&gt; containing the object values. Let's take a look at this illustration for clearer understanding&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objectName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;{ a : 5}&lt;/code&gt; - The curly braces represents the whole object as a reference to the variable &lt;code&gt;objectName&lt;/code&gt;. Now,the reference can  cannot be changed in respect to the variable but the object value  can be changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objectName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//Attempting to reassign a new value to the variable reference&lt;/span&gt;
&lt;span class="nx"&gt;objectName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;//Uncaught TypeError: Assignment to constant variable.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we can reassign a new value to the object reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;objectName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objectName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// { a : 3}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scopes
&lt;/h2&gt;

&lt;p&gt;This process of declaring variables using the &lt;code&gt;var&lt;/code&gt; keyword also works with the &lt;code&gt;let&lt;/code&gt; keyword. But it is recommended to use  &lt;code&gt;let&lt;/code&gt; rather than &lt;code&gt;var&lt;/code&gt; because &lt;code&gt;let&lt;/code&gt; allows you declare variables that are limited to a &lt;strong&gt;Block scope&lt;/strong&gt;, unlike &lt;code&gt;var&lt;/code&gt; which declares a variable globally to an entire function, regardless of the block scope. &lt;/p&gt;

&lt;p&gt;For better understanding, let's get a clear picture of what these scopes mean.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt; tells us which variable is accessible and unto what point it is accessible. We can identify scopes by curly braces &lt;code&gt;{}&lt;/code&gt;. Let's look at the different scopes we have in javascript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Scope&lt;/strong&gt;: This is your entire javascript code file and all other scopes, functions and variables are contained in the global scopes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Local Scope&lt;/strong&gt;: These are variables declared in the functions and are further classed into &lt;strong&gt;function scopes&lt;/strong&gt; and &lt;strong&gt;block scopes&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Function Scope&lt;/strong&gt;: These are variables declared inside a function and they can only be accessed within the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Block scope&lt;/strong&gt;:These variables are only accessible within the particular loop or conditional statements they are declared in.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To illustrate these concepts, let's create the following program&lt;br&gt;
(&lt;code&gt;const&lt;/code&gt;variables are equally block-scoped, so we'll be using only &lt;code&gt;var&lt;/code&gt;and &lt;code&gt;let&lt;/code&gt; keywords for easier understanding):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nc"&gt;If &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//2&lt;/span&gt;
         &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both declarations are executed because they are within a block scope. Now let's see what happens when we declare a variable within a block scope and print outside the block scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Uncaught ReferenceError: b is not defined&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see that the variable declared with the &lt;code&gt;let&lt;/code&gt; keyword is not recognised outside the block scope of the &lt;code&gt;if&lt;/code&gt; statement. &lt;code&gt;var&lt;/code&gt; functions regardless of what scope it has been declared in. Let's take a look at how this can be a disadvantage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// very important variable&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result we get here is &lt;code&gt;b -&amp;gt; b&lt;/code&gt; because that is the value of &lt;code&gt;b&lt;/code&gt; in the function scope (the variable &lt;code&gt;b&lt;/code&gt; in the block scope has been terminated within the scope).&lt;/p&gt;

&lt;p&gt;we get &lt;code&gt;a -&amp;gt; 1&lt;/code&gt; being our output for &lt;code&gt;var&lt;/code&gt; keyword because &lt;code&gt;var&lt;/code&gt; is not dependent on the scope it is declared in and therefore it will override an existing variable(our important variable) and print out the most recent variable declared using &lt;code&gt;var&lt;/code&gt; keyword. This can cause bugs in our code hence, it is safer to use the &lt;code&gt;let&lt;/code&gt; keyword which is terminated within it's scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hoisting
&lt;/h2&gt;

&lt;p&gt;Hoisting is a concept where variables and function declarations are moved to the top of their scope before the execution of the code. while &lt;code&gt;var&lt;/code&gt; can be hoisted to the top before declaration, &lt;code&gt;let&lt;/code&gt;and &lt;code&gt;const&lt;/code&gt;cannot because only the &lt;code&gt;var&lt;/code&gt;keyword is initialized as &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Quick summary
&lt;/h2&gt;

&lt;p&gt;Incase the differences weren't clear enough, here's a summary&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; both can be declared without initializing while &lt;code&gt;const&lt;/code&gt; must be declared and assigned a value on the same line of code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; variables can be reassigned to new values while you cannot reassign new references for &lt;code&gt;const&lt;/code&gt; variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; can be redeclared while both &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; cannot be redeclared.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are block-scoped while &lt;code&gt;var&lt;/code&gt; is global-scoped and function-scoped when declared in a function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; can be hoisted to the top of the code block, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; cannot.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can check out these resources for further and  in-depth understanding of these concepts.&lt;br&gt;
&lt;a href="https://medium.com/nerd-for-tech/function-scope-block-scope-in-js-d29c8e7cd216" rel="noopener noreferrer"&gt;https://medium.com/nerd-for-tech/function-scope-block-scope-in-js-d29c8e7cd216&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=FNh2JCiFXIg" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=FNh2JCiFXIg&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you so much for reading❤. Comments, questions and contributions are welcome.&lt;/p&gt;

&lt;p&gt;I hope this article breaks down the concepts of defining variables in a clear, concise manner. &lt;br&gt;
Also, please I need help with embedding resources! Please somebody, help!🤧&lt;/p&gt;

</description>
      <category>career</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>How the Internet Works</title>
      <dc:creator>Damilola Alloh</dc:creator>
      <pubDate>Sat, 19 Nov 2022 20:45:02 +0000</pubDate>
      <link>https://forem.com/damilolaweb/how-the-internet-works-4jlg</link>
      <guid>https://forem.com/damilolaweb/how-the-internet-works-4jlg</guid>
      <description>&lt;p&gt;One general mistake we make as beginners is not understanding how the web works. How the codes we create get transformed into websites that can be displayed on any device from anywhere in the world. &lt;br&gt;
It is quite tricky to want to skip this part in our learning process but in the long run, it becomes quite useful to have some basic knowledge on how the internet works. &lt;/p&gt;




&lt;p&gt;The internet system is made up of two components. The hardware and the protocols.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Hardware&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The hardware includes everything that carry information from cables that carry heavy bits of information to your personal devices. These components together create what is called a &lt;em&gt;network of networks&lt;/em&gt;.This network is further divided to the &lt;strong&gt;clients&lt;/strong&gt; and the &lt;strong&gt;servers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xUCiAC3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di6v4n0gn896l6njegme.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xUCiAC3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di6v4n0gn896l6njegme.png" alt="Server-to-client" width="300" height="197"&gt;&lt;/a&gt;source:wikipedia&lt;/p&gt;

&lt;p&gt;The clients are the devices(could be from phones, laptops, PCs, and browsers) which we use in sending requests for information from the servers which store up huge chunks of information. These servers provide the response(information) we receive in our devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Protocols&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The hardware cannot send and receive information without the &lt;strong&gt;protocols&lt;/strong&gt;. These protocols are the sets of rules guiding how information moves on the internet. The most important ones being the &lt;strong&gt;Internet Protocol(IP)/Transfer Control Protocol(TCP)&lt;/strong&gt;.  The IP provides a common language for machines and devices to understand the passed request/information using IP addresses. We also have the &lt;strong&gt;Hypertext Transfer protocol(HTTP)&lt;/strong&gt; which is the set of rules responsible for transferring files such as HTML and multimedia resources over the internet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4O01kLnS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p387ipey2ei81qlcek6k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4O01kLnS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p387ipey2ei81qlcek6k.png" alt="An IP Address" width="258" height="196"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;IP Address&lt;/strong&gt; - These are a set of numbers with which machines use in communicating with one another within the massive amount of devices in the internet space. Every device connected to the internet has a unique IP Address.&lt;/p&gt;

&lt;p&gt;Now let's get into how all these come together.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Web Flow&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0MXeHVFA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aaaf8cwjhy3vgo9iubt1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0MXeHVFA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aaaf8cwjhy3vgo9iubt1.png" alt="Image description" width="880" height="440"&gt;&lt;/a&gt;Image source: Geeks4Geeks&lt;br&gt;
When we send a request(HTTP request) through our device browsers( the client) (an example is typing in a url such as &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt; in our web browser), the request goes over the &lt;strong&gt;Domain Name System(DNS) server&lt;/strong&gt; which is responsible for looking to see if  there is a server that matches your request i.e &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt; server. Once the requested server is found, the DNS server converts that request to an IP address so that the server can understand the request. &lt;/p&gt;

&lt;p&gt;If the server approves your request, it sends a "200 OK" message to the client(your device) and then the server sends the HTTP response in sets of &lt;strong&gt;packets&lt;/strong&gt;.&lt;br&gt;
If the DNS server does not find the requested server, it sends an "Error 404" message to the client computer.&lt;/p&gt;

&lt;p&gt;These packets are pieces of the HTTP response webpage which the server sends to the client. These packets contain &lt;u&gt;headers&lt;/u&gt; and &lt;u&gt;footers&lt;/u&gt; that tell your device what is in the packet and the packets are arranged to show you the requested webpage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transfer control protocol(TCP)&lt;/strong&gt; sorts out how these packets are transferred between one IP address(server) and another(client). It also controls how the packets are rearranged on the client's device.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;So how does your device know which DNS server to use?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When you connect your device to your home network or &lt;strong&gt;Internet Service Provider&lt;/strong&gt;, you have a router which determines your computer's IP address. It also adds some network configuration Information which also Includes some DNS servers for translating the requests to IP addresses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And there you have it! A basic rundown of how the web works.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And I'm hoping it is as simplified enough for your understanding&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Thanks for Sticking!✨&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I'm hopeful you've gained something reading this article and I value your time reading it. &lt;br&gt;
Thank you so much for reading❤&lt;/p&gt;

&lt;p&gt;_Every comment, corrections and discussion are welcome!😊&lt;br&gt;
_ See you soon. Byeee❤&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>writing</category>
    </item>
    <item>
      <title>JavaScript: The Beginning (A Beginner's perspective)</title>
      <dc:creator>Damilola Alloh</dc:creator>
      <pubDate>Wed, 16 Nov 2022 19:55:20 +0000</pubDate>
      <link>https://forem.com/damilolaweb/javascript-the-beginning-a-beginners-perspective-58mp</link>
      <guid>https://forem.com/damilolaweb/javascript-the-beginning-a-beginners-perspective-58mp</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Every great developer you know got there by solving problems they were unqualified for until they actually did it - &lt;em&gt;Patrick Mackenzie&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As beginners, it is important to build our knowledge from the roots in order to have a solid foundation. &lt;br&gt;
I have decided to document my JavaScript journey on this space to get closer with other newbies and also have inputs from the more seasoned developers. &lt;/p&gt;

&lt;p&gt;In this introductory article, we will discuss the the creation of JavaScript, the process of development through the years and where it is today.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Beginning&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript is the programming language of the web and it's origin dates back to 1995 when the internet was becoming quite popular and webpages were looking too static and boring and needed fluidity and dynamics. Netscape's(now known as Moxilla) founder, Marc Andreessen asked &lt;a href="https://en.wikipedia.org/wiki/Brendan_Eich" rel="noopener noreferrer"&gt;Brendan Eich&lt;/a&gt; to come up with a solution to the lack of dynamics on the web browser. In 10 days🤯, Brendan Eich developed JavaScript which was at the time, known as 'Mocha'. &lt;/p&gt;

&lt;p&gt;'Mocha' was originally intended to be a lesser complex language for the more informal programmers and designers to create and automate interactions on the web browser and also make websites more dynamic.&lt;/p&gt;

&lt;p&gt;The name was later changed to 'LiveScript' in &lt;strong&gt;September 1995&lt;/strong&gt;. The 'Script' meant it was a scripting language and not a real programming language compared to Java which was to be the complicated programming language reserved for real programmers to build the more complex big projects.&lt;/p&gt;

&lt;p&gt;The Syntax of JavaScript is derived from Java, it's first class functions are from &lt;a href="https://en.wikipedia.org/wiki/Scheme_(programming_language)" rel="noopener noreferrer"&gt;Scheme&lt;/a&gt;, a multi-paradigm programming language and it's prototype-based inheritance is from &lt;a href="https://en.wikipedia.org/wiki/Self_(programming_language)" rel="noopener noreferrer"&gt;Self&lt;/a&gt; which is a prototype based dynamic object oriented programming language.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Birth of "JavaScript"&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The name 'JavaScript' was introduced in &lt;strong&gt;December 1995&lt;/strong&gt; at a time when Java was quite popular among programmers and Netscape saw it as a good opportunity to clamp down on the booming success of Java. Hence, creating the name 'JavaScript'. Even though both are distinctively different languages. &lt;br&gt;
This has caused quite the confusion among newbies(myself inclusive), so I found out what some of the differences were.&lt;br&gt;
You can check this &lt;a href="https://www.thesoftwareguild.com/faq/difference-between-java-and-javascript/#:~:text=JavaScript%20code%20is%20written%20completely,on%20HTML%20documents%20and%20browsers." rel="noopener noreferrer"&gt;article&lt;/a&gt; for an indepth description of the differences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7rc5wptge9n55vj5mjtb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7rc5wptge9n55vj5mjtb.png" alt="Differences between Java and JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;
Image from codingninjas.com



&lt;h2&gt;
  
  
  &lt;strong&gt;ECMA&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;At the time when Microsoft's Bill Gates created the internet explorer and it became the new wave, Netscape struggled to keep up with the Internet Explorer for market shares. Then Microsoft decided to create it's own dynamic language, &lt;strong&gt;JScript&lt;/strong&gt;😏 which by the way was a &lt;em&gt;reversed-engineered JavaScript&lt;/em&gt;. This just brought alot of confusion among programmers because the different JavaScript versions were not compatible with all web browsers. &lt;/p&gt;

&lt;p&gt;Soon Netscape saw the need for JavaScript to be managed and standardized. As a result, in &lt;strong&gt;1996&lt;/strong&gt; Netscape submitted JavaScript's documentation to European Computer Manufacturers Association(ECMA) for standardization.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;1997&lt;/strong&gt;, the TC-39 committee (Ecma International's TC39 is a group of JavaScript developers, implementers, academics, and more, collaborating with the community to maintain and evolve the definition of JavaScript) released the first standardized version of JavaScript(ES1) called the &lt;strong&gt;ECMAScript&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;2009 - ES5, which is currently the standard version of JavaScript as it is supported by virtually all web browsers and is the easier version of ECMAScript to understand. &lt;/p&gt;

&lt;p&gt;2015 - ES6 was released with the biggest update to the language in years.&lt;/p&gt;

&lt;p&gt;The most current version of the ECMASCript is the ECMAScript 2022 (ES13) released in June 2022. As this article is directed towards beginners, it's better to avoid the confusing details of the update.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;JavaScript Today&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript was initially a browser-only scripting language. Today, JavaScript is a widely-adopted general-purpose multi-paradigm programming language that runs literally everywhere (web browsers, web servers, mobile apps, desktop apps, IoT devices).&lt;br&gt;
Nowadays, Other non-browser &lt;strong&gt;hosting environments&lt;/strong&gt; have been developed, a very popular one known as &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Node.js" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09fmi981xjl1s243fa4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09fmi981xjl1s243fa4a.png" alt="Node.Js logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node.js is a cross-platform, open-source server environment Developed by &lt;a href="https://en.wikipedia.org/wiki/Ryan_Dahl" rel="noopener noreferrer"&gt;Ryan Dahl&lt;/a&gt; . It runs on a &lt;a href="https://en.wikipedia.org/wiki/V8_(JavaScript_engine)" rel="noopener noreferrer"&gt;V8&lt;/a&gt; Engine and executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting.&lt;br&gt;
Another hosting framework is called &lt;a href="https://en.wikipedia.org/wiki/Deno_(software)" rel="noopener noreferrer"&gt;Deno&lt;/a&gt;, developed by the same creator of Node.js.&lt;/p&gt;

&lt;p&gt;JavaScript frameworks and libraries have been created to ease programming steps as websites are now having more functionality and are more dynamic. &lt;/p&gt;

&lt;p&gt;A JavaScript framework is a collection of JavaScript code libraries that provide a web developer with pre-written code for routine programming tasks. &lt;br&gt;
JavaScript libraries are collections of prewritten code snippets that can be used and reused to perform common JavaScript functions. Examples include Examples are &lt;a href="https://en.wikipedia.org/wiki/Vue.js" rel="noopener noreferrer"&gt;Vue.js&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Angular_(web_framework)" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/JQuery" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt;,&lt;a href="https://en.wikipedia.org/wiki/Next.js" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/React_(JavaScript_library)" rel="noopener noreferrer"&gt;React&lt;/a&gt;.&lt;br&gt;
We'll study these frameworks better as we progress in further articles.&lt;/p&gt;

&lt;p&gt;JavaScript  has garnered so much fame because of its dynamic nature and tight-interaction with Document Object Modelling(DOM ) which we'll also discuss later.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;You got here!💪🎉&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Your being here means you interested on this journey with me and I'm hoping I did some justice in explaining the start. I've gathered much more information researching for this article than when i just read about it😅. I believe this is a good foundation for us as I learn to give out more useful coding information to you guys. &lt;strong&gt;I hope you learned something new!&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Thanks for reading!❤&lt;/p&gt;

&lt;p&gt;All comments, additions, corrections and subtractions are welcome😊.&lt;br&gt;
This week we code!💪&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
