<?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: Veronica</title>
    <description>The latest articles on DEV Community by Veronica (@veronicorn).</description>
    <link>https://dev.to/veronicorn</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%2F98461%2F4c48ba3c-72eb-4ac4-9ee4-0f01673af676.jpeg</url>
      <title>DEV Community: Veronica</title>
      <link>https://dev.to/veronicorn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/veronicorn"/>
    <language>en</language>
    <item>
      <title>Arrow Functions + This keyword</title>
      <dc:creator>Veronica</dc:creator>
      <pubDate>Wed, 14 Nov 2018 18:53:19 +0000</pubDate>
      <link>https://dev.to/veronicorn/arrow-functions--this-keyword-8i1</link>
      <guid>https://dev.to/veronicorn/arrow-functions--this-keyword-8i1</guid>
      <description>&lt;p&gt;Technical blog post number trois, coming at ya!&lt;/p&gt;

&lt;p&gt;At the end of my last post about arrow functions, I briefly teased that the arrow function has a special relationship with the JavaScript keyword, &lt;em&gt;this&lt;/em&gt;. There's so much to learn about &lt;em&gt;this&lt;/em&gt; (Google spit out over 309,000 hits on the topic!), but here is what I've learned so far about it in regards to the lovely &lt;em&gt;fat arrow&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;(Sidenote: As evidenced by some mildly-heated debate in my last post's discussion section, the arrow function goes by many names! I even just saw it referred to as the &lt;em&gt;hash rocket&lt;/em&gt;, which is a term dubbed by Ruby enthusiasts. And I've gotta say, that may be my favorite term dubbed by anyone for anything.)&lt;/p&gt;

&lt;p&gt;From what I've seen, &lt;em&gt;this&lt;/em&gt; has as almost many haters as it has super fans. It can be confusing and seemingly unreliable to use in all classic function expressions because &lt;em&gt;this&lt;/em&gt; relies on the &lt;strong&gt;context&lt;/strong&gt; of its environment in which its called, e.g., if &lt;em&gt;this&lt;/em&gt; lies within a function within a method, &lt;em&gt;this&lt;/em&gt; will refer to the global scope and not the method.  &lt;/p&gt;

&lt;p&gt;Enter... THE ARROW FUNCTION!&lt;/p&gt;

&lt;p&gt;As you can see in my example code below, &lt;em&gt;this&lt;/em&gt; unfortunately does not work the way I intend it. The alerts that pop up show "loves to bite", "loves to scratch", and "loves to destroy" without including the cat's awesome name, Dragon. &lt;em&gt;This&lt;/em&gt; fails to refer to the object but refers to the global scope since it is within a function. I've seen this failure referred to as a "JavaScript quirk," which can be considered an understatement by some. :)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Trying to use 'this' without an arrow function

let cat = {
  name: 'Dragon',
  favThings: ['bite', 'scratch', 'destroy'],
  showFavThings: function() {
    this.favThings.forEach(function(fav) {
      alert(this.name + " loves to " + fav + "!");
    });
  }
};

cat.showFavThings();
//output does not include cat name, boooo!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But our friend, The Arrow Function (which was developed for JavaScript ES6 in part due to the aforementioned "quirk"), comes to the rescue here because &lt;em&gt;this&lt;/em&gt; is lexically-bound to arrow functions, meaning that &lt;em&gt;this&lt;/em&gt; will refer to whatever code the arrow function is in before it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//this with arrow function

let cat = {
  name: 'Dragon',
  favThings: ['bite', 'scratch', 'destroy'],
  showFavThings () {
    this.favThings.forEach((fav) =&amp;gt; {
      alert(this.name + " loves to " + fav + "!");
    });
  }
};

cat.showFavThings();
//Dragon loves to bite!
//Dragon loves to scratch!
//Dragon loves to destroy!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good job, Dragon! You do you!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fvignette.wikia.nocookie.net%2Fhowtotrainyourdragon%2Fimages%2F6%2F69%2FToothless_ecstatic_claps.gif%2Frevision%2Flatest%3Fcb%3D20160224034457" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fvignette.wikia.nocookie.net%2Fhowtotrainyourdragon%2Fimages%2F6%2F69%2FToothless_ecstatic_claps.gif%2Frevision%2Flatest%3Fcb%3D20160224034457" alt="Toothless applauds" width="500" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a novice coder, I'm still learning how to best use Arrow Functions as not all situations call for them. &lt;strong&gt;But what about you? Why do you like or dislike this method?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Brief Intro to Arrow Functions</title>
      <dc:creator>Veronica</dc:creator>
      <pubDate>Thu, 08 Nov 2018 00:19:39 +0000</pubDate>
      <link>https://dev.to/veronicorn/brief-intro-to-arrow-functions-2pc6</link>
      <guid>https://dev.to/veronicorn/brief-intro-to-arrow-functions-2pc6</guid>
      <description>&lt;p&gt;Hey Devvies; technical blog post number two coming your way.&lt;/p&gt;

&lt;p&gt;Evidently, one of the most celebrated additions to JavaScript a short three or so years ago (version ES6/ES2015) was the introduction to the &lt;strong&gt;Arrow Function.&lt;/strong&gt; (I've also seen it referred to as the &lt;strong&gt;fat arrow&lt;/strong&gt; function.)&lt;/p&gt;

&lt;p&gt;A simple explanation of what an arrow function accomplishes is that it cleans up your function code to be more concise, less messy looking by using shorter syntax.&lt;/p&gt;

&lt;p&gt;Take this simple function to double a number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const double = function (num) {
    return num * 2;
    }

double(3);
// output is 6

double (12);
// output is 24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lookee what an &lt;em&gt;arrow function&lt;/em&gt; can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const doubleArrow = num =&amp;gt; num * 2;

doubleArrow(3);
// output is still 6!

doubleArrow(12);
// output is still 24!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fmemeshappen.com%2Fmedia%2Fcreated%2F2016%2F12%2FWhaaaat-.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fmemeshappen.com%2Fmedia%2Fcreated%2F2016%2F12%2FWhaaaat-.jpg" alt="whaaaaaat?" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;doubleArrow&lt;/strong&gt; function did the exact same thing as what the &lt;strong&gt;double&lt;/strong&gt; function did but in one line of code instead of three! That's amazing!&lt;/p&gt;

&lt;p&gt;That was a very simple example using just one parameter. Let's do another very simple example but with &lt;em&gt;two&lt;/em&gt; parameters this time, just for kicks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// regular function

const sum = function (num1, num2) {
    return num1 + num2;
    }

// arrow function version

const sumArrow = (num 1, num2) =&amp;gt; num1 + num2;

sum(1, 10);
// output is 11

sumArrow (1, 10);
// output is still 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty cool! The only difference between the double and sum syntax is we added the parentheses back in when there was more than one parameter to apply. You can still include the parentheses if there is just one parameter, but they're optional.&lt;/p&gt;

&lt;p&gt;There are some other cool features of the arrow function that slightly differ from regular functions (most notably while using the 'this' keyword), but we can delve into that in a later post. :) &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Heart Eyes for Array Methods</title>
      <dc:creator>Veronica</dc:creator>
      <pubDate>Wed, 31 Oct 2018 04:02:11 +0000</pubDate>
      <link>https://dev.to/veronicorn/heart-eyes-for-array-methods-2g3c</link>
      <guid>https://dev.to/veronicorn/heart-eyes-for-array-methods-2g3c</guid>
      <description>&lt;p&gt;It's been almost three months (aka half-way there!) into my first intensive experience in a coding boot camp, and it's clear that objects and arrays are pretty important to even a novice at JavaScript. Objects are key-value pairs (&lt;em&gt;like a word and its corresponding definition in a dictionary&lt;/em&gt;) while an array, which is a special type of object, is an ordered list, which is useful when dealing with a large amount of the same type of data, like a collection of names. &lt;/p&gt;

&lt;p&gt;For example, an array of random colors is noted such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ['yellow', 'black', ‘blue’, ‘green’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With arrays, JavaScript gives you the ability to make basic edits like add, delete, and update the data as well as helps you sort through the information with limited amounts of code. These are called &lt;em&gt;array methods&lt;/em&gt;. There is a plethora of these cool little mechanisms, not even a fraction of which I have tried and tested myself yet, but here are a couple of my favorites so far.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push&lt;/strong&gt;&lt;br&gt;
Adds new element to the end of an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ['yellow', 'black', ‘blue’, ‘green’]

colors.push('white');

alert(colors) 
// Output will be yellow, black, blue, green, white

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Splice&lt;/strong&gt;&lt;br&gt;
Deletes item(s) from an array, from any location. The parameters you pass through indicate &lt;em&gt;where in the array you’re beginning&lt;/em&gt; and &lt;em&gt;how many items to remove&lt;/em&gt;. Remember the index rule: the first item in an array is defined as 0, second item is 1, third item is 2, and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ['yellow', 'black', ‘blue’, ‘green’, 'white'] 
// let’s remove black and blue out of there!

colors.splice(1, 2) 
// so starting at index 1 (black), remove 2 items (black, blue)

alert(colors) 
// Output will now be yellow, green, white

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Splice&lt;/strong&gt; is doubly cool because not only can you delete items from anywhere in the array, you can also insert new items at the same time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ['yellow', 'black', 'blue', 'green', 'white'] 
// let’s remove blue and green and add a bit more flair

colors.splice(2, 2, 'rose gold')

alert(colors) 
// Output will be yellow, black, rose gold, white

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope to put to use and get to know many more of these tiny heroes (many of which you can find &lt;a href="https://javascript.info/array-methods" rel="noopener noreferrer"&gt;here&lt;/a&gt;) throughout my boot camp journey and beyond. Hooray for arrays!&lt;/p&gt;

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