<?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: Vincent Tong</title>
    <description>The latest articles on DEV Community by Vincent Tong (@vkton115).</description>
    <link>https://dev.to/vkton115</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%2F815465%2F24343590-bedc-436f-8f94-2e34c0e173d3.jpeg</url>
      <title>DEV Community: Vincent Tong</title>
      <link>https://dev.to/vkton115</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vkton115"/>
    <language>en</language>
    <item>
      <title>TypeScript: Advanced Types</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Mon, 15 Aug 2022 00:28:00 +0000</pubDate>
      <link>https://dev.to/vkton115/typescript-advanced-types-2lpn</link>
      <guid>https://dev.to/vkton115/typescript-advanced-types-2lpn</guid>
      <description>&lt;p&gt;In this blog we're going to deep dive into some of the more advanced built-in types included in TypeScript. If you are new to TypeScript I recommend starting with some of my beginner tutorial blogs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/vkton115/easy-start-guide-typescript-3ip4"&gt;TypeScript: Easy Start Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/vkton115/typescript-standard-built-in-types-485c"&gt;TypeScript: Basic Types&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Type Aliases
&lt;/h2&gt;

&lt;p&gt;In our last lesson we created this TypeScript object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;contactInfo&lt;/span&gt;&lt;span class="p"&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="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;fax&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;number&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="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;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="nx"&gt;_456_7890&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 great but it poses a few problems for us:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt;If we want to create a new contact info object, we would have to repeat this structure:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; The other contact info object may have other properties so the shape may vary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; The overall structure may be difficult to interpret at a glance.&lt;/p&gt;

&lt;p&gt;This is where Type Aliases come in handy to create &lt;strong&gt;custom&lt;/strong&gt; types. To do this, initiate the keyword 'type' followed by the name of your object in Pascal case (first letter in each word uppercased) like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ContactInfo&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="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;fax&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;number&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 the structure defined in our alias, we can remove it from our previous object and create a new object with our new custom typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myContactInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ContactInfo&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="s2"&gt;Vincent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="nx"&gt;_456_7890&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;h2&gt;
  
  
  Unions
&lt;/h2&gt;

&lt;p&gt;Unions are a fairly simple concept. You can use them to give additional typings to variables or function parameters. This is done with the "|" character:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Breaking it down, what this function is saying is that it takes one argument that can either be a number, or a string. While the above function can accept either, there is a possibilty that it may not return a number as required (when you add a string to a number, the result is a string).&lt;/p&gt;

&lt;p&gt;note: In the previous blog we talked about Code Completion and how it is one of the benefits TypeScript provides us. However, when we use Unions like in this example, the only methods we will be able to see are the methods that are shared by both &lt;em&gt;strings&lt;/em&gt; and &lt;em&gt;numbers&lt;/em&gt;:&lt;/p&gt;

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

&lt;p&gt;So within our function we can add some conditional logic to clear the air:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addTwo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&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="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="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="nf"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This process of using conditional logic to find out the typing of the argument is what is known as &lt;strong&gt;Type Narrowing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And now with &lt;strong&gt;inference&lt;/strong&gt; TypeScript will know that num in the first condition will be a number type and num in the 'else' condition must be a string and therefore, the respective type methods will be made available once again with code completion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intersections
&lt;/h2&gt;

&lt;p&gt;The concept of intersections types are similar to unions. However, instead of allowing the value to be passed in to be one type OR the other, it allows the variable to be both types at the same time. Our previous example would not be the best way to show this as an object cannot be both a number AND a string at the same time, but lets try it with some custom typings.&lt;/p&gt;

&lt;p&gt;Imagine if we are creating simple video game entity.&lt;br&gt;
For some entities we want them to be able to move only left or right like a goomba in the Mario games!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk2e34d81mj67mw0sde2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk2e34d81mj67mw0sde2.png" alt="goomba"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;note this is not necessarily how the actual video game entities were coded but just a visual analogy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For others we may want them to be able to move up and down like the piranha plant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl57z31owdwi1zud2b1z1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl57z31owdwi1zud2b1z1.png" alt="piranha plant"&gt;&lt;/a&gt;&lt;br&gt;
our custom types might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;LeftAndRight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;moveLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;moveRight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UpAndDown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="na"&gt;moveUp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="na"&gt;moveDown&lt;/span&gt;&lt;span class="p"&gt;:()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if we wanted an entity that can go both left &amp;amp; right AND up &amp;amp; down like the flying koopa troopa.&lt;/p&gt;

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

&lt;p&gt;To make a custom type that has the attributes of already existing/custom types that we created, we can use the '&amp;amp;' symbol like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;UpDownLeftAndRight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;LeftAndRight&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;UpAndDown&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// and now we can create a variable of that combined type&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;flyingKoopaTroopa&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UpDownLeftAndRight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;moveLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;moveRight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;moveUp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;moveDown&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;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;h2&gt;
  
  
  Literal Types
&lt;/h2&gt;

&lt;p&gt;We learned that with TypeScript we can assign variables to specific data types like strings. But we can also specify specific strings by assigning the 'type' to the specific string like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;CoinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;heads&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tails&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//here we are creating a custom type that can only be of two values&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstFlip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CoinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;heads&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//this is ok&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;secondFlip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CoinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tails&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//this is also ok&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;thirdFlip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CoinFlip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a crow took it&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//this is not ok&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Nullable Types
&lt;/h2&gt;

&lt;p&gt;By default TypeScripts configuration does not allow for null types when assigning variables to specific types. However, if you wish to allow for a variable to be null, you can specify it with the union operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="c1"&gt;//we are saying that greeting can be either a string or null&lt;/span&gt;
&lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="c1"&gt;// this is ok&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!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// this is also ok&lt;/span&gt;
&lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="c1"&gt;// error&lt;/span&gt;

&lt;span class="c1"&gt;// if you wish to also specify that greeting can also be undefined, you would need to add another union to include 'undefined' types&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you are now an expert on TypeScript types! I hope this post has been informative and will save you plenty of debugging time in the future.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>tutorial</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>TypeScript: Standard Built-in Types</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 07 Aug 2022 23:56:00 +0000</pubDate>
      <link>https://dev.to/vkton115/typescript-standard-built-in-types-485c</link>
      <guid>https://dev.to/vkton115/typescript-standard-built-in-types-485c</guid>
      <description>&lt;p&gt;Welcome to my second lesson on TypeScript where we'll go more in depth with the built in 'types' that TypeScript includes. If you are new to TypeScript, you should read my initial TypeScript introduction and setup blog here: &lt;a href="https://dev.to/vkton115/easy-start-guide-typescript-3ip4"&gt;https://dev.to/vkton115/easy-start-guide-typescript-3ip4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;similarly to how javascript has built in types such as &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;numbers&lt;/li&gt;
&lt;li&gt;strings&lt;/li&gt;
&lt;li&gt;booleans&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;objects&lt;/li&gt;
&lt;li&gt;functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TypeScript introduces some of its own built-in types such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;any&lt;/li&gt;
&lt;li&gt;unknown&lt;/li&gt;
&lt;li&gt;never&lt;/li&gt;
&lt;li&gt;enum&lt;/li&gt;
&lt;li&gt;tuple&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inference:&lt;/p&gt;

&lt;p&gt;In the last lesson, we learned that we can initialize variables as specific types like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this creates a variable with the type of a number set to the value of 123. Because we specified that it was a number, it cannot be reassigned to a different datatype, like a boolean or a string for example.&lt;/p&gt;

&lt;p&gt;However, due to inference, we can also write the same login in our TypeScript file as:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will achieve the same result and the same variable will not be able to be reassigned to a different datatype. While this does look similar to typing regular JavaScript, the TypeScript compiler will be sure to catch any incorrect reassignments of the variable. There may be some niche situations in which you'd want the variable created to have flexible value types. In these cases, you'd want to utilize &lt;strong&gt;any&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  ANY
&lt;/h2&gt;

&lt;p&gt;The any typing can be implemented one of two ways. By declaring a variable without assigning it to an inferred value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&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;10&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;ten&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//this will work because age was not given a specified type when declared.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way to set a typing to any would be similar to setting it to any other type, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;ten&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;However, using the 'any' typing goes against what the main functionality of TypeScript. It's merely kept as an option to allow users the ability to declare free-type variables for specific situations where specific typing may not be important or 'code-breaking'.&lt;/p&gt;

&lt;h2&gt;
  
  
  ARRAYS
&lt;/h2&gt;

&lt;p&gt;In JavaScript, individual elements in an array can be of different types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;strings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To specify what type of values the individual elements should be with TypeScript, the format would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// this will work because every value in the array is already a number&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// this won't work because '20' is a string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With inference, the acceptable element types will be whatever types are already present in the array when assigned&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbersAndStrings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// this infers that both numbers and strings can exist in this aray&lt;/span&gt;
&lt;span class="nx"&gt;numbersAndStrings&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// this will work&lt;/span&gt;
&lt;span class="nx"&gt;numbersAndStrings&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// this will error because booleans were not inferred&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;similarly to how to set a primitive value to an 'any' type, TypeScript arrays can accept any values by initializing it as an empty array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;anyType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="nx"&gt;anyType&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//this works&lt;/span&gt;
&lt;span class="nx"&gt;anyType&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// this also works&lt;/span&gt;
&lt;span class="nx"&gt;anyType&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// this works too&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CODE COMPLETION
&lt;/h2&gt;

&lt;p&gt;Before we move onto more built-in types, let's talk about one of the key benefits to using TypeScript: &lt;strong&gt;Code Completion.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given a TypeScript Array like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;//inference makes it so all elements are presumed to be numbers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because TypeScript should now know what type of data each element in the array is, it knows what methods we should have access to. So if we were to iterate through this array, we will receive a list of methods that can be applied to each element after using dot notation like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FgNDgVJv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vc0zuoufyljtbsw3mbvh.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FgNDgVJv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vc0zuoufyljtbsw3mbvh.JPG" alt="CC" width="688" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having this feature is convenient and is one of the ways TypeScript helps with productivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  TUPLES
&lt;/h2&gt;

&lt;p&gt;Tuples are essentially fixed length TypeScript arrays in which you can specify the type of data that each element index should be. The syntax for TypeScript tuples are as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does a couple of things for us:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Tuples make it so we cannot assign the variable to an array of different size than the defined array length.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;male&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// error: target only allows for 2 elements&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// error: target requires 2 elements;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;note: using push/pop/shift/unshift methods seems to allow us to bypass this and add/remove values in the array. The reasons for this is unknown to me but at the moment it seems to be a lapse in TypeScripts functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Using Tuples also allows us to set the datatype of specific elements in an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twenty-seven&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;//error index 1 cannot be a string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is usually best practice to keep the size of the tuples to a minimum (2 elements is usually recommended similar to key-value pair) as it may get harder to distinguish what each value may represent.&lt;/p&gt;

&lt;h2&gt;
  
  
  ENUMS
&lt;/h2&gt;

&lt;p&gt;Enums(short for enumerated) are a data type that includes values which are predefined. In TypeScript it is initialized with the keyword 'enum':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;Alphabet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the first item in the brace's value is set to 0, and each value following it's value will be incremented by 1 so:&lt;br&gt;
a = 0&lt;br&gt;
b = 1&lt;br&gt;
c = 2&lt;/p&gt;

&lt;p&gt;You can specify the value of specific item(s) but note that any follow items values will increment by one by default unless otherwise specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;Alphabet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Alphabet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Alphabet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Alphabet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;// 21&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Alphabet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Alphabet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//20 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;note: adding const to the beginning of the enum declaration will generate a more optimized and cleaner looking code when you run the compiler.&lt;/p&gt;

&lt;h2&gt;
  
  
  FUNCTIONS
&lt;/h2&gt;

&lt;p&gt;When it comes to functions, annotating your parameters is important to ensure arguments passed in are of the correct typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;incrementer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;incrementer&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;Here we are declaring a function named count. its parameters, start and incrementer are both assigned to number types and therefore if you tried to pass in a non-number argument to the count function, you will receive an error.&lt;/p&gt;

&lt;p&gt;If you wish to set optional parameters in TypeScript there are two ways.&lt;br&gt;
&lt;strong&gt;1.&lt;/strong&gt; Using default values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;incrementer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;incrementer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; returns 3 (2 + 1)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Using '?'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;incrementer&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;incrementer&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; returns 3 (2 + 1);&lt;/span&gt;
&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; returns 4 (2 + 2);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because incrementer could possibly be undefined, we needed to create a condition to handle that case, hence why we set it to 1.&lt;/p&gt;

&lt;p&gt;Also note that due to inference, TypeScript knows that the return value will always be a number type. However, in a function in other cases you may want to specify what type of value your return should be, like this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;returnNumber&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="c1"&gt;//this will work&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;returnNumber&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;7&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="c1"&gt;//this won't work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;related configs:&lt;br&gt;
&lt;strong&gt;noUnusedParameters&lt;/strong&gt; - when set to true, if a parameter is never used within a function, it will show an error.&lt;br&gt;
&lt;strong&gt;noImplicitReturns&lt;/strong&gt; - when set to true, it will error if a function has a code path that does not explicitly return in a function.&lt;br&gt;
&lt;strong&gt;noUnusedLocals&lt;/strong&gt; - when set to true, it will error if there are any unused variables. This includes variables declared within functions.&lt;/p&gt;
&lt;h2&gt;
  
  
  OBJECTS
&lt;/h2&gt;

&lt;p&gt;When it comes to JavaScript objects, we're accustomed to being able to add properties with dot/bracket notation like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nx"&gt;obj&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;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;obj&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;27&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// {name: Vincent, age, 27}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, in TypeScript, we need to define the body of the object before we can change its properties as we will not be able to add/change properties that do not match the object that we defined.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;contactInfo&lt;/span&gt;&lt;span class="p"&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="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nx"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nx"&gt;fax&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;number&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="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;Vincent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="nx"&gt;_456_7890&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;note: numbers in TypeScript can be split with an underscore(_) to segment it&lt;/p&gt;

&lt;p&gt;As you can see, we initially defined the structure and typing of each key's value in the body of the object. The fax is set to optional with the '?' so therefore we do not need to include it when we assign the initial value of the object. Using the '?' is generally not recommended as it can cause unforeseen errors when compiling, however in this case it makes sense as not every person may have a fax machine.&lt;/p&gt;

&lt;p&gt;And finally since we defined the types of each key's value, they can be reassigned as long as they are being reassigned to the same datatype.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;contactInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;987&lt;/span&gt;&lt;span class="nx"&gt;_654_3210&lt;/span&gt; &lt;span class="c1"&gt;// this is an ok reassignment&lt;/span&gt;
&lt;span class="nx"&gt;contactInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;(123)-456-7890&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;//this won't work because it expects a number and not a string.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;Thank you for taking the time out to read this TypeScript tutorial. I hope I was able to help you understand the standard built-in types that TypeScript provides. Stay tuned for more information on more advanced types.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Easy Start Guide: TypeScript</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 31 Jul 2022 21:29:00 +0000</pubDate>
      <link>https://dev.to/vkton115/easy-start-guide-typescript-3ip4</link>
      <guid>https://dev.to/vkton115/easy-start-guide-typescript-3ip4</guid>
      <description>&lt;p&gt;Before we dive in to TypeScript here are the fundamental concepts you should be familiar with the following JavaScript concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Arrays/Objects/Functions&lt;/li&gt;
&lt;li&gt;Arrow Functions&lt;/li&gt;
&lt;li&gt;Destructuring&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is TypeScript?
&lt;/h2&gt;

&lt;p&gt;Created by Microsoft, this programming language overcomes some of the challenges of working with Javascript. It is built ontop of Javascript and therefore all Javascript files are technically a TypeScript file.&lt;/p&gt;

&lt;p&gt;On a basic level, TypeScript allows you to set variables so that they can only be assignable to a specific datatype.&lt;/p&gt;

&lt;p&gt;You can think of plain vanilla JavaScript is the &lt;em&gt;script&lt;/em&gt; that tells us what will happen in the play. TypeScript assigns roles (type classification) to the individual actors (variables that we create) so that they know what part they have to play. And if all goes well, our application will perform wonderfully and we may even get a standing ovation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dt0hi-tM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgsi9s1b3u7uqxiq67ng.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dt0hi-tM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgsi9s1b3u7uqxiq67ng.gif" alt="standing O" width="220" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you &lt;strong&gt;SHOULD&lt;/strong&gt; use it
&lt;/h2&gt;

&lt;p&gt;Type Script grants us some convenient benefits such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static Typing: the ability to set a variable's &lt;strong&gt;TYPE&lt;/strong&gt; and therefore not allow it to be assigned a value of any other type. Some examples of programming languages that use static typing are: C++, C#, Java. Plain Javascript on the other hand, along with Python and Ruby, use Dynamic Typing, meaning that a variable can be reassigned to a variety of different types of data.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Static Typing (C++/C#/Java)&lt;/span&gt;
&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This is fine&lt;/span&gt;
&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;abc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// this will error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Dynamic Typing (JavaScript, Python, Ruby)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// this works&lt;/span&gt;
&lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// this will also work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;TypeScript compilation allows for us to find errors in our typescript at compile time as opposed to when we run our application or unit tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Shorthand notations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Features not available or not yet available in plain JavaScript that allows us to write cleaner, more efficient code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Most code editors nowadays have support for typescript which enables us even more benefits such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code Completion&lt;/li&gt;
&lt;li&gt;Refactoring&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why you &lt;strong&gt;SHOULDN'T&lt;/strong&gt; use it
&lt;/h2&gt;

&lt;p&gt;Browser's inherently do not know how to read TypeScript. Therefore, a transpile process is required to convert your TypeScript code into a browser-readable JavaScript code. However, this process can become especially tedious if you're only working on small and simple components. Therefore it is not typically recommended to use TypeScript in that situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  When should you use it?
&lt;/h2&gt;

&lt;p&gt;Simply put, TypeScript's benefits are more apparent when working on medium to large projects and/or with a team of developers to ensure they and yourself don't have any unexpected problems when running your program.&lt;/p&gt;

&lt;p&gt;Plain vanilla JavaScript is best when you want to keep your projects simple and finish it in an efficient timeframe.&lt;br&gt;
How to use it&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started with TypeScript
&lt;/h2&gt;

&lt;p&gt;In your code editor's terminal, you'll use your node package manager (or npm) to install typescript globally by running the command:&lt;br&gt;
&lt;code&gt;npm i -g typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the installation is complete you can verify the installyation by running: &lt;br&gt;
&lt;code&gt;tsc -v&lt;/code&gt; and you should receive a response back with the version number.&lt;/p&gt;

&lt;p&gt;After verifying that you have type script installed, you can start writing your first TypeScript program by creating a .ts file.&lt;/p&gt;

&lt;p&gt;Inside of this new file you can write any JavaScript code and it will be valid TypeScript code. &lt;br&gt;
example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The syntax is very similar to plain JavaScript but you'll notice a difference with the colon. This denotes the typing of the variable age. &lt;br&gt;
If you were to try to reassign this value to something other than another number you will get an error. &lt;/p&gt;

&lt;p&gt;Now that we have a single line of TypeScript code, we can run the command: 'tsc ' in order to run our compiler and transpile our .ts file into a .js file. &lt;/p&gt;

&lt;p&gt;You should see the new .js file now and inside of it would look something like this:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;As you can see, the code you wrote in TypeScript has now been translated into plain javascript. However, by default the TypeScript compiler will set variables to var instead of let or const. If we wish to change this, we will have to make some configurations to our compiler.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONFIGURING THE TYPESCRIPT COMPILER
&lt;/h2&gt;

&lt;p&gt;To do this, run 'tsc --init' in your terminal. This will create a tsconfig.json file which you can modify to fit your needs. Below is a snippet of the TypeScript compiler configurations. You do not need to read all of the configurations, but as you can see it is well documented with what each configuration will do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;compilerOptions&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="cm"&gt;/* Visit https://aka.ms/tsconfig to read more about this file */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Projects */&lt;/span&gt;
    &lt;span class="c1"&gt;// "incremental": true,                              /* Save .tsbuildinfo files to allow for incremental compilation of projects. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "composite": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "tsBuildInfoFile": "./.tsbuildinfo",              /* Specify the path to .tsbuildinfo incremental compilation file. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "disableSourceOfProjectReferenceRedirect": true,  /* Disable preferring source files instead of declaration files when referencing composite projects. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "disableSolutionSearching": true,                 /* Opt a project out of multi-project reference checking when editing. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "disableReferencedProjectLoad": true,             /* Reduce the number of projects loaded automatically by TypeScript. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Language and Environment */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;target&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es2016&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                  &lt;span class="cm"&gt;/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "jsx": "preserve",                                /* Specify what JSX code is generated. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "experimentalDecorators": true,                   /* Enable experimental support for TC39 stage 2 draft decorators. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "reactNamespace": "",                             /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noLib": true,                                    /* Disable including any library files, including the default lib.d.ts. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "useDefineForClassFields": true,                  /* Emit ECMAScript-standard-compliant class fields. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "moduleDetection": "auto",                        /* Control what method is used to detect module-format JS files. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Modules */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;commonjs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                &lt;span class="cm"&gt;/* Specify what module code is generated. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "rootDir": "./",                                  /* Specify the root folder within your source files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "moduleResolution": "node",                       /* Specify how TypeScript looks up a file from a given module specifier. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "baseUrl": "./",                                  /* Specify the base directory to resolve non-relative module names. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "paths": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "typeRoots": [],                                  /* Specify multiple folders that act like './node_modules/@types'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "moduleSuffixes": [],                             /* List of file name suffixes to search when resolving a module. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "resolveJsonModule": true,                        /* Enable importing .json files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noResolve": true,                                /* Disallow 'import's, 'require's or '&amp;lt;reference&amp;gt;'s from expanding the number of files TypeScript should add to a project. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* JavaScript Support */&lt;/span&gt;
    &lt;span class="c1"&gt;// "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Emit */&lt;/span&gt;
    &lt;span class="c1"&gt;// "declaration": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "declarationMap": true,                           /* Create sourcemaps for d.ts files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "emitDeclarationOnly": true,                      /* Only output d.ts files and not JavaScript files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "sourceMap": true,                                /* Create source map files for emitted JavaScript files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "outFile": "./",                                  /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;outDir&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./dist&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                   &lt;span class="cm"&gt;/* Specify an output folder for all emitted files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "removeComments": true,                           /* Disable emitting comments. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noEmit": true,                                   /* Disable emitting files from a compilation. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "importHelpers": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "importsNotUsedAsValues": "remove",               /* Specify emit/checking behavior for imports that are only used for types. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "downlevelIteration": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "sourceRoot": "",                                 /* Specify the root path for debuggers to find the reference source code. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "mapRoot": "",                                    /* Specify the location where debugger should locate map files instead of generated locations. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "emitBOM": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "newLine": "crlf",                                /* Set the newline character for emitting files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "stripInternal": true,                            /* Disable emitting declarations that have '@internal' in their JSDoc comments. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noEmitHelpers": true,                            /* Disable generating custom helper functions like '__extends' in compiled output. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noEmitOnError": true,                            /* Disable emitting files if any type checking errors are reported. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "preserveConstEnums": true,                       /* Disable erasing 'const enum' declarations in generated code. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "declarationDir": "./",                           /* Specify the output directory for generated declaration files. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "preserveValueImports": true,                     /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Interop Constraints */&lt;/span&gt;
    &lt;span class="c1"&gt;// "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "allowSyntheticDefaultImports": true,             /* Allow 'import x from y' when a module doesn't have a default export. */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;esModuleInterop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                             &lt;span class="cm"&gt;/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;forceConsistentCasingInFileNames&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="cm"&gt;/* Ensure that casing is correct in imports. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Type Checking */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                      &lt;span class="cm"&gt;/* Enable all strict type-checking options. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied 'any' type. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "strictNullChecks": true,                         /* When type checking, take into account 'null' and 'undefined'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "strictFunctionTypes": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "strictBindCallApply": true,                      /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "strictPropertyInitialization": true,             /* Check for class properties that are declared but not set in the constructor. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noImplicitThis": true,                           /* Enable error reporting when 'this' is given the type 'any'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "useUnknownInCatchVariables": true,               /* Default catch clause variables as 'unknown' instead of 'any'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "alwaysStrict": true,                             /* Ensure 'use strict' is always emitted. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noUnusedLocals": true,                           /* Enable error reporting when local variables aren't read. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noUnusedParameters": true,                       /* Raise an error when a function parameter isn't read. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "exactOptionalPropertyTypes": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noImplicitReturns": true,                        /* Enable error reporting for codepaths that do not explicitly return in a function. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noFallthroughCasesInSwitch": true,               /* Enable error reporting for fallthrough cases in switch statements. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noUncheckedIndexedAccess": true,                 /* Add 'undefined' to a type when accessed using an index. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noImplicitOverride": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "noPropertyAccessFromIndexSignature": true,       /* Enforces using indexed accessors for keys declared using an indexed type. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "allowUnusedLabels": true,                        /* Disable error reporting for unused labels. */&lt;/span&gt;
    &lt;span class="c1"&gt;// "allowUnreachableCode": true,                     /* Disable error reporting for unreachable code. */&lt;/span&gt;

    &lt;span class="cm"&gt;/* Completeness */&lt;/span&gt;
    &lt;span class="c1"&gt;// "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;skipLibCheck&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;                                 &lt;span class="cm"&gt;/* Skip type checking all .d.ts files. */&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;To use a configuration you will just have to uncomment the line you wish to configure. There are a lot of configurations in this file that you don't necessarily need to understand but the more common ones are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;target&lt;/strong&gt;: You can set this to any ES version (ES2016/ES2017/ES2018...). ES2016 is a very common and most used version so that will likely work best for you in most situations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rootDir&lt;/strong&gt;: The configuration that specifies the directory that contains our src files. By default it is set to "./" which represents the current folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;outDir&lt;/strong&gt;: This configuration specifies the directory where our transpiled .js files will be sent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;removeComments&lt;/strong&gt;: If you add this configuration and keep it set to true, any comments you typed in your TypeScript code will not be transpiled in your .js files. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;noEmitOnError&lt;/strong&gt;: This will stop the compiler if there are any errors in our TypeScript code. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After you finish setting up your configuration, you can now run 'tsc' instead of 'tsc ' to transpile ALL .ts files in your application.&lt;/p&gt;

&lt;p&gt;There you have it, you should now be set up to start typing in TypeScript! Of course there are many more nuances to this programming language but I hope this was a good read to get you started! Stay tuned for more information in the future!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting Deployed with Digital Ocean</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 26 Jun 2022 22:42:20 +0000</pubDate>
      <link>https://dev.to/vkton115/getting-deployed-with-digital-ocean-4293</link>
      <guid>https://dev.to/vkton115/getting-deployed-with-digital-ocean-4293</guid>
      <description>&lt;h2&gt;
  
  
  WHAT IS DEPLOYMENT?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;"Application Deployment, also known as Software Deployment, is the process of installing, configuring, updating, and enabling one application or suite of applications that make a software system available for use, like facilitating a certain URL on a server."&lt;/em&gt;&lt;a href="https://www.vmware.com/topics/glossary/content/application-deployment.html#:~:text=Application%20Deployment%2C%20also%20known%20as,certain%20URL%20on%20a%20server."&gt;[1]&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many providers of deployment service, each with their own benefits and flaws. Deciding which ones are optimal to use for your application will be a huge asset in becoming the best developer you can be. Today we will be talking about one particular deployment service provider: &lt;strong&gt;Digital Ocean&lt;/strong&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  ABOUT DIGITAL OCEAN
&lt;/h2&gt;

&lt;p&gt;Digital ocean is a cloud-based deployment service that is geared towards helping developers, startups, and small-medium sized businesses get their projects up and running which is why its the perfect platform to understanding the basics of deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  GETTING STARTED
&lt;/h2&gt;

&lt;p&gt;After creating your account on &lt;a href="https://www.digitalocean.com/"&gt;Digital Ocean&lt;/a&gt;, you'll be able to create your first project.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RQDaitXh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq71av3pjes11m969p28.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RQDaitXh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq71av3pjes11m969p28.JPG" alt="create" width="178" height="188"&gt;&lt;/a&gt;&lt;br&gt;
After clicking the + New Project button, you will be prompted to provide a name, description, and provide a description for the purpose of your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_arUUSuB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1fzhhtq8jcoorfkp4gt.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_arUUSuB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1fzhhtq8jcoorfkp4gt.JPG" alt="createProject" width="633" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For me, I will be selecting the "Class Project/Educational Purposes" option.&lt;/p&gt;

&lt;p&gt;Once your project has been created, you can select what type of product want.&lt;/p&gt;

&lt;h2&gt;
  
  
  PRODUCTS
&lt;/h2&gt;

&lt;p&gt;Digital Ocean offers a variety of products which include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Droplets&lt;/strong&gt;: Linux-based virtual machines (VMs) that run on top of virtualized Hardware&lt;a href="https://www.digitalocean.com/products/droplets"&gt;[2]&lt;/a&gt;. These are essentially an individual server that you can use by itself or part of a larger cloud-based infrastructure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Kubernetes&lt;/strong&gt;: a service that automates software development, project scaling, and management. Useful when you have an application that is being deployed across multiple servers. This provides an open source API to orchestrate each of the VMs run based on their available resources and resource requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;App&lt;/strong&gt;: service that allows the user to directly publish code to Digital Ocean's servers. Can build your code directly from your GitHub, GitLab, or public Git repositories and publish the app straight to the cloud. Provides lifecycle management services, such as scaling, push-to-deploy support, DBM (database management) and integration.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many more products/services but these are some of the more common ones you'll see as you are just learning about deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  COST
&lt;/h2&gt;

&lt;p&gt;Digital ocean provides a large amount of flexibility on pricing depending on your application's resource needs. A full listing on their pricing can be found here: &lt;a href="https://www.digitalocean.com/pricing"&gt;https://www.digitalocean.com/pricing&lt;/a&gt; but as this blog is geared towards beginners who want to learn the basics of deployment, we will choose their "most used" product as our example, &lt;strong&gt;droplets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RHkr5mZd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa168ysp1zvjl0ec68hm.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RHkr5mZd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa168ysp1zvjl0ec68hm.JPG" alt="droplet" width="362" height="397"&gt;&lt;/a&gt;&lt;br&gt;
The starting price for the most basic droplet is currently $5/month but can go up depending on you the expected resource requirements of your application. Droplets are a great way to get started because they get your app up, running, and scaled with increased traffic flow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xt8rGqWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01he2yd55os0gg1z7y6u.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xt8rGqWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01he2yd55os0gg1z7y6u.JPG" alt="prices" width="880" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See the link below for a full, updated listing of their droplet prices. As mentioned it is highly flexible and can cater to your app's specific requirements.&lt;br&gt;
&lt;a href="https://www.digitalocean.com/pricing/droplets"&gt;droplet prices&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CREATING YOUR DROPLET
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Choose Your Distributions System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ecEOgjiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpb6gc7xbahhng47hm7d.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ecEOgjiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpb6gc7xbahhng47hm7d.JPG" alt="Distributions" width="880" height="112"&gt;&lt;/a&gt;&lt;br&gt;
Choose which distribution system your application is run on and its corresponding version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose a plan&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S2eZQEvF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z78ekn8vevs6n5uqlh4w.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S2eZQEvF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z78ekn8vevs6n5uqlh4w.JPG" alt="Plan" width="880" height="345"&gt;&lt;/a&gt;&lt;br&gt;
Same step as our pricings section, this is just a verification step to ensure you are selecting the right plan for your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Select your DataCenter Region&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ae1sndvz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwudy9y2zi7m7sqhpjr3.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ae1sndvz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwudy9y2zi7m7sqhpjr3.JPG" alt="datacenter" width="880" height="262"&gt;&lt;/a&gt;&lt;br&gt;
Digital Ocean hosts servers globally so choose the one that will be closest to where your application will be visited most often to reduce service times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AUTHENTICATION&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tPF9gqKV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dva88rgbuon8cruqs6hw.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tPF9gqKV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dva88rgbuon8cruqs6hw.JPG" alt="SSH" width="216" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll want your newly created server to be secure. There are two options: creating an SSH key or a Password. SSH Keys, or Security Shell Keys, don't have password authentication so it's safer against brute force attacks and is usually the recommended option. Hitting the New SSH Key button will provides steps to creating your key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FINALIZE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1flgtoZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/krvn11z28letnw32v64g.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1flgtoZG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/krvn11z28letnw32v64g.JPG" alt="finalize" width="880" height="160"&gt;&lt;/a&gt;&lt;br&gt;
Finally, you'll want to determine how many servers you will want to run under the same configurations you've set above and provide the hostname. If you want to host websites, you'll want to choose a hostname that is a fully qualified domain name.&lt;/p&gt;

&lt;p&gt;Once you have done so, click the 'Create Droplet' and you are officially finished creating your server! It'll take a minute or two before your droplet is fully deployed so definitely use that time to give yourself a pat on the back.&lt;/p&gt;

&lt;p&gt;Your newly created droplet will come with an ip address which you can now include in your application to load it onto the server!&lt;/p&gt;

&lt;h2&gt;
  
  
  SOURCES
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.vmware.com/topics/glossary/content/application-deployment.html#:~:text=Application%20Deployment%2C%20also%20known%20as,certain%20URL%20on%20a%20server."&gt;[1] https://www.vmware.com/topics/glossary/content/application-deployment.html#:~:text=Application%20Deployment%2C%20also%20known%20as,certain%20URL%20on%20a%20server. &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/products/droplets"&gt;[2] https://www.digitalocean.com/products/droplets &lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>startup</category>
    </item>
    <item>
      <title>ES6: Promises</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Mon, 20 Jun 2022 03:47:55 +0000</pubDate>
      <link>https://dev.to/vkton115/es6-promises-5eh9</link>
      <guid>https://dev.to/vkton115/es6-promises-5eh9</guid>
      <description>&lt;h2&gt;
  
  
  What are promises:
&lt;/h2&gt;

&lt;p&gt;With the introduction of ES6 came Promises. They are an object class that represents a value depending on a successful/failed completion of an asynchronous operation.&lt;/p&gt;

&lt;p&gt;As the name implies, using promise is akin to making a commitment to performing some operation or providing some value in the future.&lt;/p&gt;

&lt;p&gt;There are two possible outcomes to a promise: either it is successful and it &lt;strong&gt;resolves&lt;/strong&gt; or it fails and is &lt;strong&gt;rejected&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use promises:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;similar to using success &amp;amp; error callbacks, but in a much cleaner way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;prevents callback hell (when you have so many nested callbacks, it's hard to keep track of it all). This is done through the use of &lt;strong&gt;.then()&lt;/strong&gt; and &lt;strong&gt;.catch()&lt;/strong&gt;. more on them later.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Syntax:
&lt;/h2&gt;

&lt;p&gt;As briefly mentioned earlier, a promise object takes in a callback function with two parameters: resolve &amp;amp; reject.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const examplePromise = new Promise((resolve, reject) =&amp;gt; {

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, within the callback function, you would define what the promise is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const examplePromise = new Promise((resolve, reject) =&amp;gt; {
let grade = 100;

if (grade &amp;gt;= 70) {
 resolve("passed");
} else {
 reject ("failed");
}

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the resolve argument will be called if the condition met is true and the reject will be called if it is false. But what exactly do the resolve and reject do?&lt;/p&gt;

&lt;h2&gt;
  
  
  .then() &amp;amp; .catch()
&lt;/h2&gt;

&lt;p&gt;This is where .then() and .catch() come into play. &lt;/p&gt;

&lt;p&gt;.then() will invoke if the promise resolves/rejects.&lt;br&gt;
.catch() will invoke if the promise rejects.&lt;/p&gt;

&lt;p&gt;With our newly created promise, we can invoke &amp;amp; chain these methods like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;examplePromise
.then((message) =&amp;gt; console.log("you " + message))
.catch((message) =&amp;gt; console.log("you " + message));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.then() passes in a callback for when the promise resolves and also an optional callback for if the promise rejects.&lt;/p&gt;

&lt;p&gt;.catch() only passes in a callback for when the promise rejects.&lt;/p&gt;

&lt;p&gt;The callbacks within the .then() &amp;amp; .catch() will pass in the same arguments as the respective resolve and reject calls.  As you may have guessed, since our grade was set at 100, it will invoke the resolve, which in turn invokes our .then() to log to the console:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"you passed"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As mentioned before, .then() takes in a resolve callback but can ALSO take a reject callback. does that sound familiar? It's just like a promise. That is because every call to .then() returns a new promise, which is why we can chain multiple .then() calls to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Promise Methods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;.all()&lt;/strong&gt; - Promise.all() takes in an iterable amount of promises. Once each of those promises resolves, it will return a single promise that resolves to an array of the results of those inputted promises.[1]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of the inputted promises should reject, Promise.all() asynchronously rejects and returns the value of the promise that rejected, regardless of if the other input promises have resolved.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.allSettled()&lt;/strong&gt; - takes in an iterable amount of promises and will return an array of their outcomes, regardless of whether or not the resolved or rejected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.any()&lt;/strong&gt; - takes in an iterable amount of promises and will return a promise that resolves at the first instance of one of the input promises being fulfilled/resolved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.race()&lt;/strong&gt; - similar to .any() but will return at the first instance of any of the input promises being resolved or rejected.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[1] &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all&lt;/a&gt;&lt;/p&gt;

</description>
      <category>es6</category>
      <category>javascript</category>
      <category>promises</category>
    </item>
    <item>
      <title>React Component Lifecycle</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 12 Jun 2022 22:23:29 +0000</pubDate>
      <link>https://dev.to/vkton115/react-component-lifecycle-13c9</link>
      <guid>https://dev.to/vkton115/react-component-lifecycle-13c9</guid>
      <description>&lt;p&gt;ReactJS is a javascript library used to build user interfaces.&lt;/p&gt;

&lt;p&gt;Understanding the life cycle of a component is fundamental in building user-friendly application. &lt;/p&gt;

&lt;p&gt;A react component has 4 major phases: &lt;strong&gt;Initializing&lt;/strong&gt;, &lt;strong&gt;Mounting&lt;/strong&gt;, &lt;strong&gt;Updating&lt;/strong&gt;, &amp;amp; &lt;strong&gt;Unmounting&lt;/strong&gt;.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;INITIALIZATION&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;- The set-up phase where we set the state. It is usually done within the constructor method.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MOUNTING&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;- The process of placing elements onto the DOM.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;- This will be the first time an element will be rendered on a page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATING&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;- occurs whenever there is a change to a component's STATE or PROPS.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UNMOUNTING&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;- As the name implies, this is when a component is REMOVED from the DOM&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React Components have methods that, when called, are invoked at certain stages in it's lifecycle. Most of these are optional and for the most part self-explanatory, but serve important functionality.&lt;/p&gt;

&lt;p&gt;Lets break it down piece by piece:&lt;/p&gt;

&lt;h2&gt;
  
  
  INITIALIZATION
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;constructor() - (optional**) Similar as using constructor in JS classes, constructor is used the same way in React passing in 'props' as an argument. Within the constructor scope is the invocation of super(props). Calling super will allow us access to variables from the parent class while passing in props will allow us to pass data from one component to another [3]&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;**Although a constructor() call is technically optional, you will usually want to call it for two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;to initialize the local state by assigning an object to this.state&lt;/li&gt;
&lt;li&gt;to bind an event handler method to an instance [5]
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Example extends React.Component {
    constructor(props) { 
    super(props);
    this.state = {
     };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  MOUNTING
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;getDerivedStateFromProps() - (optional) called before render. Here we can set the state based on the initial props.[1]&lt;/li&gt;
&lt;li&gt;componentWillMount() - (optional) called before render. After this method, the component will get mounted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;render()&lt;/strong&gt; - (&lt;strong&gt;required&lt;/strong&gt;) this method is what actually puts our HTML on the page. Once it is run, you will be able to see your component. When changes are made to the props/state this method will be invoked again to re-render the page.&lt;/li&gt;
&lt;li&gt;componentDidMount - (optional) called after render(). can be used to change the state after it has successfully rendered onto the page. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  UPDATING
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;getDerivedStateFromProps() - (optional) same functionality when used in mounting. see above.&lt;/li&gt;
&lt;li&gt;shouldComponentUpdate() - (optional) returns a boolean. if set to false, the component will not update when a state/prop is changed. If true or not called, it will allow updates to occur. Essentially, this method makes a re-render optional.&lt;/li&gt;
&lt;li&gt;componentWillUpdate() - accepts two arguments: next props and next state. It is called once after shouldComponentUpdate and before a re-render.&lt;/li&gt;
&lt;li&gt;getSnapshotBeforeUpdate - (optional) accepts two arguments: previous props, and previous state. It allows the access to any props and stats before the component was updated. If using this method, you are &lt;strong&gt;required&lt;/strong&gt; to have componentDidUpdate() called as well, otherwise there will be bugs on your app.&lt;/li&gt;
&lt;li&gt;componentDidUpdate() - (optional) called after a component is updated in the DOM [3].&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  UNMOUNTING
&lt;/h2&gt;

&lt;p&gt;There's only one method that will run when you wish to unmount your component and that is &lt;strong&gt;componentWillUnmount()&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;componentWillUnmount()&lt;/strong&gt; - (&lt;strong&gt;required&lt;/strong&gt;) immediately after removing component from DOM, this will invoke. This denotes the end of a component's lifecycle and is required when properly trying to remove a component from the app. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;[1] &lt;a href="https://www.w3schools.com/react/react_lifecycle.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/react/react_lifecycle.asp&lt;/a&gt;&lt;br&gt;
[2] &lt;a href="https://www.javatpoint.com/react-constructor#:%7E:text=The%20constructor%20is%20a%20method,before%20the%20component%20is%20mounted" rel="noopener noreferrer"&gt;https://www.javatpoint.com/react-constructor#:~:text=The%20constructor%20is%20a%20method,before%20the%20component%20is%20mounted&lt;/a&gt;.&lt;br&gt;
[3]&lt;a href="https://www.geeksforgeeks.org/whats-the-difference-between-super-and-superprops-in-react/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/whats-the-difference-between-super-and-superprops-in-react/&lt;/a&gt;&lt;br&gt;
[4] &lt;a href="https://www.freecodecamp.org/news/how-to-understand-a-components-lifecycle-methods-in-reactjs-e1a609840630/" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/how-to-understand-a-components-lifecycle-methods-in-reactjs-e1a609840630/&lt;/a&gt;&lt;br&gt;
[5] &lt;a href="https://reactjs.org/docs/react-component.html#:%7E:text=If%20you%20don't%20initialize,props)%20before%20any%20other%20statement" rel="noopener noreferrer"&gt;https://reactjs.org/docs/react-component.html#:~:text=If%20you%20don't%20initialize,props)%20before%20any%20other%20statement&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>html</category>
      <category>components</category>
    </item>
    <item>
      <title>Encryption Methods</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 01 May 2022 23:41:25 +0000</pubDate>
      <link>https://dev.to/vkton115/encryption-methods-1p6h</link>
      <guid>https://dev.to/vkton115/encryption-methods-1p6h</guid>
      <description>&lt;h2&gt;
  
  
  What is Encryption?
&lt;/h2&gt;

&lt;p&gt;Encryption is the process of changing plain-text information into a seemingly random, or noncoherent sequence of characters known as &lt;strong&gt;cipher text&lt;/strong&gt; via the implementation of complex mathematical algorithims. The purpose for which is to safely deliver a message to a recipient without worry of it being intercepted by a third party or even tampered with.&lt;/p&gt;

&lt;p&gt;But what's the point of changing the message if the person receiving it won't be able to understand it either? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SRAQl5SC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgpuot92irmqp8j1tpjp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRAQl5SC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgpuot92irmqp8j1tpjp.jpg" alt="confused" width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
That's where an &lt;strong&gt;Encryption key&lt;/strong&gt; comes in handy. The purpose of the key can be to both encrypt and/or decrypt a message. This allows for the recipient of the encrypted message to actually understand our message.&lt;/p&gt;

&lt;p&gt;The Strength of an encryption key is determined by how well a hacker can guess it through brute force. A four-bit key (2^4) has 16 possible combinations, which means the hacker has a pretty good chance of guessing it right. Today's standard is a 256-bit key, which produces at 78-digit number which will probably take that same hacker much much longer to guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Encryption?
&lt;/h2&gt;

&lt;p&gt;While encryption today is widely used today in our world of technology anywhere from sending a simple text message to protecting your financial information, it has a long history dating all the way back as far as 600 BC. In ancient wars, the Spartans would use an item called a &lt;strong&gt;Scytale&lt;/strong&gt;, which is a piece of leather wrapped around a wooden pole. The piece of letter would consist of letters when unwrapped, were meaningless. Only when this leather strip was wrapped around a correctly sized rod, would the true message reveal itself. &lt;/p&gt;

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

&lt;p&gt;Fast forward a little ways down the road in 1918, a German engineer by the name of Arthur Scherbius invented the Enigma machine, which was later integrated by the German military to send coded messages. This device was deemed &lt;em&gt;uncrackable&lt;/em&gt; by other nations and was considered one of Germany's strongest weapons as it allowed them to send messages without the need to worry that their enemies would be able to decipher it. &lt;/p&gt;

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

&lt;p&gt;It wasn't until the invention of the &lt;strong&gt;bombe machine&lt;/strong&gt; that Germany's infamous Enigma machine met its match. The bombe machine was a large electro-mechanical device used by British cryptologists like &lt;strong&gt;Alan Turing&lt;/strong&gt; to decipher the Enigma machine's coded messages which ultimately change the tides of war in the Allies' favor during World War II. &lt;em&gt;The Imitation Game&lt;/em&gt;, which is a fantastic movie which goes more into detail about this topic. It features Benadryl Cucumberpatch as Alan Turing and explains the functionality of his bombe machine much more in depth. But for simplicity purposes, you can consider the bombe machine as one of the first electronic decryption devices.&lt;/p&gt;

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

&lt;p&gt;This was not intended to be a history lesson, but I just wanted to show you the big scope that encryption has in our lives and the benefits of being able to securely send messages across our data and even across the world. Back then, the main purposes of encryption was to prevent our enemies from knowing our secrets. Well, not much has changed. In the context of using encryption in our daily lives, its to prevent hackers from maliciously using the information we send out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Encryption
&lt;/h2&gt;

&lt;p&gt;There are 2 main types of Encryption, &lt;strong&gt;Symmetric&lt;/strong&gt; and &lt;strong&gt;Asymmetric&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Symmetric&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We talked briefly about &lt;em&gt;keys&lt;/em&gt; and their importance. A symmetric encryption uses only one key to both encrypt and decrypt electronic data. Both parties must have access to this key so that it can be used to decrypt their messages. This method scrambles data so that it cannot be understood by anyone outside of the entities who do not have the key. Typically, symmetric encryptions are faster and able to efficiently send larger pieces of data, albeit less secure than Asymmetric encryption. This is due to the risk of the key being compromised. If any outside party were to have the key, they could use it maliciously to decrypt messages that were intended to be private.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gSC8GtGG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0aub2n9p5kkrscxhbyel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gSC8GtGG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0aub2n9p5kkrscxhbyel.png" alt="Symmetric Encryption" width="796" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asymmetric&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While symmetric encryption uses a single key. Asymmetric uses two keys: a public key, and a private key. The public key is shared with all intended recipients of the message while the private key is known only to the generator of the key. The public key is used to encrypt the message while the private key's purpose is to decrypt. Asymmetric encryption is preferred over its symmetric counterpart when security is prioritized over speed and where personal identity verification is required.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YScq21u4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m9hxaa07av21rcr4a3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YScq21u4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m9hxaa07av21rcr4a3c.png" alt="Asymmetric" width="516" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;End-to-End Encryption (E2EE)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I felt I should also mention this encryption method as it differs slightly from the above. This encryption method can be mistakenly confused with symmetric encryption because it only requires one key. However, where it differs is the fact that the key to decipher is known only between the sender and recipient. The third party that is responsible for sending the encrypted message does not have access to this key, therefore they do not know the contents within it. This is why certain companies who provide end-to-end encryption services can not provide the texts of their customers over to the police.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notable Encryption Methods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Encryption Standard (DES) [Symmetric]&lt;/strong&gt;&lt;br&gt;
An outdated, but huge step in data encryption, DES was developed in the 1970s as a proposal for its used in protecting sensitive, unclassified electronic government data. It takes a fixed-length (64bit) of text, or its &lt;strong&gt;block size&lt;/strong&gt;, and turns it into a cipher text of identical length. DES then uses a 64 bit key to change the plain text. Technically only 56/64 of the bits are used by the algorithm to make this change, the remaining bits are used for checking &lt;strong&gt;parity&lt;/strong&gt;, or error detecting code. Those 8 remaining bits are discarded afterwards, making the true key length 56 bits. The process for decryption is the same as in encryption, only in reversed order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Triple Data Encryption Standard (3DES/TDES) [Symmetric]&lt;/strong&gt;&lt;br&gt;
While the DES was a major milestone in encryption, it's 56bit key is considered short in comparison to its same-era decryption techniques. TDES applies the DES cipher algorithm three times to each data block, which increases the key size of DES without having to create a new block algorithm.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rijndael/Advanced Encryption Standard (AES) [Symmetric]&lt;/strong&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Formerly known as Rijndael, this algorithm was selected to become the Advanced Encryption Standard by the National Institute of Standards and Technology in 2000. Officially published in 2001, AES operates on a 128, 192, or 256-bit key depending on how many rounds of transformations occur on the plaintext (10/12/14 rounds respectively). Compared to DES' 56 bit key, this is much more secure. DES operates on the Feistel Cipher Principle, which divides the block into 2 before it transforms plaintext while AES works on a substitution &amp;amp; permutation principle. AES is also faster than DES because it uses a more mathematically efficient algorithm.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blowfish Cipher [Symmetric]&lt;/strong&gt;&lt;br&gt;
Designed in 1993, this encryption method is still considered strong to this date as there are no notably effective cryptanalysis methods. It was initially designed by Bruce Schneier to be a general purpose algorithm to replace DES. Similarly to DES, this algorithm uses the Feistel Cipher principle and uses a 64-bit block size. However it's key length can range anywhere from 32 bits up to 448 bits and runs the plain text through 16 rounds of transformations. Due to the block size, it is not recommended to use this encryption technique on files larger than 4GB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Twofish [Symmetric]&lt;/strong&gt;&lt;br&gt;
The Twofish algorithm was amongst the top 5 competitors including the aforementioned winner Rijndael to become the Advanced Encryption Standard. It is the successor to the Blowfish method, however the latter is still more widely used due to it being around longer. While blow fish ciphers data blocks of 64 bits, Twofish ciphers data blocks of 128 bits. One of the key factors that this method was not chosen of Rijndael was due to its encryption speed, although it has been noted to be slightly faster when operating with 256 bit keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rivest-Shamir-Adleman (RSA) [Asymmetric]&lt;/strong&gt;&lt;br&gt;
This method, which derives its name from its designers Ron Rivest, Adi Shamir, and Leonard Adleman, is one of the oldest and widely used algorithms for secure data transmission. As this method is asymmetric, it uses a public encryption key and a private decryption key. The public key is based on two large prime numbers, which are kept secret. Only someone with knowledge of the two prime numbers would be able to successfully decode/decrypt a file. The main reason this method is highly secured is because of the difficulty it takes to factor the produce of the two large secret prime numbers. While secure, this method is also quite slow, making it not suitable to directly encrypt user data. It is more commonly used to transmit shared keys for symmetric-key cryptography.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  To Summarize
&lt;/h2&gt;

&lt;p&gt;Understanding data encryption is the first step to keeping your information secure, whether its a private text message or a company email. No matter how you look at it, encryption provides so a lot of protection in the form of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication: being able to verify a file/message's origins&lt;/li&gt;
&lt;li&gt;Nonrepudiation: prevents the message sender from being able to deny sending a message.&lt;/li&gt;
&lt;li&gt;Security: prevents unwanted entities from reading your data&lt;/li&gt;
&lt;li&gt;Integrity: verifies that the message/file has not been tampered with since it was sent&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>websecurity</category>
      <category>security</category>
      <category>beginners</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>RESET CSS &amp; Normalize.css</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Sun, 24 Apr 2022 22:30:44 +0000</pubDate>
      <link>https://dev.to/vkton115/reset-css-normalizecss-320m</link>
      <guid>https://dev.to/vkton115/reset-css-normalizecss-320m</guid>
      <description>&lt;p&gt;If you're like me, adding CSS (cascading style sheets) to your projects is one of the most fun parts of developing a webpage. It's the part of the job that really lets you give your project some color, and bring it to life. However, there are many things about webpage styling that you don't really notice in the beginning.&lt;/p&gt;

&lt;p&gt;For example, take this very basic html document I've created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
  &amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
      &amp;lt;title&amp;gt;Vincent's Webpage&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;

    &amp;lt;body&amp;gt;
      &amp;lt;main&amp;gt;
        &amp;lt;header&amp;gt;
          &amp;lt;nav&amp;gt;
            &amp;lt;ul&amp;gt;
              &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Gallery&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;&amp;lt;a href="#"&amp;gt;Contact&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
          &amp;lt;/nav&amp;gt;
          &amp;lt;h1&amp;gt;H1 Heading&amp;lt;/h1&amp;gt;
          &amp;lt;h2&amp;gt;H2 Heading&amp;lt;/h2&amp;gt;
        &amp;lt;/header&amp;gt;

        &amp;lt;section class="info"&amp;gt;
          &amp;lt;p class="description"&amp;gt; paragraph element
        &amp;lt;section class="examples"&amp;gt;
          &amp;lt;ul&amp;gt;Example List
            &amp;lt;li&amp;gt;listItem1&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;listItem2&amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;listItem3&amp;lt;/li&amp;gt;
          &amp;lt;/ul&amp;gt;
          &amp;lt;button&amp;gt;THIS IS A BUTTON&amp;lt;/button&amp;gt;
          &amp;lt;input type="checkbox"&amp;gt; THIS IS A CHECKBOX
          &amp;lt;select&amp;gt;
            &amp;lt;option&amp;gt;Select Option 1&amp;lt;/option&amp;gt;
            &amp;lt;option&amp;gt;Select Option 2&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;
      &amp;lt;/main&amp;gt;

    &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From a quick glance you can see that there are few different html elements incorporated, such has: headers, hyperlinks, paragraphs, list items, buttons, etc.&lt;/p&gt;

&lt;p&gt;As you'd expect this is what this very basic webpage would look like:&lt;/p&gt;

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

&lt;p&gt;But ask yourself these questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why are the headers bold?&lt;/li&gt;
&lt;li&gt;Why is an H1 heading a different size than an H2?&lt;/li&gt;
&lt;li&gt;When you click a hyperlink, why did it turn purple?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have never added any css styling of our own to these elements and yet here they are, all dressed by themselves with no help from us. They grow up so fast. &lt;/p&gt;

&lt;p&gt;Don't let these few unanswered questions haunt you at night. The short and simple answer is: &lt;strong&gt;Browser Defaults&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Did you know that different browsers have their own default style settings? It might be hard to tell at first but take a look at this side-by-side comparison between some popular browsers used today.&lt;/p&gt;

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

&lt;p&gt;Some aspects may be more difficult to distinguish amongst browsers such as the hyperlinks and headings. However, this becomes much clearer when we look at certain elements such as the checkbox and the drop down menu items. As you saw, these styles are specific to each individual browser.&lt;/p&gt;

&lt;p&gt;Detailed lists of specific browser stylings can be found here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://web.archive.org/web/20170122223926/http://www.iecss.com/" rel="noopener noreferrer"&gt;internet explorer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://searchfox.org/mozilla-central/source/layout/style/res/html.css" rel="noopener noreferrer"&gt;firefox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css" rel="noopener noreferrer"&gt;google chrome&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The purpose for these browser defaults is so that pages are rendered with more uniformity and consistency if we developers don't specify them ourselves. But what if we didn't want our page to incorporate any of the styles that have been preset? Would we have to go in and change/undo every preset style change that the browser set for them? That seems rather excessive. Fortunately for us there are methods which we can use to make that process more efficient. These methods are called &lt;strong&gt;CSS Resets&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS RESETS
&lt;/h2&gt;

&lt;p&gt;There are a few ways to implement css resets on your page:&lt;/p&gt;

&lt;p&gt;The first is the &lt;strong&gt;Universal Selector&lt;/strong&gt;:&lt;/p&gt;

&lt;h2&gt;
  
  
  Universal Selector - How to Use
&lt;/h2&gt;

&lt;p&gt;In a new css file, we would start this off with an asterisk(*) followed by curly braces {} like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*{
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does is target every single element on your page. Typically with this method, we would set the margin and padding to 0 to remove any default user agent styles associated with padding and margin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we added these styling changes we will need to link it in our initial html document like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;head&amp;gt;
      &amp;lt;title&amp;gt;Vincent's Webpage&amp;lt;/title&amp;gt;
      &amp;lt;link rel="stylesheet" href="/styles.css"&amp;gt;
    &amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that it's been linked, we can take a look at how this affected our webpage (I will be using chrome for any examples moving forward). &lt;/p&gt;

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

&lt;p&gt;As you can see, all stylings associated with margins and padding have been set to 0. This is a very simple way to reset many styling changes at once.&lt;/p&gt;

&lt;p&gt;The main benefit to this method is that it is a very quick and easy way to remove all formatting. The downside is that if your webpage has a lot of content, this reset would apply to many elements on the page which in turn will affect the speed of the website.&lt;/p&gt;

&lt;p&gt;A better way to reset your file is to reset your style on each element individually. This way, you're only applying the reset styles when they are needed as opposed to every single element that might exist out there which will result in faster speeds on your site.&lt;/p&gt;

&lt;h2&gt;
  
  
  ERIC MEYER'S CSS RESET
&lt;/h2&gt;

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

&lt;p&gt;Eric Meyer's version of CSS Reset is one of most widely used and popular implementations of this technique.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://meyerweb.com/eric/tools/css/reset/reset.css" rel="noopener noreferrer"&gt;Eric Meyers CSS RESET TEMPLATE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://meyerweb.com/" rel="noopener noreferrer"&gt;Eric Meyer's Website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Eric Meyer's CSS Reset - How to Use
&lt;/h2&gt;

&lt;p&gt;Eric Meyer's reset template is essentially a "plug-and-play". You can just copy it into a css file and link it to your html doc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;head&amp;gt;
      &amp;lt;title&amp;gt;Vincent's Webpage&amp;lt;/title&amp;gt;
      &amp;lt;link rel="stylesheet" href="/reset.css"&amp;gt;
      &amp;lt;link rel="stylesheet" href="/styles.css"&amp;gt;
    &amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: It is very important that you place the link before your own style.css link. This is because the page is rendered from top-down, meaning you want to reset your css BEFORE you add your own styling to it.&lt;/p&gt;

&lt;p&gt;For the purposes of this example, our previous styles.css has been commented out to show what reset.css will do to our webpage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fro640m38yi3chuort2rg.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fro640m38yi3chuort2rg.JPG" alt="Eric Meyer's Reset"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From there on, you can design and style the page the way you want.&lt;/p&gt;

&lt;p&gt;To summarize CSS Reset, it is an effective way of resetting the styling of HTML elements down to a consistent baseline. This will give the developer a peace of mind knowing that any user's viewing their page via different browsers will not be affected. Performing a css reset is by no means a requirement, but as you go on to develop webpages in the future, it is a great technique to understand in order to save you much time and headaches. &lt;/p&gt;

&lt;p&gt;While CSS reset is a good thing to learn, it doesn't come without its own flaws, such as being hard/nearly impossible to debug. It is also non-modular, meaning that there are no section breaks in styles. This is where &lt;strong&gt;Normalize.css&lt;/strong&gt; comes into play.&lt;/p&gt;

&lt;h2&gt;
  
  
  NORMALIZE.CSS
&lt;/h2&gt;

&lt;p&gt;Normalize.css is a tool developed by &lt;a href="https://twitter.com/necolas" rel="noopener noreferrer"&gt;Nicolas Gallagher&lt;/a&gt; &amp;amp; &lt;a href="https://twitter.com/jon_neal" rel="noopener noreferrer"&gt;Jonathan Neal&lt;/a&gt; as an alternative to CSS resets.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Nicolas Gallagher&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqh8an1y6tz5xudciizm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqh8an1y6tz5xudciizm.jpg" alt="Nicolas Gallagher"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Jonathan Neal&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzygffirszf7gmzsp1vl3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzygffirszf7gmzsp1vl3.jpg" alt="Jonathan Neal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An important distinguishing feature of Normalize.css from CSS resets is that it doesn't aim to completely create a clean slate when it comes to styling, rather it's goal is to maintain a consistent style across different browsers. Instead of resetting all the preset styles, it preserves the useful defaults.&lt;/p&gt;

&lt;p&gt;There are many reasons why one would wish to use this tool over a css reset:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Preserved Defaults&lt;/strong&gt;&lt;br&gt;
To elaborate on what &lt;em&gt;preserved defaults&lt;/em&gt; entails, normalize.css keeps you from having to re-style what you've already reset from using a css reset. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Less Clutter&lt;/strong&gt;&lt;br&gt;
When it comes to your debugging tools, reset css usually has a long inheritence chain that can just be an absolute nightmare to stare at.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modular&lt;/strong&gt;
Unlike css resets, Normalize.css is modular, meaning that your project is divided into separate sections, making it much easier for you to pick and choose which styles to apply to each of them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Well Documented&lt;/strong&gt;
This project was created to help teach users how separate browsers render their elements by default. Each section of their code has comments to describe its purpose specific to each browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6l4hvmxr5imcn1uj643.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx6l4hvmxr5imcn1uj643.JPG" alt="normalize repo"&gt;&lt;/a&gt;&lt;br&gt;
This is just a small snippet to show you what I mean. The repository is very intuitive and helps to provide the user with insight into how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supported Browsers
&lt;/h2&gt;

&lt;p&gt;Currently, normalize.css supports the following browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome&lt;/li&gt;
&lt;li&gt;Edge&lt;/li&gt;
&lt;li&gt;Firefox ESR+&lt;/li&gt;
&lt;li&gt;Internet Explorer 10+&lt;/li&gt;
&lt;li&gt;Safari 8+&lt;/li&gt;
&lt;li&gt;Opera&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Notable users of Normalize.css
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Twitter&lt;/li&gt;
&lt;li&gt;TweetDeck&lt;/li&gt;
&lt;li&gt;GitHub&lt;/li&gt;
&lt;li&gt;SoundCloud&lt;/li&gt;
&lt;li&gt;Guardian&lt;/li&gt;
&lt;li&gt;Medium&lt;/li&gt;
&lt;li&gt;Boostrap&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Normalize.css - How to Use
&lt;/h2&gt;

&lt;p&gt;The repository for normalize.css can be found &lt;a href="https://github.com/necolas/normalize.css" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once forked, you can add the link of your file location to your index.html as we've done previously with our reset.css and styles.css files. &lt;/p&gt;

&lt;p&gt;From there, you have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can modify the preset settings inside of the normalize.css files to your liking.&lt;/li&gt;
&lt;li&gt;Leave normalize.css untouched and overwrite those changes in your own .css file. Just be sure to add your .css file under the normalize.css file in your html document.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  TO SUMMARIZE
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reset CSS&lt;/strong&gt; resets all styles that come with a browser's user agent. It can however, be excessive as it may make many unnecessary overwrites in the styling. It can be difficult to identify bugs and it is non-modular. You can create  your own reset by using the universal selector reset or you can utilize Eric Meyer's template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Normalize.css&lt;/strong&gt; doesn't affect all default stylings. It will instead preserve the useful ones. It corrects bugs and common browser inconsistencies and is well documented and intuitive to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  IN CONCLUSION
&lt;/h2&gt;

&lt;p&gt;Both CSS Reset and Normalize.css have their benefits. It's not necessarily better to use one over the other but it's essential to understand the differences in order to decide which route you wish to take when designing your webpage. Reset CSS is essentially a clean slate, allowing you freedom to style your page from the ground up whereas Normalize.css helps break it down into sections for more modularity.&lt;/p&gt;

&lt;p&gt;Both help to achieve the same goal - to get default stylings out of the way to give you creative freedom to style your page the way you wish to.&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Introduction to Zombie.JS</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Mon, 18 Apr 2022 02:13:15 +0000</pubDate>
      <link>https://dev.to/vkton115/zombiejs-24fo</link>
      <guid>https://dev.to/vkton115/zombiejs-24fo</guid>
      <description>&lt;p&gt;Before we talk about zombies, let's talk about skeletons. In particular, the skeleton we will discuss is named &lt;strong&gt;DOM&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9GXMeX2T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p5p6zskcglhwtv2md70.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9GXMeX2T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p5p6zskcglhwtv2md70.gif" alt="skeleton dance" width="222" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the DOM?&lt;/strong&gt;&lt;br&gt;
  DOM stands for Document Object Model. It is the basis for how a browser represents a webpage. The DOM is technically a type of API (application programming interface) that is inside of your browser.&lt;/p&gt;

&lt;p&gt;An easy way to break it down is as so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Document&lt;/strong&gt; = file&lt;br&gt;
Can be any type of file. In most cases, when we refer to the DOM we are referring to our html file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt; = tags/elements&lt;br&gt;
Consists of anything you put inside of the file.&lt;br&gt;
In the context of an html file, this would be the body, html, head, body tags.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KKrb0myf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj650m3uxnlvwwd5ac1g.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KKrb0myf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj650m3uxnlvwwd5ac1g.JPG" alt="DOM model" width="379" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt; = layout structure
Now that we have all of our elements and tags added to the html, the way we organize those pieces will define our the skeleton of our page!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Kh8Igkk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74ip5zynxx51rm1vo3bx.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Kh8Igkk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74ip5zynxx51rm1vo3bx.JPG" alt="zombie coder" width="553" height="465"&gt;&lt;/a&gt;&lt;br&gt;
  Enough about skeletons, I know you're only here for the zombies.&lt;/p&gt;

&lt;p&gt;Firstly, I would like to introduce you to Assaf Arkin, the developer for zombie.js&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kj0Wz0iV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9qgnmnpo5iv5p6o9ub6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kj0Wz0iV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9qgnmnpo5iv5p6o9ub6.JPG" alt="Assaf profile pic" width="248" height="249"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/assaf/zombie"&gt;https://github.com/assaf/zombie&lt;/a&gt;&lt;br&gt;
&lt;a href="http://twitter.com/@assaf"&gt;http://twitter.com/@assaf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I had to breakdown what zombie.js does in a single sentence I would say that it is a lightweight simulated browser environment typically geared towards efficiently running tests.&lt;/p&gt;

&lt;p&gt;What do I mean when I say simulated? Unfortunately, I don't mean to say that Assaf created his own version of the Matrix. However, the functionality of this tool is quite interesting due to the fact that it allows you to test components of your application without ever actually having to open a web browser. Instead, it will let you know if you have any errors in the comfort of your own console.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"If you're going to write an insanely fast, headless browser, how can you not call it Zombie" -Assaf Arkin&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In-depth description:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Automated tests can be split into two types: &lt;strong&gt;Unit Tests&lt;/strong&gt; and &lt;strong&gt;Integration Tests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unit tests&lt;/strong&gt; are tests in which you are only looking at a specific component of your application, like a specific object for example. These are typically used to ensure that they react the way you wanted them to as to not interfere with the functionality of other subsets of your application. Because these tests are on smaller components, their load times are usually not a cause for concern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integration Tests&lt;/strong&gt; are used when you collectively want to see if all your individual components are operating as expected. Because of the complexity of testing these components can scale quite largely, this is where zombie.js comes in handy.&lt;/p&gt;

&lt;p&gt;zombie.js allows you to run tests without actually having to open a web browser. Rather, it creates it's own simulated browser and because the HTML pages no longer need to be displayed, it cuts and saves you time from having to render those pages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K9aP7qJV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1id6a19pev0yz7gar37.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K9aP7qJV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1id6a19pev0yz7gar37.JPG" alt="zombie.js snippet" width="624" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above is just a small list of actual browser features that zombie.js can imitate. It can simulate anything from new tabs to looking up/deleting cookies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To SUMMARIZE:&lt;/strong&gt;&lt;br&gt;
  In the software development industry, testing is an integral part in creating any application. The user can utilize zombie.js to create any set of tests that run in a browser-like object and because that browser-object never has to actually render any HTML, the tests will run much faster than they would use any other browser out there. Any changes to your code, whether large or small, will benefit you greatly by running the tests for it through zombie.js. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use Functions</title>
      <dc:creator>Vincent Tong</dc:creator>
      <pubDate>Fri, 18 Feb 2022 15:49:54 +0000</pubDate>
      <link>https://dev.to/vkton115/how-to-use-functions-9gn</link>
      <guid>https://dev.to/vkton115/how-to-use-functions-9gn</guid>
      <description>&lt;p&gt;&lt;strong&gt;Declaring Functions:&lt;/strong&gt;&lt;br&gt;
functions can declared by using the &lt;strong&gt;&lt;em&gt;function&lt;/em&gt;&lt;/strong&gt; keyword, followed by the name you wish to give a function, parenthesis, and curly braces like so:&lt;br&gt;
&lt;code&gt;function namedFunction () {}&lt;/code&gt;&lt;br&gt;
inside the parenthesis, you can add parameters. the names of these parameters can be anything but they should represent the data that you'd expect someone to input into this function if they were using it. Let's say we were creating a function to find the area of a rectangle, which is length times width. We can add two parameters named len and wid. like so:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function rectangleArea (len, wid){}&lt;/code&gt;&lt;br&gt;
now inside your curly braces is where our code will go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function rectangleArea (len, wid){
return len * wid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! We have successfully declared a function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anonymous functions:&lt;/strong&gt;&lt;br&gt;
Functions don't necessarily need names. Instead, we can assign the function to a variable in a method called a &lt;strong&gt;function expression&lt;/strong&gt;. Take our previous example, instead of naming it, we could have instead assigned it to a variable like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var area = function(len, wid){
return len * wid
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anonymous functions can be useful if you don't need to reference it later on. However, you can still provide a name so that it can be easily called for future uses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calling Functions:&lt;/strong&gt;&lt;br&gt;
Whether or not the function is named, we can still call them in a similar fashion. We just need to enter the name of the function, or the name of the variable if it was declared anonymously, as a keyword followed by the &lt;strong&gt;&lt;em&gt;arguments&lt;/em&gt;&lt;/strong&gt;. arguments are what we input in the parenthesis of the function, they take the place of the &lt;em&gt;&lt;strong&gt;parameters&lt;/strong&gt;&lt;/em&gt; we discussed earlier and can be any datatype, be it simple (like strings &amp;amp; numbers) or complex (like arrays and objects).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rectangle(3, 4) // calling the rectangle function will return 12
area(5, 4) // calling the function expression will return 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function Scope&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now its time to talk about scope- and no, i'm not talking about the mouthwash brand. &lt;strong&gt;function scopes&lt;/strong&gt; define the limits of what can reach the variables inside of a function and also what variables that same function can reach outside of itself. First, you should understand that &lt;strong&gt;global scope&lt;/strong&gt;, which is the window that encompasses all of your code. Any variable declared in the global scope can be accessed within any function or code block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//global window
var x = 20;

//function within the global window
function logX(){
  //function will try to access x from inside its own scope
  console.log(x) 
}

//calling the function
logX();//  20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the function is able to access the variable x, which was defined outside of its own function scope. It is successful because variables defined in the global scope can be accessed from anywhere.&lt;/p&gt;

&lt;p&gt;now lets see what happens when we do the opposite- try to access a variable inside a function's scope from the global window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function logX(){
  //same function but we declared a variable y inside
  var y = 10;
  console.log(x) //=&amp;gt; 20
}

//trying to access the variable y outside of the function scope
console.log(y);// y is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we get a reference error: y is not defined. This is because the variable y is inside of a specific function's scope, and therefore can only be accessed within that function.&lt;/p&gt;

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

&lt;p&gt;The image above should demonstrate the boundaries scopes can set. The formatting is very similar to that of a nested russian doll.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;What we Learned:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Functions can be declared - with a name or anonymously with a function expression&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When calling a function, you can do so by calling the &lt;em&gt;function name&lt;/em&gt; or the variable that the &lt;em&gt;function expression&lt;/em&gt; is assigned to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function scopes define what variables can be accessed and from where&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
To summarize, functions are the building blocks of our code. Without them, nothing would get done, literally! Being able to create your own functions and be able to use them anywhere in your code is the first step to becoming a successful programmer.&lt;/p&gt;

&lt;p&gt;Functions can become much more complicated, but what we learned today will be a great starting point for understanding future topics. Stay tuned for more to come!&lt;/p&gt;

</description>
      <category>java</category>
      <category>javascript</category>
      <category>coding</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
