<?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: George Hanson</title>
    <description>The latest articles on Forem by George Hanson (@georgehanson).</description>
    <link>https://forem.com/georgehanson</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%2F99197%2F1a765904-9d43-4790-a3cc-7077ce6842ad.jpg</url>
      <title>Forem: George Hanson</title>
      <link>https://forem.com/georgehanson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/georgehanson"/>
    <language>en</language>
    <item>
      <title>Are Web Development Bootcamps Worth It?</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Thu, 08 Aug 2019 08:10:45 +0000</pubDate>
      <link>https://forem.com/georgehanson/are-web-development-bootcamps-worth-it-18fo</link>
      <guid>https://forem.com/georgehanson/are-web-development-bootcamps-worth-it-18fo</guid>
      <description>&lt;p&gt;Over the past couple of years, web development bootcamps have sprung up all over the place. It now seems to be the goto place for would-be developers to get started within the industry. There are some pro's and con's to going through a bootcamp, so is it worth it?&lt;/p&gt;

&lt;p&gt;Well the answer to that (like most code related questions) - it depends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Web Development Bootcamps
&lt;/h2&gt;

&lt;p&gt;The main reason in my opinion for the rise of bootcamps is undoubtedly the support they offer. Now not all bootcamps are equal and some are just plain terrible. But I'm just talking about the reputable ones here.&lt;/p&gt;

&lt;p&gt;You have the support and guidance of not just the tutors, but the other students who are going through the same bootcamp. If you are someone who has difficulty self-teaching then this is a massive benefit.&lt;/p&gt;

&lt;p&gt;Another key benefit of enrolling in a web development bootcamp is the top-quality learning resources. Whether these are videos, textbooks or codelabs you have the re-assurance that you are learning from high quality resource material that has already been vetted for accuracy and completeness. When you are self-teaching, you have to do this research yourself.&lt;/p&gt;

&lt;p&gt;One thing I hear bootcamp students mention all of the time is just how much they learn within a short space of time. These courses can be intensive and you have to put a lot of work into them. But because of the high quality curated content you are consuming, you do learn lots within a short period of time. But it is worth bearing in mind that this can be seen as both a pro and a con. You still need to have enough experience working with something for it to fully stick in your head, you can't just quickly glaze over something and remember it all perfectly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cons of Web Development Bootcamps
&lt;/h2&gt;

&lt;p&gt;The first con I'd like to mention about web development bootcamps is the price. These bootcamps can get very expensive very quickly. They often range from $5000 to $25000+ which unless you have a bunch of cash in the bank means borrowing or financing. Straight away you are putting yourself into debt before you get a job. Which leads me nicely onto my second point.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You do not have a guaranteed job afterwards.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A lot of bootcamps like to highlight how much earning potential there is as a web developer, but in reality you still have to go out and find the job. You don't get it handed to you on a silver platter and unless you continue to put hard work and teach yourself after you have finished you will find progression to be extremely difficult.&lt;/p&gt;

&lt;p&gt;It is important to remember that web development bootcamps are not a &lt;strong&gt;"magic bullet"&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, are they worth it?
&lt;/h2&gt;

&lt;p&gt;Well, as I said at the start of the post it depends. For some people it works as an excellent way to get into the industry, but it is important that you manage your expectations. While there are some people who do go through bootcamps and land the well-paying job straight away; a lot of people don't. So just be prepared to put work in, especially if you want to progress your career further. Technology is changing at such a rapid rate.&lt;/p&gt;

&lt;p&gt;In my personal opinion if you feel like you are able to self-teach and you are able to take your time, there are plenty of free resources that teach you everything you need to know. But if you are comfortable with bootcamps, go right ahead.&lt;/p&gt;

&lt;p&gt;Whichever route you chose to go down, just have fun!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was originally posted on my blog at &lt;a href="https://www.georgehanson.co.uk/blog/are-web-development-bootcamps-worth-it"&gt;https://www.georgehanson.co.uk/blog/are-web-development-bootcamps-worth-it&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>firstyearincode</category>
      <category>discuss</category>
    </item>
    <item>
      <title>3 reasons why you SHOULD write tests</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Mon, 08 Jul 2019 11:00:50 +0000</pubDate>
      <link>https://forem.com/georgehanson/3-reasons-why-you-should-write-tests-c7e</link>
      <guid>https://forem.com/georgehanson/3-reasons-why-you-should-write-tests-c7e</guid>
      <description>&lt;p&gt;Writing tests is something that I think a lot of developers come to later on. It's quite often that when developers are learning to code, whether that is self taught, through bootcamps or at university; testing is often overlooked.&lt;/p&gt;

&lt;p&gt;I don't get it, why is testing not focused on enough? When you start working on production projects and in teams you often find that testing is something you simply have to do.&lt;/p&gt;

&lt;p&gt;I think part of it comes down to the case for writing tests not being clear enough. It's like the developers version of office paperwork - nobody seems to want to do it. Let me go through why you &lt;strong&gt;should&lt;/strong&gt; be writing automated tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typical Scenario
&lt;/h2&gt;

&lt;p&gt;In most workplaces, a typical scenario is this. You're working on a REST endpoint for an API. It starts off fairly simple but over time it gets more and more complicated. Before long you are using repositories, caching and the whole thing becomes a bit daunting to touch. Because you become worried about breaking things you don't refactor the code and over time it becomes this spaghetti code that people don't want to work with.&lt;/p&gt;

&lt;p&gt;Testing makes this better.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is automated testing?
&lt;/h2&gt;

&lt;p&gt;Put simply, automated testing is making sure that your code does what it is supposed to do. You interact with your API you have created and assert that the correct actions have occurred. Whether that is a HTTP response code, checking that a record exists in the database or just something else.&lt;/p&gt;

&lt;p&gt;It's also worth mentioning that testing is not a magic bullet. It follows the same principles as most things GiGo (Garbage in, Garbage out). You have to make sure that the tests you write are meaningful and useful otherwise they serve no purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Testing Frameworks
&lt;/h2&gt;

&lt;p&gt;For testing the easiest way of getting started is to use one the many frameworks available for your language of choice. Here are some common testing frameworks used for PHP and JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  PHP
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;PHPUnit&lt;/li&gt;
&lt;li&gt;Codeception&lt;/li&gt;
&lt;li&gt;Behat&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Jest&lt;/li&gt;
&lt;li&gt;Jasmine&lt;/li&gt;
&lt;li&gt;Mocha&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why you should write automated tests?
&lt;/h2&gt;

&lt;p&gt;So I have already covered a couple of reasons why automated tests are useful. But let me dive in a little deeper on why you should be writing automated tests.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Developer confidence
&lt;/h3&gt;

&lt;p&gt;As I mentioned above, it doesn't take long to create these large classes that are unwieldy. One of the best benefits that testing gives you is this confidence as a developer. You can make any change you want, simply run the test suite and know straight away if you have broken anything.&lt;/p&gt;

&lt;p&gt;This gives you a lot of flexibility. You can not only refactor code worry-free, but you can also experiment with solutions without the fear of breaking the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Thinking as a consumer
&lt;/h3&gt;

&lt;p&gt;Testing often requires you to think from a different perspective. You have to take your developer hat off and put on your consumer hat. Whether this is how someone will consume a HTTP API or a package, you can design your system in a way that is best for the consumer.&lt;/p&gt;

&lt;p&gt;Because of this, it allows you to easily think of edge cases in how the user might choose to interact with your application. How many times have users used an app in a way you hadn't anticipated?&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Time saving
&lt;/h3&gt;

&lt;p&gt;Contrary to what a lot of people think, testing &lt;strong&gt;does&lt;/strong&gt; save you time. How can this be when you are writing the test as well as the implementation you ask? Well because it allows you to spot bugs easier you are less likely to spend time debugging for a start. If a bug gets reported in your system, write a test to reproduce the bug and then you can interact with the application in isolation to find the root cause.&lt;/p&gt;

&lt;p&gt;Testing is something that you are spending time writing as an investment in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is there a time you shouldn't write automated tests?
&lt;/h2&gt;

&lt;p&gt;Generally speaking no. But remember this is not a law, use your best judgement. If you are writing a small app just to play around with an idea and you are not planning on releasing it to the outside world then there is no harm in not writing any tests. That being said, it is a really good habit to get into and the more you do it the easier it will become.&lt;/p&gt;

</description>
      <category>php</category>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>Simple PHP Control Structure Refactoring</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Thu, 02 May 2019 15:02:06 +0000</pubDate>
      <link>https://forem.com/georgehanson/simple-php-control-structure-refactoring-2mn4</link>
      <guid>https://forem.com/georgehanson/simple-php-control-structure-refactoring-2mn4</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally posted on my blog - &lt;a href="https://www.georgehanson.co.uk/blog/simple-php-control-structure-refactoring"&gt;Simple PHP Control Structure Refactoring&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before we get into it, I posted all three of these little refactors on my &lt;a href="https://instagram.com/_georgehanson_"&gt;Instagram&lt;/a&gt; and &lt;a href="https://twitter.com/GeorgeHanson_"&gt;Twitter&lt;/a&gt; pages. Be sure to check those out as there is a handy little image you can save.&lt;/p&gt;

&lt;p&gt;One common thing I see when looking at code is some simple refactors that can make it slightly more readable. One of these "code smells" are if control structures. There are some occasions where these can be made much simpler and even reduced to just one line.&lt;/p&gt;

&lt;p&gt;In this article I'll go through three simple refactoring tips to help tidy up your code. I hope you find them useful so let's begin. &lt;/p&gt;

&lt;h2&gt;
  
  
  Ternary Operator
&lt;/h2&gt;

&lt;p&gt;The ternary operator is a simple but powerful operator that I find myself using throughout my code-base. This operator allows us to easily check a condition and return a value in just one line.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example. Here we are looking at a five line control structure. We are checking if the user is logged in or not and changing the value of the &lt;code&gt;welcome&lt;/code&gt; variable accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$welcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Welcome '&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$welcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Welcome Guest'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Simple enough right?&lt;/p&gt;

&lt;p&gt;Well we can make it even simpler using the Ternary operator. Here is an example of how we could refactor this control structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$welcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Welcome '&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Guest'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And there we go. We have refactored the control structure into just one line. But how does this work? Let's break it down. The first thing we are doing is concatenating the result of the conditional to the string &lt;code&gt;Welcome&lt;/code&gt;. With me so far? &lt;/p&gt;

&lt;p&gt;Great. So let's take a look at the conditional itself. We are checking if the user is currently logged in, if they are it returns the value after the &lt;code&gt;?&lt;/code&gt; which in this case is the users first name. If not it returns the value after the &lt;code&gt;:&lt;/code&gt; which is "Guest".&lt;/p&gt;

&lt;p&gt;As you can see this is a really simple, yet powerful shortcut to clean up control structures.&lt;/p&gt;

&lt;h2&gt;
  
  
  'Elvis' Operator
&lt;/h2&gt;

&lt;p&gt;Ok, ok. This isn't actually called the Elvis operator, but it does look like a little guy with Elvis' hair style - so it has been dubbed as such.&lt;/p&gt;

&lt;p&gt;This instead is actually the Ternary operator, but a short-hand version of it. There are some cases where we want to return the value of what we are evaluating rather than a separate value. In which case we can use the Elvis operator.&lt;/p&gt;

&lt;p&gt;Sounds a little confusing? Don't worry, let's take a look at an example and it will all become clear.&lt;/p&gt;

&lt;p&gt;Here we want to get the url for the avatar that should be displayed. If the user has an avatar url we will use that, otherwise we want to use the default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;avatarUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;avatarUrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'/default.jpg'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Take a look at how we can make it simpler. Here is an example of how we could refactor this control structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;avatarUrl&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s1"&gt;'/default.jpg'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Can you see why it has been dubbed the Elvis operator?&lt;/p&gt;

&lt;p&gt;You can see that this is very similar to using the long-form Ternary operator. But it is slightly different. If the &lt;code&gt;avatarUrl&lt;/code&gt; is truthy it will return that value, otherwise it will return the string. This is the same as writing the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;avatarUrl&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;avatarUrl&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'/default.jpg'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Null Coalescing Operator
&lt;/h2&gt;

&lt;p&gt;This is the final operator I'm going to talk about. This operator strictly checks if the left operand is not null or if it exists as a variable, array index or object property. This is another awesome little feature that was added in PHP 7.&lt;/p&gt;

&lt;p&gt;This operator acts similarly to the PHPs &lt;code&gt;isset&lt;/code&gt; function as well as the 'Elvis' operator.&lt;/p&gt;

&lt;p&gt;The most common use case I find for these is checking if an item exists in an array and if it does setting that value to a variable, otherwise setting it to a default. That way we avoid errors where the index does not exist.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example.&lt;/p&gt;

&lt;p&gt;Here I am checking the data in a &lt;code&gt;POST&lt;/code&gt; request to see if the user has provided a slug for the post. If one has been provided we will set the &lt;code&gt;slug&lt;/code&gt; variable to that value, otherwise I want to call a &lt;code&gt;generateSlug&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;generateSlug&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see we are already using the Ternary operator but we can make this even simpler by using the Null Coalescing operator.&lt;/p&gt;

&lt;p&gt;To use this operator we simply use &lt;code&gt;??&lt;/code&gt; with the default value as the right operand. Here is how we can refactor the code above to make it easier to read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;generateSlug&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Much nicer, using the Null Coalescing operator we have simplified it massively. It checks if the &lt;code&gt;$_POST['slug']&lt;/code&gt; value exists and if it does, assigns it to the slug variable. Otherwise we call the function.&lt;/p&gt;

&lt;p&gt;I hope that you found this post useful. I know that I use all three of these techniques throughout my code-base to clean it up and I hope you do to. Be sure to check out my &lt;a href="https://twitter.com/GeorgeHanson_"&gt;Twitter&lt;/a&gt; and &lt;a href="https://instagram.com/_georgehanson_"&gt;Instagram&lt;/a&gt; pages for handy little images you can save.&lt;/p&gt;

</description>
      <category>php</category>
      <category>refactorit</category>
      <category>beginners</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Building Vue.js Applications With TypeScript - Part Two</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Tue, 23 Apr 2019 13:09:29 +0000</pubDate>
      <link>https://forem.com/georgehanson/building-vue-js-applications-with-typescript-part-two-2808</link>
      <guid>https://forem.com/georgehanson/building-vue-js-applications-with-typescript-part-two-2808</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally posted on my blog here - &lt;a href="https://www.georgehanson.co.uk/blog/building-vuejs-applications-with-typescript-part-two"&gt;https://www.georgehanson.co.uk/blog/building-vuejs-applications-with-typescript-part-two&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A while ago, I posted an article titled "Building VueJS Applications with TypeScript". If you haven't seen that yet, make sure you take a look. You can find it by clicking &lt;a href="https://dev.to/georgehanson/building-vuejs-applications-with-typescript-1j2n"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the end of that post, I noted that I would be writing a follow-up article explaining methods, props, child components, etc. While it has been a while since I posted that, this is the second post in the series.&lt;/p&gt;

&lt;p&gt;In this article, we will carry on where we left off. But we are going to create a very simple to-do list application to demonstrate a variety of concepts. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up
&lt;/h2&gt;

&lt;p&gt;The first thing that we need to do is to create a new component for our to-do list. Within your &lt;code&gt;src/components&lt;/code&gt; folder, create a new file called &lt;code&gt;ToDo.ts&lt;/code&gt; and add the following boilerplate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;WithRender&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./to-do.html&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="nd"&gt;WithRender&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ToDo&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also, create a new file in the same directory called &lt;code&gt;to-do.html&lt;/code&gt;. Here is some very basic HTML to get us started.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;My To-Do App!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter task..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Task&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, we need to update our &lt;code&gt;Home.vue&lt;/code&gt; file within the views directory so that it loads our new &lt;code&gt;ToDo.ts&lt;/code&gt; component. Update the component to look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"home"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Vue logo"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"../assets/logo.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ToDo&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"ts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ToDo&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/components/ToDo.ts&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="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ToDo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Our First Component
&lt;/h2&gt;

&lt;p&gt;The first thing I would like to do is abstract our form to its own component. Let's create a new component called &lt;code&gt;ToDoForm.ts&lt;/code&gt; and copy the HTML template also. We should have two new files that look like this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ToDoForm.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;WithRender&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./to-do-form.html&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="nd"&gt;WithRender&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;to-do-form.html&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter task..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Task&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have abstracted the component, we need to include this child component within our parent. In order to do this, we need to import the component into the TypeScript file, register it and then update the template to display it. Let's go through that now. To get started, import the &lt;code&gt;ToDoForm.ts&lt;/code&gt; component into the &lt;code&gt;ToDo.ts&lt;/code&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ToDoForm&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;p&gt;Next, we need to register the component. We can do this by passing an object to our &lt;code&gt;@Component&lt;/code&gt; decorator. Here we can configure the component like we would any normal Vue component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&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;to-do-form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;ToDo.ts&lt;/code&gt; file should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;WithRender&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./to-do.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./ToDoForm&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="nd"&gt;WithRender&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&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;to-do-form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ToDo&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The final step is to now update our &lt;code&gt;to-do.html&lt;/code&gt; template so that we are referencing the child component. Simply remove the form and replace it with a &lt;code&gt;&amp;lt;to-do-form /&amp;gt;&lt;/code&gt; tag. Once done, our template file should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;My To-Do App!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;to-do-form&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You should now see that the form is being displayed on our page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Showing The Tasks
&lt;/h2&gt;

&lt;p&gt;The next thing we are going to tackle is showing the tasks to the user. To start with we need to store the tasks as an array. In our &lt;code&gt;ToDo.ts&lt;/code&gt; component, we will add a new property. This is essentially the same as adding any data property in a standard &lt;code&gt;.vue&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;Let's define a type for a task. Create a &lt;code&gt;types&lt;/code&gt; folder within &lt;code&gt;src&lt;/code&gt; and then create a file called &lt;code&gt;Task.ts&lt;/code&gt;. Our task is going to be relatively simple. Each task will consist of a description and a completion status. Here is our type definition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can create our data property in our &lt;code&gt;ToDo.ts&lt;/code&gt; component. Import the type into our component...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/types/Task&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;p&gt;...and then add the following property to the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In order to see the results on the page, we need to render them using a &lt;code&gt;v-for&lt;/code&gt; loop. Here you can see I have updated the template within the &lt;code&gt;to-do.html&lt;/code&gt; template to output each task item in an unordered list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;My To-Do App!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;to-do-form&amp;gt;&amp;lt;/to-do-form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"task in tasks"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;:checked=&lt;/span&gt;&lt;span class="s"&gt;"task.completed"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{ task.description }}&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For now, let's hard-code some tasks so we know that it is working. Update the tasks property in the &lt;code&gt;ToDo.ts&lt;/code&gt; component to have some items in the array by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Make Coffee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Feed Dragons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You should now see those tasks being rendered on the page. Good job!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating New Tasks
&lt;/h2&gt;

&lt;p&gt;So we now have a form and a way of displaying the current tasks on the page. Next, we need to actually add the functionality so that when a user adds a task in the form it updates the data property.&lt;/p&gt;

&lt;p&gt;To do this we will first need to edit our &lt;code&gt;ToDoForm.ts&lt;/code&gt; component. We need to use &lt;code&gt;v-model&lt;/code&gt; so that we can capture the input with data binding. Within your &lt;code&gt;ToDoForm.ts&lt;/code&gt; file, add a new property called task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&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;p&gt;Now update the &lt;code&gt;to-do-form.html&lt;/code&gt; template so that the input field has &lt;code&gt;v-model&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter task..."&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"task"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Task&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Great, we now have a way of capturing the user input. Next, we need to ensure that when the "Add Task" button is clicked, we emit an event to the parent component. Let's add an event listener to the form tag within our template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit.prevent=&lt;/span&gt;&lt;span class="s"&gt;"emitTask"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter task..."&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"task"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Task&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, we need to create the &lt;code&gt;emitTask&lt;/code&gt; method on in our &lt;code&gt;ToDoForm.ts&lt;/code&gt; component. Simply add a new method to the class. Within this method we want to emit a new event, passing the value entered in the form. We then want to reset the value ready for the next input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;emitTask&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;added&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have an event emitting, we can listen for this event in our parent component. First, let's add an event listener to the component in our &lt;code&gt;to-do.html&lt;/code&gt; template file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;to-do-form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;added=&lt;/span&gt;&lt;span class="s"&gt;"addTask"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we need to create the listener. Add a new method to the &lt;code&gt;ToDo.ts&lt;/code&gt; class called &lt;code&gt;addTask&lt;/code&gt;. In this method, we want to push a new item to the tasks property with the description from the event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;addTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now you are ready to check it out in the browser. You should now be able to add a new task, submit the form and see it added to the list below.&lt;/p&gt;

&lt;h2&gt;
  
  
  What About Props?
&lt;/h2&gt;

&lt;p&gt;So far I have shown how to use child components, data properties, and events. But you'll commonly have to use props in any real-world use case.&lt;/p&gt;

&lt;p&gt;Let's add a new feature so that we can easily customise the text of the form button. We want to be able to pass the value through a prop called &lt;code&gt;button-text&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Firstly, we'll update the template so we are passing a prop through to the child component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;to-do-form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;added=&lt;/span&gt;&lt;span class="s"&gt;"addTask"&lt;/span&gt; &lt;span class="na"&gt;button-text=&lt;/span&gt;&lt;span class="s"&gt;"Create Task"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The next thing we need to do is accept the prop in our child component. In order to do this, we are going to use another decorator, &lt;code&gt;@Prop&lt;/code&gt;. Update the import statement within our &lt;code&gt;ToDoForm.ts&lt;/code&gt; file so that we can use the decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Prop&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&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;p&gt;Now we can go ahead and use it. Add the decorator to the class to accept the prop. Your &lt;code&gt;ToDoForm.ts&lt;/code&gt; file should now look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Prop&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;WithRender&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./to-do-form.html&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="nd"&gt;WithRender&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;ToDoForm&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;buttonText&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;emitTask&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;added&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="o"&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll notice that for the prop decorator, we are declaring the type twice. Let me explain just a little what is going on here. The first time we specify it, we are passing it as a parameter to the decorator. This is for Vue's type checking. This is similar to how you would declare the property in the following way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;buttonText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We also specify the type at the end of the property. This is for TypeScript's type checking.&lt;/p&gt;

&lt;p&gt;We should now be able to update our &lt;code&gt;to-do-form.html&lt;/code&gt; template to reference the property as opposed to a hard-coded value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit.prevent=&lt;/span&gt;&lt;span class="s"&gt;"emitTask"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter task..."&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"task"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ buttonText }}&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;However, what if we don't pass through a property? You'll notice that we will just get an empty button. Let's add a default just to be safe. In order to do this, we need to pass more information to the &lt;code&gt;@Prop&lt;/code&gt; decorator. As we are already providing the type, we instead need to pass in an object so that we can configure multiple options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Add Task&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;buttonText&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That is all there is to it. We now have a default value for the button text if we don't provide one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This has been somewhat of a lengthy article, but I hope it has been useful. We have looked at how we can use child components, data properties, events, and props.&lt;/p&gt;

&lt;p&gt;If you have any questions at all, please feel free to get in touch and I'll do my best to answer them.&lt;/p&gt;

&lt;p&gt;If you would like to view the code for this, I have pushed it to a git repository. You can find it here - &lt;a href="https://github.com/georgehanson/vue-todo-typescript"&gt;https://github.com/georgehanson/vue-todo-typescript&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Homework
&lt;/h2&gt;

&lt;p&gt;If you fancy it, here is a little task for you to do.&lt;/p&gt;

&lt;p&gt;Firstly fork the repository. Next add a feature so that you can mark the task as complete. But rather than using &lt;code&gt;v-model&lt;/code&gt;, make each task it's own component and use events.&lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vue</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
    <item>
      <title>My Top 3 JavaScript Array Methods</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Sun, 21 Apr 2019 15:30:45 +0000</pubDate>
      <link>https://forem.com/georgehanson/my-top-3-javascript-array-methods-5co9</link>
      <guid>https://forem.com/georgehanson/my-top-3-javascript-array-methods-5co9</guid>
      <description>&lt;p&gt;JavaScript is a super versatile language. I love it and it really has come a long way over recent years. With JavaScript, we can now build powerful single page applications and when building these applications you will at some point or another use arrays.&lt;/p&gt;

&lt;p&gt;I love arrays, here are my top three JavaScript methods that I use on a regular basis.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Array Filter
&lt;/h2&gt;

&lt;p&gt;This is actually a method that was added back in ES5, but it is still a method that I use on a regular basis. Array filter allows us to basically do what it says on the tin. Filter an array to a subset based on rules that we provide.&lt;/p&gt;

&lt;p&gt;To do this, you simply call the filter method on the array and pass it a callback. For example in this array, I am filtering the results to only return objects where the age is less than 18.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Daenerys&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;﻿Arya&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Returns [ { name: 'Arya', age: 17} ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Array Find
&lt;/h2&gt;

&lt;p&gt;This is something that was added to the ES6 specification. It is similar to the array filter method, but it instead returns us the first result from the filtered array.&lt;/p&gt;

&lt;p&gt;For this method again we pass it a callback, containing the rules for our filter. It will then filter the results and return us the first item in the subset. In this case, I want to find the first adult in the array of people.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="err"&gt;﻿&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Daenerys&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;﻿Arya&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;adult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Returns { name: 'Jon', age: 23 }&lt;/span&gt;

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



&lt;p&gt;You'll notice that this time it returns the object, as opposed to an array containing the object.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Array ForEach
&lt;/h2&gt;

&lt;p&gt;The forEach method is one that was introduced back in ES5 and therefore has ample browser support. However, I do still see code where people are not using this and are instead using a for loop.&lt;/p&gt;

&lt;p&gt;The forEach method does exactly what you think, it loops over each item in the array for you to run a callback on. This is similar to the map method, but there is one key difference. When you use array map, it returns a new array based on the callback you have passed it. Whereas with the forEach method it returns nothing.&lt;/p&gt;

&lt;p&gt;Both the map and forEach methods have their use cases. But if I am not intending on manipulating the array I will generally reach for the forEach method.&lt;/p&gt;

&lt;p&gt;In the example below I am simply calling the forEach method on the array and passing the object to a custom function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="err"&gt;﻿&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Daenerys&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;﻿Arya&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sendNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There you go, there are my three favourite array methods. Don't get me wrong there are plenty of other array methods that are really useful and I implore you to look them up. But these are three of my favourites and the three I most commonly use.&lt;/p&gt;

&lt;p&gt;Do you have any different array methods that you frequently use? Be sure to let me know.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I'm a R&amp;D Developer. Ask me anything!</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Sat, 20 Apr 2019 18:02:39 +0000</pubDate>
      <link>https://forem.com/georgehanson/i-m-a-r-d-developer-ask-me-anything-1l44</link>
      <guid>https://forem.com/georgehanson/i-m-a-r-d-developer-ask-me-anything-1l44</guid>
      <description>&lt;p&gt;I recently got promoted within my company from a Full Stack Developer to R&amp;amp;D Developer. &lt;/p&gt;

&lt;p&gt;Ask me anything!&lt;/p&gt;

</description>
      <category>ama</category>
    </item>
    <item>
      <title>Turbocharge JavaScript strings with Template Literals</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Fri, 19 Apr 2019 15:25:39 +0000</pubDate>
      <link>https://forem.com/georgehanson/turbocharge-javascript-strings-with-template-literals-jj</link>
      <guid>https://forem.com/georgehanson/turbocharge-javascript-strings-with-template-literals-jj</guid>
      <description>&lt;p&gt;Anyone who has been writing JavaScript for a long time will know it has come on leaps and bounds. ES6 has been out for a while now, but there are still a lot of features that I see developers either forgetting or not realising they exist.&lt;/p&gt;

&lt;p&gt;Today I'm going to show one of my personal favourites, template literals!&lt;/p&gt;

&lt;h2&gt;
  
  
  Before ES6
&lt;/h2&gt;

&lt;p&gt;In the old-un days back when we used to use jQuery for absolutely everything, string concatenation was fairly limited. If we wanted to construct a string it got messy, quite quickly. Here is an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;George&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;England&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;sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi, my name is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;. I am &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; years old and I live in &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;While this works, it looks messy. If something can be tidied up and made more readable, personally I think it is worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  After ES6
&lt;/h2&gt;

&lt;p&gt;When ES6 arrived it brought a bunch of features with it. Template literals allow you to easily construct these strings without making the concatenation look too messy.&lt;/p&gt;

&lt;p&gt;Let's take the same example above. How might we do this using ES6 template literals? Well, it is very simple. Below is how we would do the exact same thing but in a more readable way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;George&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;England&lt;/span&gt;&lt;span class="dl"&gt;'&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;sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Hi, my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old and I live in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see with template literals we no longer have to use quotes or &lt;code&gt;+&lt;/code&gt; operators to concatenate the string. Instead, we can just use &lt;code&gt;${&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt;. I feel like this is a really nice improvement.&lt;/p&gt;

&lt;p&gt;In order to use template literals, you'll notice that we use back-ticks rather than quotes. This is also useful because it means we no longer need to escape quotation marks in the string. For example, without using template literals we would have to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello! I&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;m pleased to meet you!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But with template literals, we aren't using quotation marks to denote a string. So we can just include them without having to escape them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Hello! I'm pleased to meet you!`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One final point I'll make, you can also evaluate expressions within template literals. For example, if I wanted to double the person's age I could write this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Hi, my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&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="s2"&gt; years old and I live in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I hope you find this useful, I find myself using template literals all of the time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was originally posted here: &lt;a href="https://www.georgehanson.co.uk/code-tips/es6-javascript-tips-template-literals"&gt;https://www.georgehanson.co.uk/code-tips/es6-javascript-tips-template-literals&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Doing What Makes You Happy</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Thu, 18 Apr 2019 23:00:55 +0000</pubDate>
      <link>https://forem.com/georgehanson/doing-what-makes-you-happy-26p0</link>
      <guid>https://forem.com/georgehanson/doing-what-makes-you-happy-26p0</guid>
      <description>&lt;p&gt;I wrote my first line of code when I was 9. In most industries starting that early would be unusual. Yet in the tech industry this is actually quite common.&lt;/p&gt;

&lt;p&gt;So why is this? It is simply because we have a passion for it.&lt;/p&gt;

&lt;p&gt;When you are 9 years old, you're not doing it for money, popularity or anything self indulgent other than the amazement of seeing something you have created out of nothing. Even if it is just a blue box on a webpage. That hit if dopamine still tells you it's the coolest thing ever.&lt;/p&gt;

&lt;p&gt;But as we get older and step out into the real world we find all sorts of external pressures. Rent to pay, food to put on the table - the list goes on.&lt;/p&gt;

&lt;p&gt;For most people the dream is to have passive income. Be able to build something and earn money from it, rather than selling your time. It gives you the freedom to work on those projects you think are cool and that you enjoy, rather than working out of necessity.&lt;/p&gt;

&lt;p&gt;This is where so many developers get into the SaaS mindset. Software as a service can lucrative. So why not? The issue is coming up with an idea. &lt;/p&gt;

&lt;p&gt;You search around for SaaS ideas. What industries have a gap for a niche app? You find one and start building. Full of passion and positive mentality.&lt;/p&gt;

&lt;p&gt;Some people will succeed at this, but quite a few wont. That's because it all goes back to the 9 year old self making a box blue on the screen. After spending a significant amount of time on just setting up the project you begin to lose interest and motivation. You don't find the project enjoyable because you don't have that passion to see it through.&lt;/p&gt;

&lt;p&gt;It is not because you lack passion in coding, it is because you lack passion in the product you are building.&lt;/p&gt;

&lt;p&gt;This won't apply to everybody, but I know for me it does. &lt;/p&gt;

&lt;p&gt;This is how we end up with a bunch of unfinished side projects.&lt;/p&gt;

&lt;p&gt;Because of this, I am now putting that time and energy from trying to build SaaS apps to doing those things that give me the dopamine hit. For me, it is helping people and creating resources.&lt;/p&gt;

&lt;p&gt;So I aim to be a lot more active on a variety of channels. My website, DEV and Twitter to name a few.&lt;/p&gt;

&lt;p&gt;I'm going back to my 9 year old self and doing what is making me happy - and there's nothing wrong with that.&lt;/p&gt;

</description>
      <category>career</category>
      <category>personal</category>
      <category>advice</category>
    </item>
    <item>
      <title>Why Are Coding Standards Important?</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Thu, 18 Apr 2019 10:41:10 +0000</pubDate>
      <link>https://forem.com/georgehanson/why-are-coding-standards-important-49dp</link>
      <guid>https://forem.com/georgehanson/why-are-coding-standards-important-49dp</guid>
      <description>&lt;p&gt;Almost every language has a set of standards that developers advocate. Off the top of my head and coming from a PHP background, PSR standards spring to mind. These standards are essentially a set of rules on how you should name your files, variables, classes and even non-naming issues such as line length.&lt;/p&gt;

&lt;p&gt;But why are these standards important? I mean if it works isn’t that the main thing? Why do I have to follow these strict rules that tell me how I should code!?&lt;/p&gt;

&lt;p&gt;Well, hang on a minute let’s put the brakes on. Coding standards are important, but it is important to know &lt;strong&gt;why&lt;/strong&gt; you should be doing them, rather than just following them because you feel like you should.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are coding standards important?
&lt;/h2&gt;

&lt;p&gt;Coding standards are there for a reason. They are designed to try and make the code you write as maintainable as possible. I want to especially emphasise this if you are working within a team. If you are all following the same set of rules on how you should write your code, it is far easier for other developers to understand it, contribute to it and to help maintain it.&lt;/p&gt;

&lt;p&gt;But it is not just for those within teams.&lt;/p&gt;

&lt;p&gt;It is also important if you are working solo. Even if it is a project that will never be shared with anyone. By consistently following these standards, if you stop working on a project and come back to it 6 months later it will be far easier to understand the code instead of having to spend hours or even days reading the code trying to understand what is happening.&lt;/p&gt;

&lt;p&gt;Having knowledge and experience in coding standards is also beneficial for getting hired. Companies like to know that the code you write can easily be maintained by other developers in the team. Or if you were to leave, that another developer could come along and understand what you are doing.&lt;/p&gt;

&lt;p&gt;Coding standards aren’t there to be a hurdle you have to jump over. They are there to stop the headache down the road. If you start using them, it will become muscle memory and you won’t even realise you are doing it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was originally posted here: &lt;a href="https://www.georgehanson.co.uk/blog/why-coding-standards-are-important"&gt;https://www.georgehanson.co.uk/blog/why-coding-standards-are-important&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>codequality</category>
      <category>career</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Code Tip: Avoid unnecessary else statements</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Wed, 23 Jan 2019 16:21:27 +0000</pubDate>
      <link>https://forem.com/georgehanson/code-tip-avoid-unnecessary-else-statements-2jie</link>
      <guid>https://forem.com/georgehanson/code-tip-avoid-unnecessary-else-statements-2jie</guid>
      <description>&lt;p&gt;When writing code it is easy to think in a logical way. With conditionals, people often write it as they would think it. If this condition is true then return this value, otherwise return a different value.&lt;/p&gt;

&lt;p&gt;However there is a trap that people often fall into and one simple refactor can make the code more readable. If you have this conditional within a method or function that is returning a value, you can often just remove the else condition because if the condition is true it would never hit it in the first place.&lt;/p&gt;

&lt;p&gt;Consider the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getName&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is a perfect example for refactoring.&lt;/p&gt;

&lt;p&gt;You will notice that if the user has a first and last name, we return it. Otherwise we just return their first name.&lt;/p&gt;

&lt;p&gt;However the else condition is redundant because we are already returning a value if the condition evaluates to true.&lt;/p&gt;

&lt;p&gt;Therefore we can refactor this method to remove the else statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getName&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By doing this, it removes a level of indentation which makes the code more readable. It's a useful tip to remember and one that I find applying all over the place.&lt;/p&gt;

&lt;p&gt;Originally Posted on &lt;a href="https://www.georgehanson.co.uk/code-tips/code-tip-avoid-unnecessary-else-statements"&gt;George Hanson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tips</category>
    </item>
    <item>
      <title>What are your favourite podcasts?</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Wed, 21 Nov 2018 13:22:44 +0000</pubDate>
      <link>https://forem.com/georgehanson/what-are-your-favourite-podcasts-3pmn</link>
      <guid>https://forem.com/georgehanson/what-are-your-favourite-podcasts-3pmn</guid>
      <description>&lt;p&gt;Many of us developers listen to podcasts, what are your favourites? It doesn't have to be specifically "dev" related :)&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>To be a software engineer or developer, do you still need a degree?</title>
      <dc:creator>George Hanson</dc:creator>
      <pubDate>Mon, 01 Oct 2018 12:27:46 +0000</pubDate>
      <link>https://forem.com/georgehanson/to-be-a-software-engineer-or-developer-do-you-still-need-a-degree-27gp</link>
      <guid>https://forem.com/georgehanson/to-be-a-software-engineer-or-developer-do-you-still-need-a-degree-27gp</guid>
      <description>&lt;p&gt;Many companies and organisations are starting to relax their hiring criteria and don't require employees to have degrees - yet some are still very strict on this. Do you think that a degree is &lt;strong&gt;still&lt;/strong&gt; needed to make it as a software engineer or a developer? Discuss.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
