<?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: Devin Ho</title>
    <description>The latest articles on DEV Community by Devin Ho (@devinho).</description>
    <link>https://dev.to/devinho</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%2F862951%2F4618605c-1f32-4d50-af87-efd7305affea.png</url>
      <title>DEV Community: Devin Ho</title>
      <link>https://dev.to/devinho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devinho"/>
    <language>en</language>
    <item>
      <title>Using Referencing, Invocation, and Callback Functions with Event Listeners</title>
      <dc:creator>Devin Ho</dc:creator>
      <pubDate>Wed, 06 Jul 2022 13:06:17 +0000</pubDate>
      <link>https://dev.to/devinho/using-referencing-invocation-and-callback-functions-with-event-listeners-45de</link>
      <guid>https://dev.to/devinho/using-referencing-invocation-and-callback-functions-with-event-listeners-45de</guid>
      <description>&lt;p&gt;Callback functions are quite useful as a programmer especially when they’re used with Event Listeners. A callback function by definition is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. For callback functions and event listeners to work properly, they need function referencing, not function invocation. Here, in the blog, I will dive deeper into the difference between the two and explain why you should use one over the other. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To get a better grasp of invocation, referencing, and callback functions, I’m going to change the text of “Hello, World” to “Goodbye, World” when I click on it. By doing so, I need to create an event listener (&lt;em&gt;addEventListener&lt;/em&gt;) to listen for when the click happens. Once the click happens, then the function will run. The function below is the function I’ve declared that will run once the event listener occurs. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_JY6u5Yq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70kx4q53sp9rlox92bk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_JY6u5Yq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70kx4q53sp9rlox92bk3.png" alt="Image description" width="708" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we grabbed the HTML element to change the text and assigned it to the variable &lt;em&gt;header&lt;/em&gt;. Then we want to change the content of that text so we use &lt;em&gt;textContent&lt;/em&gt; to change it to what we want it to be once the event listener happens. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HCFwP22n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zc21ot1lx9ez9xn2hre5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HCFwP22n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zc21ot1lx9ez9xn2hre5.gif" alt="Image description" width="518" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z_eMB-42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awuza9jjsx8twkffhr9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z_eMB-42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awuza9jjsx8twkffhr9d.png" alt="Image description" width="708" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the screenshot above, we were able to change the text from “Hello, World” to “Goodbye, World” using a callback function. If we remember the definition of a callback function mentioned earlier in the blog, we created an anonymous function inside the event listener as the second parameter. We used (&lt;em&gt;event&lt;/em&gt;) as a parameter using the arrow functions method ( =&amp;gt; ) and then passed that function as an argument when we used it in our &lt;em&gt;handleClick&lt;/em&gt; function. This was used to run the &lt;em&gt;handleClick&lt;/em&gt;’s code which changed the text from “Hello, World” to “Goodbye, World.” However, in order for the functions to work correctly as designed it’s important to understand why it is better to &lt;strong&gt;reference&lt;/strong&gt; a function rather than &lt;strong&gt;invoke&lt;/strong&gt; or &lt;strong&gt;call&lt;/strong&gt; a function once the event listener occurs. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Invoking a Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we use event listeners, typically we want to reference a function rather than invoke or call a function. You might ask, “Don’t we want to call the function?” which technically yes but the screenshot below will help you understand why you don’t want to call the function. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f05jY6lq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxb0muhql6ioj2eyrhjy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f05jY6lq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxb0muhql6ioj2eyrhjy.gif" alt="Image description" width="518" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Vfvaa6r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe0hq1f1tmnon7tsayx8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Vfvaa6r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe0hq1f1tmnon7tsayx8.png" alt="Image description" width="708" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example, the function is executed as soon as the line is read by the program. We see that as soon as we put the code into the console, “Hello, World” is immediately changed to “Goodbye, World” without us clicking on the text to make it change. Because we included parenthesis in our _handleClick _function, we executed the function before we could click on “Hello, World.” This is happening because we wrote our function with parenthesis on the end () of our function so therefore, we are calling or invoking the function rather than referencing it which we want to do instead. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Referencing a Function&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;If we take the same example and reference the function rather than invoke it, we will see very results of what we want to do. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2zCsgd6H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axd1uv70efpnyx92hze3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2zCsgd6H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axd1uv70efpnyx92hze3.gif" alt="Image description" width="518" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DfE165gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhe740039er46wxp75pa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DfE165gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhe740039er46wxp75pa.png" alt="Image description" width="674" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the screenshots above, we see that once we add the code into the console, “Hello, World” remains as is until we click on the text in which the event listener will occur and the handleClick function will run, changing “Hello, World” to “Goodbye, World” By not adding the parentheses at the end of our &lt;em&gt;handleClick&lt;/em&gt; function, we are referencing it instead of invoking. The function will not execute until the event listener or “click” occurs which is what we want to happen. By referencing our &lt;em&gt;handleClick&lt;/em&gt; function, it waits until the event listener occurs instead of executing as soon as the script loads as it would have done when we were invoking the function. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Map vs. forEach: Which one to use?</title>
      <dc:creator>Devin Ho</dc:creator>
      <pubDate>Tue, 31 May 2022 14:16:40 +0000</pubDate>
      <link>https://dev.to/devinho/map-vs-foreach-which-one-to-use-53ob</link>
      <guid>https://dev.to/devinho/map-vs-foreach-which-one-to-use-53ob</guid>
      <description>&lt;p&gt;When I first started learning array iterations, I came across two different but seemingly similar array methods. Array.prototype.map() and Array.prototype.forEach(). &lt;/p&gt;

&lt;p&gt;So, what's the difference? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition of .map and .forEach&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;map(): creates a new array that populates the results of calling a provided function on every element in the calling array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;forEach(): executes a provided function once for each array element&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What Doest This Mean?&lt;/strong&gt;&lt;br&gt;
The forEach() method doesn't actually have a built-in return value, meaning it will return undefined. This makes the forEach() method generic which makes it an attractive option to choose. However, this method should be used when you can't use a method that is more specialized. A common way for using forEach() is trying to print contents to the screen. &lt;/p&gt;

&lt;p&gt;The .map() method is specialized. it will have a return value and will create a new array the same size as the array it is copying. It is important to note that this method will not change the original array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
.forEach():&lt;br&gt;
&lt;em&gt;array.forEach(function(currentValue, index, arr), thisValue)&lt;/em&gt;&lt;br&gt;
Parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function(): a function to run for each array element&lt;/li&gt;
&lt;li&gt;currentValue: the current value being processed in the array&lt;/li&gt;
&lt;li&gt;index (optional): the index of the current element&lt;/li&gt;
&lt;li&gt;arr (optional): The array of which the .forEach was called upon&lt;/li&gt;
&lt;li&gt;thisValue (optional): Values to use “this” when executing a “callback function”. The default value is undefined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Return Value: undefined&lt;/p&gt;

&lt;p&gt;.map():&lt;br&gt;
&lt;em&gt;array.map(function(currentValue, index, arr), thisValue)&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function(): a function to run for each array element&lt;/li&gt;
&lt;li&gt;currentValue: the current value being processed in the array&lt;/li&gt;
&lt;li&gt;index (optional): the index of the current element&lt;/li&gt;
&lt;li&gt;arr (optional): The array of which the .map was called upon&lt;/li&gt;
&lt;li&gt;thisValue (optional): A value passed to the function to be used as its “this” value. The default value is undefined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Return Value: The results of a function for each array element&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coding Examples&lt;/strong&gt;&lt;br&gt;
Let us see some examples in which each method can be displayed and used properly.&lt;/p&gt;

&lt;p&gt;.forEach() method:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZqUtqUoW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldna28lzscy7svamzltm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZqUtqUoW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldna28lzscy7svamzltm.jpg" alt="Image description" width="578" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return Value:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f8gQzDvb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2b43eifhhhonm1dn5ep.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f8gQzDvb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2b43eifhhhonm1dn5ep.jpg" alt="Image description" width="370" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we are multiplying each number by itself for each element in an array. The forEach method is called for each element and we print or log the multiplication of the number. We can see that the original array has not changed and the console.log of the returnValue shows as undefined because the return value of a .forEach will always be undefined. Because, forEach method doesn’t create a new array and allows you to modify the source array itself, this is considered a mutator method.&lt;/p&gt;

&lt;p&gt;.map() method:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dAvEJWbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsrbs3uy6vdqylrq737w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dAvEJWbz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsrbs3uy6vdqylrq737w.jpg" alt="Image description" width="572" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return Value:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mz2zfL8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38eaun84g8armpz51ui6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mz2zfL8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38eaun84g8armpz51ui6.jpg" alt="Image description" width="364" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we are using the same arrays and elements but just switching the forEach iteration with the .map iteration. As you can see, we get two different results when using the different methods. Looking at the example, when we console logged the numberArray, the array has remained unchanged but the return value of the .map iteration created a new array which is built by multiplying a number to each element of the array. Unlike the .forEach method which had a return value of undefined, the .map gave us a return value of each number multiplying by itself. Through our example, the .map creates a new array by applying the callback function on each element of the source array. Since the original array is not changed, we can say that .map uses an immutable method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which One Is Better?&lt;/strong&gt;&lt;br&gt;
Once we’ve established the difference between the two methods. Now it comes to the question: how do we know when to use the forEach method or the map method?&lt;/p&gt;

&lt;p&gt;This question depends on what you are trying to accomplish.&lt;/p&gt;

&lt;p&gt;One might favor the forEach method when you just want to loop through each element and not worried about changing the data in the array. Someone might just want the array to do something just as saving it to a database or console logging it out:&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3R0Fc3m1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urqf5rn9jzpa9b80435l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3R0Fc3m1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urqf5rn9jzpa9b80435l.png" alt="Image description" width="880" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One might favor the map method when you want to change or alter the data. This is preferable when changing or altering data because it doesn’t modify the original array and returns a new array. Because of this, the original array is kept intact and unchanged. Because it returns a new array, this means that you can do things such as chaining which means you can chain other methods or array iterations to the map method.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eSXVEs2u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1pzsqalbkvlm40b1phs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eSXVEs2u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1pzsqalbkvlm40b1phs.jpg" alt="Image description" width="880" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we are mapping over array1 and multiplying each element by 2. After each element is done multiplying, then we filter through the array and only keep the elements that are greater than 50 which is then saved in the array named array2. The final result then gives us an array of [74, 84, 100].&lt;/p&gt;

&lt;p&gt;In the end, it’s to know what you’re trying to accomplish so you know which method to use properly but it’s equally important to understand the difference and understand how each method can affect your code.&lt;/p&gt;

&lt;p&gt;Sources: MDM, W3Schools, StackOverflow&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Starting My Software Engineering Journey</title>
      <dc:creator>Devin Ho</dc:creator>
      <pubDate>Tue, 31 May 2022 14:16:24 +0000</pubDate>
      <link>https://dev.to/devinho/starting-my-software-engineering-journey-323m</link>
      <guid>https://dev.to/devinho/starting-my-software-engineering-journey-323m</guid>
      <description>&lt;p&gt;About a month ago, I started my journey as software engineer. Although I’m about 2 years removed from college and graduated with a technical degree, I realized I didn’t actually know what I wanted to do and had no trajectory for my career. I got a job as a Software Tester out of college and thought it was something I would want to do for the rest of my life. That idea however quickly fizzled out as I found it to be very repetitive and mundane. After spending months looking for a new job and constantly getting rejection emails, I decided I needed to hone in on some new skills. &lt;/p&gt;

&lt;p&gt;As I was looking for jobs, software engineer jobs were constantly popping up on my feeds. Even while taking coding classes in college, I knew my skills weren’t on par with what companies wanted. It was in this moment, where I knew I needed to hone in on some skills. That’s when a friend told me about a software engineering program she had recently taken and thought that while it would be challenging, it’s something that I should consider taking. &lt;/p&gt;

&lt;p&gt;Through many weeks of wrestling with the idea, I finally decided to enroll in the Flatiron Software Engineering Program. I remember even while completing the pre-work, I thought this was a huge mistake and while sometimes I still think that, the feeling of completing each lab and deliverable is definitely a great reminder this was the right decision. &lt;/p&gt;

&lt;p&gt;It’s extremely gratifying learning the material, putting it into practice, and seeing the results happen before your very eyes. I’m excited to learn more complex topics and languages as I continue to hone in on these new skills to start my software engineering journey. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
