<?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>DEV Community: Chi</title>
    <description>The latest articles on DEV Community by Chi (@chiexplores).</description>
    <link>https://dev.to/chiexplores</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%2F323195%2F5e25db62-3e29-414d-808e-eba279a52651.jpg</url>
      <title>DEV Community: Chi</title>
      <link>https://dev.to/chiexplores</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chiexplores"/>
    <language>en</language>
    <item>
      <title>For Beginners: What you need to know about Var, Let, Const</title>
      <dc:creator>Chi</dc:creator>
      <pubDate>Fri, 08 May 2020 04:04:02 +0000</pubDate>
      <link>https://dev.to/chiexplores/for-beginners-what-you-need-to-know-about-var-let-const-45pl</link>
      <guid>https://dev.to/chiexplores/for-beginners-what-you-need-to-know-about-var-let-const-45pl</guid>
      <description>&lt;p&gt;I originally wrote a tutorial about Var, Let, and Const using &lt;a href="https://observablehq.com/@chi37/var-let-const-for-beginners"&gt;Observable Notebook&lt;/a&gt;.&lt;br&gt;
In the notebook, you can edit the code, so that you understand by doing.&lt;/p&gt;

&lt;p&gt;As a junior dev, it seems like you are told to never use var because the variable can be accessed anywhere, but what does that even mean? Keep reading and hopefully, understand the vocabulary and seeing code examples help. Of course, mess around with code as well.&lt;/p&gt;
&lt;h2&gt;
  
  
  REASSIGN VS REDECLARE: 
&lt;/h2&gt;

&lt;p&gt;When you create a variable, you declare it with the keywords &lt;code&gt;let, var, const&lt;/code&gt;. Reassign means you are giving the variable another value. &lt;code&gt;var&lt;/code&gt; can both be redeclared and reassigned. You will see that it is different for &lt;code&gt;const and let&lt;/code&gt; from this table.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UoVTH7K7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tgk6utfxmxmifss08wab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UoVTH7K7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tgk6utfxmxmifss08wab.png" alt="Table showing Scoping of Let Var and Const "&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  var color = 'blue'; //color declared
  color = 'black' //color reassigned
  var color = 'pink' //color redeclared
  return color
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  SCOPE:
&lt;/h2&gt;

&lt;p&gt;Var, let, and const have different types of scope. Scope is the context where variables and expressions live. &lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Scope
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;b&gt; Global: &lt;/b&gt; Variables can be accessed anywhere. A JS document is globally scoped. &lt;code&gt;var&lt;/code&gt; is globally scoped unless it is declared in a function scope.&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; Local: &lt;/b&gt; Variables in a function scope or block scope are local.&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; Lexical: &lt;/b&gt; A child scope has access to data in its parent's scope. Think nested functions - inner functions have access to variables of the outer function.&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; Block: &lt;/b&gt; Code enclosed in curly brackets &lt;code&gt;{}&lt;/code&gt; can't be accessed outside the block. Variables declared with &lt;code&gt;let and const&lt;/code&gt; have block scope. You see the block scopes in if/else statements, for example. &lt;code&gt;var&lt;/code&gt; variables are &lt;em&gt;NOT&lt;/em&gt; block scope.&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; Function: &lt;/b&gt; The variables declared in a function is accessible in that local scope. &lt;code&gt;var&lt;/code&gt; is used to declare in functions, though you might be told to only use &lt;code&gt;let&lt;/code&gt; from now on.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Global Scope
 let milkyWay = 'I am globally scoped, so you can access me anywhere!';

  { //Block Scope 
    var earth = 'Earth'; 
    const sun = 'Sun';
    let house = 'My house';
  }

  console.log(earth) //'Earth'
  // console.log(milkyway)  //'I am globally scoped, so you can access me anywhere!'
  //console.log(house) // will return Error bc house is in block scope
  console.log(sun) //will return Error bc sun is in block scope
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  HOISTING
&lt;/h2&gt;

&lt;p&gt;hoisting means that everytime you declare a variable, Javascript's engine will immediately hoist (or PULL) those variables up in the beginning of the scope and the variables will be declared. But will they be assigned or initialized? &lt;br&gt; With var, it will be initialized as undefined, while let and const will not. That is why you get an error&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aaLTJRhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jg3498ayt6ritcnotyfl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aaLTJRhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jg3498ayt6ritcnotyfl.png" alt="Code Snipper of Hoisting example"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>For Beginners: What is a function? My sh*tty explanation 💩</title>
      <dc:creator>Chi</dc:creator>
      <pubDate>Wed, 01 Apr 2020 08:11:56 +0000</pubDate>
      <link>https://dev.to/chiexplores/what-is-a-function-my-sh-tty-explnation-1j76</link>
      <guid>https://dev.to/chiexplores/what-is-a-function-my-sh-tty-explnation-1j76</guid>
      <description>&lt;p&gt;It's 12:09AM, I can't sleep. After drinking my protein shake (I was hungry) I decided, why not write an informational piece.&lt;br&gt;
During a Women Who Code virtual meetup, someone needed help understanding what functions are so, here it is!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Understand the vocabulary&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the vocab, whenever you can when you are talking about your code. For example, people get parameters and arguments mixed up when they first start. The more you use the correct language, the better you'll understand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Vocabulary:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function:&lt;/strong&gt; A reusable block that allows you to perform some calculation or task. Reusable, so you don't have to repeat work!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function Body:&lt;/strong&gt; That's the meat of the function - the logic part.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parameters:&lt;/strong&gt; That's the words inside the parenthesis. Basically, empty variables names that aren't assigned to any data, until you call the function with the arguments.  Speaking of arguments...&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arguments:&lt;/strong&gt; When you call a function (aka execute your function after you have defined it), you provide the data/values to pass into that function. 
I dare you to code this function and run it &lt;code&gt;function human(protein, veggie){ console.log( arguments);}&lt;/code&gt; tell me what you see! What is the data structure?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return:&lt;/strong&gt; Return allows you to exit out of a function when a condition is satisfied. Or, sometimes a function provides an output so you can use that output for something else.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is my shitty explanation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="c1"&gt;//function name is human&lt;/span&gt;
&lt;span class="c1"&gt;//parameters are protein and vegetable&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;human&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;protein&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vegetable&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//body&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`I am digesting &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;protein&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;vegetable&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;💩&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//calling the function with the arguments, 'protein shake' and 'spinach'&lt;/span&gt;
&lt;span class="nx"&gt;human&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;protein shake&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;spinach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//output:&lt;/span&gt;
&lt;span class="c1"&gt;//[Arguments] { '0': 'protein shake', '1': 'spinach' }&lt;/span&gt;
&lt;span class="c1"&gt;//'I am digesting protein shake and spinach'&lt;/span&gt;
&lt;span class="c1"&gt;//'💩'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I am a human and one of my main functions is to take input like food and digest it. After the food is digested, what the output (aka return) is 💩. That's my shitty explanation. 😬&lt;/p&gt;

&lt;p&gt;I will edit this later for more clarity and better examples but it is now 1:11AM and I should sleep.&lt;/p&gt;

&lt;p&gt;Eat your vegetables! &lt;/p&gt;

&lt;p&gt;//Chi&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
