<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Joel P. Mugalu</title>
    <description>The latest articles on Forem by Joel P. Mugalu (@codingknite).</description>
    <link>https://forem.com/codingknite</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%2F338435%2Fc5d8e19e-cb95-470e-af6e-2ea6b1aa2b1b.JPG</url>
      <title>Forem: Joel P. Mugalu</title>
      <link>https://forem.com/codingknite</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codingknite"/>
    <language>en</language>
    <item>
      <title>Developer Stories: How Justin became a game dev by accident</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Thu, 03 Aug 2023 07:32:24 +0000</pubDate>
      <link>https://forem.com/codingknite/developer-stories-how-justin-became-a-game-dev-by-accident-23fp</link>
      <guid>https://forem.com/codingknite/developer-stories-how-justin-became-a-game-dev-by-accident-23fp</guid>
      <description>&lt;p&gt;I had a wonderful chat with Justin Scott Bieshaar, a game developer from the Netherlands.&lt;br&gt;
We talked about how he accidentally got into the craft, the challenges he’s had in his journey, and how we can be more supportive of women in tech and other underrepresented groups. &lt;/p&gt;

&lt;p&gt;Catch the full article &lt;a href="https://www.peoplewhocode.io/interviews/justin-bieshaar"&gt;here at peoplewhocode&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
      <category>news</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>TypeScript: Getting Started</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Wed, 07 Jul 2021 13:54:43 +0000</pubDate>
      <link>https://forem.com/codingknite/typescript-getting-started-39dm</link>
      <guid>https://forem.com/codingknite/typescript-getting-started-39dm</guid>
      <description>&lt;h3&gt;
  
  
  TypeScript has taken the development world by storm. No wonder it has over 15 million weekly downloads on &lt;a href="https://www.npmjs.com/package/typescript" rel="noopener noreferrer"&gt;npm&lt;/a&gt;. But what is TypeScript, and what do you need to know about it?
&lt;/h3&gt;

&lt;p&gt;In this article, I am going answer those questions. By the end you'll have a grasp of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What TypeScript is&lt;/li&gt;
&lt;li&gt;Main pillars of TypeScript&lt;/li&gt;
&lt;li&gt;Main features of TypeScript&lt;/li&gt;
&lt;li&gt;Why you should use TypeScript&lt;/li&gt;
&lt;li&gt;TypeScript basics to get you started&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, let's address the elephant in the room.&lt;/p&gt;

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

&lt;p&gt;TypeScript is a programming language built and maintained by Microsoft.&lt;br&gt;&lt;br&gt;
It is a superset of JavaScript that adds strong type checking and is compiled into plain JavaScript code.&lt;/p&gt;

&lt;p&gt;Being a superset means that TypeScript has all the features of JavaScript as well as some additional features.&lt;/p&gt;

&lt;p&gt;TypeScript comes with features such as better development-time tooling, static code analysis, compile-time type checking, and code-level documentation.&lt;/p&gt;

&lt;p&gt;Don't worry if you have no idea what any of this means. I'll explain all of it in this article.&lt;/p&gt;

&lt;p&gt;All these features that come with TypeScript make it the perfect programming language for building large-scale JavaScript applications.&lt;/p&gt;
&lt;h2&gt;
  
  
  Main pillars of TypeScript
&lt;/h2&gt;

&lt;p&gt;TypeScript is built upon three main pillars – namely the language, the compiler, and the language service.&lt;/p&gt;
&lt;h3&gt;
  
  
  TypeScript Language
&lt;/h3&gt;

&lt;p&gt;This consists of the syntax, keywords, and type annotations of TypeScript.&lt;br&gt;&lt;br&gt;
TypeScript syntax is similar to but not the same as JavaScript syntax.&lt;/p&gt;
&lt;h3&gt;
  
  
  TypeScript Compiler
&lt;/h3&gt;

&lt;p&gt;The compiler is responsible for compiling Typescript code into JavaScript.&lt;br&gt;&lt;br&gt;
In reality, what happens is not actually compiling but transpiling.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Compiling means that source code is transformed from a human-readable format to a machine-readable format, whereas transpiling is transforming source code from one human-readable format to another human-readable format.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The TypeScript compiler is also responsible for erasing any information related to types at compile time.&lt;/p&gt;

&lt;p&gt;Types are not valid features in JavaScript. And since TypeScript has to be compiled to plain JavaScript, anything related to types has to be erased before it can become valid JavaScript ready to be executed by the browser.&lt;/p&gt;

&lt;p&gt;The TypeScript compiler also performs code analysis. It emits errors and warnings if there's reason to do so.&lt;/p&gt;
&lt;h3&gt;
  
  
  Language Service
&lt;/h3&gt;

&lt;p&gt;The language service is responsible for collecting type information from the source code.&lt;/p&gt;

&lt;p&gt;This information can then be used by development tools to provide IntelliSense, type hints, and refactoring alternatives.&lt;/p&gt;
&lt;h2&gt;
  
  
  Main Features of TypeScript
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Type Annotations in TypeScript
&lt;/h3&gt;

&lt;p&gt;Type annotation simply means assigning a type to a variable or function.&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;const&lt;/span&gt; &lt;span class="nx"&gt;birthdayGreeter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Happy birthday &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, you are now &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;birthdayHero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jane User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;birthdayGreeter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;birthdayHero&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we define a function that accepts two parameters &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt;. We assign &lt;code&gt;name&lt;/code&gt; to the type &lt;em&gt;string&lt;/em&gt; &lt;code&gt;age&lt;/code&gt; to the type &lt;em&gt;number&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can also assign types to the return value of a function. In this case, our function returns a value of the type &lt;em&gt;string&lt;/em&gt;&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;const&lt;/span&gt; &lt;span class="nx"&gt;birthdayGreeter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;Typescript&lt;/span&gt; &lt;span class="nx"&gt;would&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;we&lt;/span&gt; &lt;span class="nx"&gt;passed&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;arguments&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;different&lt;/span&gt; &lt;span class="nx"&gt;types&lt;/span&gt; &lt;span class="nx"&gt;than&lt;/span&gt; &lt;span class="nx"&gt;ones&lt;/span&gt; &lt;span class="nx"&gt;we&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Structural Typing in TypeScript
&lt;/h3&gt;

&lt;p&gt;TypeScript is a structurally typed language meaning that if two elements have corresponding and identical features then they are considered to be of the same type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type Inference in TypeScript
&lt;/h3&gt;

&lt;p&gt;The TypeScript compiler can attempt to infer the type information if there is no specific type assigned. This means that TypeScript can assign a type to a variable or function based on its initial values or usage.&lt;/p&gt;

&lt;p&gt;Type inference usually happens when you initialize variables, set default values, and determe function return 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;const&lt;/span&gt; &lt;span class="nx"&gt;platform&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;freeCodeCamp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&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;number&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;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable platform in the above example is assigned the type &lt;em&gt;string&lt;/em&gt; even though we didn't explicitly do so and the return value of the function &lt;code&gt;add&lt;/code&gt; is inferred the type &lt;em&gt;number&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type Erasure in TypeScript
&lt;/h3&gt;

&lt;p&gt;TypeScript removes the type system constructs during compilation:&lt;/p&gt;

&lt;p&gt;Input&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;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;someType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&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;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Type checking and static code analysis
&lt;/h3&gt;

&lt;p&gt;This reduces the overall errors in your code because TS will warn you when you wrongfully use a certain type.&lt;/p&gt;

&lt;p&gt;It also reduces runtime errors and because of static code analysis, TypeScript will throw warnings about typos and such. So this means fewer errors which could potentially mean less testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type annotations can act like code documentation
&lt;/h3&gt;

&lt;p&gt;Type annotations help us to understand what type of arguments a function expects, for example, and what it returns.&lt;/p&gt;

&lt;p&gt;This makes code more readable and makes it easier for others and for us to understand what the code is supposed to do.&lt;/p&gt;

&lt;p&gt;Another advantage of TypeScript is that IDEs can provide more specific and smarter IntelliSense when they know exactly what types of data you are processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get Started with TypeScript
&lt;/h2&gt;

&lt;p&gt;Let's begin by installing the TypeScript package. Here we have two options: we can either install it globally so we can use it on any project in the system, or we can install it to use on the specific project we're working on.&lt;/p&gt;

&lt;p&gt;You can install TypeScript globally by running this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't wish to install globally you can just run 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;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt; &lt;span class="nx"&gt;typescript&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the local installation, TypeScript is installed as a Dev-dependency because we use it for development. It has to first compile to JavaScript before it can be used in production. The browser can't execute TypeScript.&lt;/p&gt;

&lt;p&gt;After installing TypeScript, we need to initiate a new project. You can do that by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tsc &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command initiates a new &lt;em&gt;tsconfig.json&lt;/em&gt; file in the root directory of the project. This config file comes with all the configuration options we have for using TypeScript in a project.&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%2Fwww.freecodecamp.org%2Fnews%2Fcontent%2Fimages%2F2021%2F05%2Fimage1-1.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%2Fwww.freecodecamp.org%2Fnews%2Fcontent%2Fimages%2F2021%2F05%2Fimage1-1.png" alt="an example of a tsconfig file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the compile options for a particular project can be specified in the tsconfig.json file under the &lt;em&gt;compileOptions&lt;/em&gt; key.&lt;/p&gt;

&lt;p&gt;The file comes with some config options by default but you can add more options to the project as needed. You can comment out or delete unused compiler options.&lt;/p&gt;

&lt;h3&gt;
  
  
  Built-In Types in TypeScript
&lt;/h3&gt;

&lt;p&gt;Typescript comes built-in with all the primitive types in JavaScript like string, number, and boolean.&lt;/p&gt;

&lt;p&gt;The types can then be assigned to variables to specify what data type should be assigned to the variable. This is called type annotation.&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;const&lt;/span&gt; &lt;span class="nx"&gt;myName&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Joel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myAge&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;99&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TypeScript annotations are not always necessary because TypeScript automatically infers the type of a variable based on its initial value or usage. Therefore the following would also be valid TypeScript code:&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="c1"&gt;// myName is inferred type 'string'&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jonathan&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;h3&gt;
  
  
  Arrays in TypeScript
&lt;/h3&gt;

&lt;p&gt;To specify the type of an array you can use the syntax &lt;code&gt;string[]&lt;/code&gt; or &lt;code&gt;number[]&lt;/code&gt;. This effectively means 'array of strings or array of numbers'.&lt;/p&gt;

&lt;p&gt;You'll also see people use the syntax &lt;code&gt;Array&amp;lt;number&amp;gt;&lt;/code&gt; or &lt;code&gt;Array&amp;lt;string&amp;gt;&lt;/code&gt; which means the same thing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Union Types in TypeScript
&lt;/h3&gt;

&lt;p&gt;Union types allow us to define several types that may be assigned to a variable. For this, we use a pipe | to specify the various 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;const&lt;/span&gt; &lt;span class="nx"&gt;someValue&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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&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 &lt;code&gt;null | undefined&lt;/code&gt; can be assigned to any variable but TypeScript comes with the &lt;em&gt;strictNullChecks&lt;/em&gt; compiler option which does not allow assigning both to a variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions in TypeScript
&lt;/h3&gt;

&lt;p&gt;Functions can also receive type annotations. However, with TypeScript functions, they can only receive the specified parameters. Nothing more nothing less.&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;introduction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&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="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Hello, my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I'm {age} years old`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Function parameters receive normal type annotation.&lt;/p&gt;

&lt;p&gt;TypeScript functions must also specify the return data type. In the case where a function returns nothing, we can use &lt;em&gt;void&lt;/em&gt; type as the return data type.&lt;/p&gt;

&lt;p&gt;We can also use the &lt;code&gt;?&lt;/code&gt; operator to specify &lt;strong&gt;parameters that are optional&lt;/strong&gt;. In this case, Typescript won't complain if the parameter is not passed on the function call.&lt;/p&gt;

&lt;p&gt;We can also assign default values to parameters just like we would in normal JavaScript.&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;const&lt;/span&gt; &lt;span class="nx"&gt;introduction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;job&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;developer&lt;/span&gt;&lt;span class="dl"&gt;'&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;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`Hello, my name is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I'm &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old. I work as a &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;job&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that in this example I used the JavaScript &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" rel="noopener noreferrer"&gt;arrow function&lt;/a&gt; syntax and specified that the job parameter is optional and assigned a default value 'developer' to it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;any&lt;/code&gt; type in TypeScript
&lt;/h3&gt;

&lt;p&gt;In TypeScript, every variable whose type cannot be inferred becomes implicitly the type &lt;em&gt;any&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Any&lt;/code&gt; is typically a wild card type that literally means 'whatever type'. We can also explicitly assign the type &lt;em&gt;any&lt;/em&gt; to a variable.&lt;/p&gt;

&lt;p&gt;However, &lt;code&gt;any&lt;/code&gt; typings are usually considered to be problematic.&lt;/p&gt;

&lt;p&gt;Typescript comes with the &lt;em&gt;noImplicitAny&lt;/em&gt; compiler option which raises an error when we assign the type &lt;em&gt;any&lt;/em&gt; to a variable or expression.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Create Your Own Types in TypeScript
&lt;/h3&gt;

&lt;p&gt;TypeScript offers a way for us to define and use our own types for inputs. Here we can describe the exact type that is acceptable for a particular input.&lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;type&lt;/code&gt; keyword to define our own 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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Operator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;multiply&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;add&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;divide&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the &lt;code&gt;Operator&lt;/code&gt; type can accept either of the values. Notice how we use the OR operator &lt;code&gt;|&lt;/code&gt; to create a union type. In this case, any variable assigned the type Operator can accept any of the three values.&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript Example Project
&lt;/h2&gt;

&lt;p&gt;Let's now use this knowledge to create a simple calculator program. A user can only enter one of three operations - add, multiply, or divide. If you want to, take a moment and try to attempt this then you come back and follow along.&lt;/p&gt;

&lt;p&gt;Hopefully, you tried it on your own. The program may then 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;Operation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;multiply&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;add&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;divide&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&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;number&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;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;op&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Operation&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;op&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;multiply&lt;/span&gt;&lt;span class="dl"&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;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;add&lt;/span&gt;&lt;span class="dl"&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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;divide&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&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;Can&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="nx"&gt;divide&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="mi"&gt;0&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;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;default&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;Operation unknow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to read the above code and see if you can figure out what is going on.&lt;/p&gt;

&lt;p&gt;We can also create custom types using the &lt;code&gt;interface&lt;/code&gt; keyword. Interfaces allow us to define the property and type of an object. An interface can have the ability to extend another interface.&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;interface&lt;/span&gt; &lt;span class="nx"&gt;Employee&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;title&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Manager&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Employee&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;meeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;topic&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&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 define an interface Employee which has two properties - &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt;, both of which are of the type &lt;em&gt;string&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We then use this interface to create another interface &lt;code&gt;Manager&lt;/code&gt; which has the same properties as the Employee interface but with a meeting method.&lt;/p&gt;

&lt;p&gt;At the outset, I mentioned that Typescript is a structurally typed language. This means that if an element has the same properties as another, they're both of the same types.&lt;/p&gt;

&lt;p&gt;The same is true with interfaces. If an object has the properties of an interface then it has the type of the interface. Such an object can have additional properties as long as some properties match those of the interface.&lt;/p&gt;

&lt;p&gt;We can now use our defined interface such 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;const&lt;/span&gt; &lt;span class="nx"&gt;newEmployee&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Employee&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;Joel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FrontEnd Developer&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;So far we've seen that we can create our own types using the &lt;em&gt;type&lt;/em&gt; and &lt;em&gt;interface&lt;/em&gt; keywords. But, what is the difference between the two?&lt;/p&gt;

&lt;p&gt;The most notable difference is that defining multiple interfaces with the same name will result in a merged interface. On the other hand, defining multiple types with the same name will result in an error indicating that the name is already declared.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Typescript has a lot of features that can't simply be exhausted in this article. I just highlighted a few of the features that may be helpful to understand in order to get started working with it.&lt;/p&gt;

&lt;p&gt;You can learn more about Typescript by reading the &lt;a href="https://www.typescriptlang.org/docs/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you liked this article, consider following me on &lt;a href="https://twitter.com/codingknite" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; or connecting with me on &lt;a href="https://linkedin.com/in/joelmugalu" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;. I share content about programming and what am learning. Feel free to get in touch or share your thoughts regarding TypeScript in the comment section below.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to add a video to your GitHub README</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Tue, 01 Dec 2020 11:05:48 +0000</pubDate>
      <link>https://forem.com/codingknite/how-to-add-a-video-to-your-github-readme-52hk</link>
      <guid>https://forem.com/codingknite/how-to-add-a-video-to-your-github-readme-52hk</guid>
      <description>&lt;p&gt;As you might already know the version of Markdown that GitHub uses does not support adding videos. Although you might find work arounds if you search hard enough, the closest you'll get to is embedding a YouTube video in your markdown file. But what if you have a custom video? A video on your device?&lt;/p&gt;

&lt;p&gt;Well, there's a workaround, it won't enable you to upload the video but you'll get the same results. The thing is GitHub READMEs work perfectly with GIFs. GIF is a bitmap graphical image format. So what you get isn't necessarily a video but the result is relatively similar.&lt;/p&gt;

&lt;p&gt;Now all you have to do is obtain the desired video and use a tool such as &lt;a href="https://cloudconvert.com/mp4-to-gif"&gt;CloudConvert&lt;/a&gt; to convert the video to a gif.&lt;/p&gt;

&lt;p&gt;However, it's worth noting that the longer the video the bigger the size and you might experience some lagging depending on the type of video and the converting software used. Besides this you should generally get good results.&lt;/p&gt;

&lt;p&gt;After converting the video to a GIF. All you have to do is create a GitHub repository with the same name as your GitHub username. For example my GitHub username is &lt;code&gt;codingknite&lt;/code&gt; so the new repository would also be called &lt;code&gt;codingknite&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then simply add the GIF in your README.md file the same way you would add an image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![caption](link to image / GIF)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's all. Push your files to your GitHub account and you should have an impressive README.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;Recently, GitHub added support for different media formats. Therefore you do not need to use a third party converter to convert your video to GIF format.&lt;/p&gt;

&lt;p&gt;With the latest update all you have to do is open your markdown editor in GitHub and just drag your media into the editor and it should be added to your README.&lt;/p&gt;

&lt;p&gt;You can checkout &lt;a href="https://github.com/codingknite"&gt;mine&lt;/a&gt; to see what I chose. Feel free to also connect with me on &lt;a href="https://twitter.com/codingknite"&gt;Twitter&lt;/a&gt; or &lt;a href="https://linkedin.com/in/joelmugalu"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Other articles you may like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/codingknite/typescript-getting-started-39dm"&gt;TypeScript: Getting Started&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/codingknite/how-to-use-tutorials-to-learn-code-effectively-377f"&gt;How to use tutorials effectively to learn how to code &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/codingknite/data-types-and-operators-in-javascript-everything-you-need-to-know-ah1"&gt;Data Types and Operators in JavaScript: Everything You Need To Know&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to use tutorials effectively to learn how to code</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Mon, 30 Nov 2020 09:01:59 +0000</pubDate>
      <link>https://forem.com/codingknite/how-to-use-tutorials-to-learn-code-effectively-377f</link>
      <guid>https://forem.com/codingknite/how-to-use-tutorials-to-learn-code-effectively-377f</guid>
      <description>&lt;p&gt;Tutorials are no doubt an incredible way to learn how to code. With the growth of popular websites such as YouTube, tutorials have become almost accessible to anyone.&lt;/p&gt;

&lt;p&gt;This also means that most tutorials are free. They're also usually taught by industry professionals. On top of this, Tutorials tend to be shorter than courses and in most cases they get straight to the point. &lt;/p&gt;

&lt;p&gt;But tutorials can be a double edged sword. So these advantages can very quickly become disadvantages. In fact if you've ever heard of the term "tutorial hell" then you know that tutorial is part of the name.&lt;/p&gt;

&lt;p&gt;Without a proper strategy  tutorials can lead one to a never ending path of watching tutorials.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Essence of strategy is choosing what not to do&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So in this article am going to discuss some practical ways that can help you learn how to code using tutorials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn The Fundamentals
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“As to methods there may be a million and then some, but principles are few. The man who grasps principles can successfully select his own methods. The man who tries methods, ignoring principles, is sure to have trouble” — Harrington Emerson&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the most common things that can lead one to the path of tutorial hell is having knowledge gaps. Most tutorials do not cover fundamental concepts. They simply cover certain specific aspects such as "How to build an x project with an x framework". &lt;/p&gt;

&lt;p&gt;So embarking on a tutorial like that can introduce you to fundamental concepts that you were not aware of. Naturally you'd watch other tutorials to understand these concepts. And the cycle goes on and on.&lt;/p&gt;

&lt;p&gt;Before watching a tutorial be sure that you know the fundamental concepts of the subject at hand. &lt;/p&gt;

&lt;p&gt;Besides tutorials, fundamentals are important to any developer. Frameworks come and go but the fundamentals remain. I'd recommend taking a course that teaches the fundamentals of programming in general. &lt;/p&gt;

&lt;p&gt;One such course is the famous &lt;a href="https://www.edx.org/course/cs50s-introduction-to-computer-science" rel="noopener noreferrer"&gt;CS50&lt;/a&gt; offered by Harvard University. This course is amazing and I can't recommend it enough. I'm sure of this because I took the course myself. It's free and coming from Harvard you know the quality is top notch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Take Notes
&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%2Flh3.googleusercontent.com%2Fproxy%2Fvz5UEf1qOUmkhF6W1OqYL6QRGgsAXbLF4V0LAERoaqbBlQU2eXTEvoTtZn4e-T2TAXLvkKIdoMQFYX5Dad79qmG7xyABXD-qNmNdSvA_QjyBWYpyDVZZzejDCyIaqEer7OntZ7RfbPhCAfSaUNOZ0KaTh2m-2TgsR68" 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%2Flh3.googleusercontent.com%2Fproxy%2Fvz5UEf1qOUmkhF6W1OqYL6QRGgsAXbLF4V0LAERoaqbBlQU2eXTEvoTtZn4e-T2TAXLvkKIdoMQFYX5Dad79qmG7xyABXD-qNmNdSvA_QjyBWYpyDVZZzejDCyIaqEer7OntZ7RfbPhCAfSaUNOZ0KaTh2m-2TgsR68" alt="Meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another very effective yet underrated way to learn from tutorials is to take notes. Being in the digital age, it's not uncommon for people to take digital notes using iPads and laptops.&lt;/p&gt;

&lt;p&gt;Where as I myself do this from time to time I still vouch for the good old hand written notes. I strongly believe that you're most likely to remember what you wrote in a hand taken note written in a physical notebook than in an digital one.&lt;/p&gt;

&lt;p&gt;Don't afraid to pause the tutorial and write something that you feel is worth remembering. The beauty of writing notes is that it allows you to express yourself in the way you understood what you've learnt. So what you're writing is what you understood not what the instructor said.&lt;/p&gt;

&lt;p&gt;Taking notes is especially important because of our forgetful nature. The moment your brain takes in information. That information is discarded as soon as possible unless you practically apply it.&lt;/p&gt;

&lt;p&gt;Which brings me to the next point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build. Build. Build.
&lt;/h2&gt;

&lt;p&gt;You'll agree with me that the only thing that makes a tutorial worth your time is how practical it is. &lt;/p&gt;

&lt;p&gt;The idea of building a project during the tutorial is what drives you to watch it.&lt;/p&gt;

&lt;p&gt;Looking at it from another perspective, that is the general goal of a tutorial. It's meant to show you how to apply a certain skill. So unless you build. You will never benefit from tutorials.&lt;/p&gt;

&lt;p&gt;If you struggle with getting ideas for what to build then look up some articles on project ideas. &lt;/p&gt;

&lt;p&gt;You can also decide to add more features to the already existing application built in the tutorial.&lt;/p&gt;

&lt;p&gt;The key to learning with this method though is to make sure you implement these features by yourself. That's the only way to apply what you've learnt.&lt;/p&gt;

&lt;p&gt;Be sure to use google to the fullest when you get stuck. Lots of questions have already been answered including the one you might have. The chances of you having a completely new question are probably 1 of 100.&lt;/p&gt;

&lt;p&gt;However, it's worth noting that these days many tutorials urge you to code a long. It's believed that this is supposed to help you with retention. &lt;/p&gt;

&lt;p&gt;I personally have mixed feelings about this.&lt;br&gt;
In my opinion I don't see how doing the same exact thing that another person is doing step by step word for word is supposed to help you learn a new skill. But that's just me. Choose to do what works for you.&lt;/p&gt;

&lt;p&gt;If you learn better by coding along then code along. If not I'd suggest watching the entire lecture and trying to re-implement what the instructor did on your own. This is most likely to test the degree to which you understood what was being taught.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spaced Repetition
&lt;/h2&gt;

&lt;p&gt;Spaced repetition is a learning method where the learner continues to revise what they learnt over a spaced amount of time.&lt;/p&gt;

&lt;p&gt;So if you learn something new today then you would come back to revise it say after 3 days and then repeat that over and over again.&lt;/p&gt;

&lt;p&gt;This learning method is very effective especially when you're learning theoretical over practical things. &lt;/p&gt;

&lt;p&gt;Like I mentioned earlier, your brain discards unused information. So revising that information after a certain period is a good trick to get the knowledge to sink in.&lt;/p&gt;

&lt;p&gt;Since you're most unlikely to apply everything learnt from a tutorial at once, this method can help and I've found it to be effective myself.&lt;/p&gt;

&lt;p&gt;Speaking of learning methods, another great one is the Pomodoro technique. Now this more of a time management technique. The technique uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. &lt;/p&gt;

&lt;p&gt;One of the reasons you're most likely to forget or even get bored during a tutorial is if you keep taking in information for very long periods of time.&lt;/p&gt;

&lt;p&gt;I have also found this method to be very effective and I tend to cover more material when using this technique. Try it out and see if it would work for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Share What You Learn
&lt;/h2&gt;

&lt;p&gt;This is standard and you've probably heard that the best way to learn is to teach. This is absolutely true and I can't recommend it enough.&lt;/p&gt;

&lt;p&gt;The moment you learn something, it's true that there is a ton of people out there who don't know what you just learnt or those that know of it but don't fully understand it.&lt;/p&gt;

&lt;p&gt;But this step involves more than just sharing what you feel you understood. A certain amount of effort is required. There's a saddening amount of mediocre articles out there that tend to lead to more confusion than clarity.&lt;/p&gt;

&lt;p&gt;Blogging requires research in order for you to make sure that what you understand harmonizes with what should actually be understood. &lt;/p&gt;

&lt;p&gt;Other than that blogging is a tremendous way to learn. And you don't need to build your own blogging site from scratch. There are lots options out there. You can use platforms like Medium, Dev, and recently an interesting one came up called Hashnode. Now I'm also new to Hashnode myself but I've heard only good things about it. So shoot your shot. There's no harm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beware of Tutorial Hell
&lt;/h2&gt;

&lt;p&gt;Now this is the biggest challenge that one could face from trying to learn from a tutorial. That of finding oneself in a never ending loop of watching tutorials endlessly.&lt;/p&gt;

&lt;p&gt;I already covered part of why one might end up in tutorial hell. That of poor knowledge of the fundamentals. &lt;/p&gt;

&lt;p&gt;However, the thing is that even those with a good grasp of the fundamentals can end up in tutorial hell. So what is the problem?&lt;/p&gt;

&lt;p&gt;The thing is that most people who end up watching tutorial after tutorial simply doubt that they have enough knowledge to build a project on their own.&lt;/p&gt;

&lt;p&gt;And so tutorial hell is simply like a quest for adequate knowledge.&lt;/p&gt;

&lt;p&gt;Couple this with the fear of failure of starting an own project and you'll see people find comfort in tutorial hell. &lt;/p&gt;

&lt;p&gt;The simple way out of tutorial hell is simply building a project on your own. That's all really.&lt;br&gt;
There's no magic pill and no you're not under a curse. All you got to do is build one project on your own, then another and soon enough you'll find that you can't even sit through a tutorial. And that's a good problem.&lt;/p&gt;

&lt;p&gt;Leaving tutorial hell can be as easy as child deciding to get up and walk instead of being carried around all day. But it can also be as hard as a child deciding to leave the comfort of being carried around all day and starting walking alone.&lt;/p&gt;

&lt;p&gt;So ultimately how you view tutorial hell and the amount of effort required for you to leave it is ultimately upon you.&lt;/p&gt;

&lt;p&gt;A practical step could be starting small. Whether you fear to fail or think you don't know enough - start small. Build small projects and then project from there.&lt;/p&gt;

&lt;p&gt;Another thing is to try to figure out how you learn best. You see tutorials aren't the only way to learn. If all attempts fail then trying switching up your learning methods. &lt;/p&gt;

&lt;p&gt;You could try reading articles instead or taking a course or even reading books. The possibilities are endless. &lt;/p&gt;

&lt;p&gt;Whichever way works for you, find that and stick to it.&lt;/p&gt;

&lt;p&gt;I hope you found this article helpful. If you did feel free to share it with a friend. If you would like to say hi to me then feel free to do so via my &lt;a href="https://twitter.com/joelpmugalu" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; or &lt;a href="https://linkedin.com/in/joelpm" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; accounts. I also have a &lt;a href="https://github.com/mojpm" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;😉&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Stack Data Structure Explained In JavaScript</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Fri, 13 Nov 2020 08:35:08 +0000</pubDate>
      <link>https://forem.com/codingknite/the-stack-data-structure-explained-in-javascript-59d3</link>
      <guid>https://forem.com/codingknite/the-stack-data-structure-explained-in-javascript-59d3</guid>
      <description>&lt;p&gt;Algorithms and Data S­tructures are the heart and soul of computer science and programming. They are part of the fundamentals of computer programming. In this series, I'm going to make an effort to explain the most commonly used data structures in JavaScript.&lt;/p&gt;

&lt;p&gt;To begin with a data structure is simply a format of organizing and storing data.&lt;/p&gt;

&lt;p&gt;In this article we're going to cover the stack. By the end of this article you'll have understood what a stack is, the methods used on a stack and how to implement a stack by yourself in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is A Stack?
&lt;/h2&gt;

&lt;p&gt;A stack is a last in first out type of data structure. This means that the last element to go in a stack is the first to come out.&lt;/p&gt;

&lt;p&gt;You can think of it as a stack of books. In order to obtain the last book in the stack, you must first remove all the books on top. And when you wish to add a book, you simply put it on top.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hv_o4xNN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/gfs90xd7shj0tjlsncy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hv_o4xNN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/gfs90xd7shj0tjlsncy9.png" alt="Stack Representation" width="429" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are four main operations that we can perform on stacks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Adding to the stack. For this operation we use the &lt;code&gt;push&lt;/code&gt; method which adds an item on top of the stack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Removing from the stack. For this operation we use the &lt;code&gt;pop&lt;/code&gt; method which simply removes the item on top of the stack and returns it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Checking the item on top the stack. For this method we use the &lt;code&gt;peek&lt;/code&gt; method to simply return the item on top of the stack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lastly, we can check for the &lt;code&gt;size&lt;/code&gt; of the array.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In JavaScript, arrays give us the properties of a stack. With arrays we can push, pop and check the length of the array.&lt;/p&gt;

&lt;p&gt;A classic example that we can use to see how we would use a stack in JavaScript is the palindrome checker. A palindrome checker is a program that checks whether a word is spelt the same way both backwards and frontwards. For example &lt;code&gt;ana&lt;/code&gt; is a palindrome and so is &lt;code&gt;racecar&lt;/code&gt; and &lt;code&gt;bob&lt;/code&gt;. Here is the implementation in JavaScript.&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;const&lt;/span&gt; &lt;span class="nx"&gt;checkPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reverseWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;reverseWord&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pop&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;reverseWord&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`"&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;" is a palindrome`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is not a palindrome`&lt;/span&gt;&lt;span class="p"&gt;;&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;checkPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;racecar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// "racecar" is a palindrome&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we used an array as a stack and to it we added every letter in the word. We then removed every last element in the array or stack in this case in order to create the reverse word. And lastly we checked whether the reversed word was the same as the word we received in the function.&lt;/p&gt;

&lt;p&gt;When it comes to the time complexity of a stack, the worst case scenario of searching a stack is O(n) because the bigger the stack the more time we'll take searching it. The best case scenario of searching a stack is Ω(1) assuming the item we're searching for is the first item in the stack and the average case is O(n)&lt;/p&gt;

&lt;p&gt;When it comes to deletion and insertion both the best, worst and average cases are O(1) simply because we can only add or remove one item on the stack&lt;/p&gt;

&lt;p&gt;If you would like to further understand Big O notation, space and time complexity then consider reading this &lt;a href="https://www.tutorialspoint.com/time-and-space-complexity-in-data-structure"&gt;article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In most cases we would never need to create an own stack, arrays suffice well enough. But in order to further understand stacks, we will implement a stack from scratch in JavaScript.&lt;/p&gt;

&lt;p&gt;In this example we will use JavaScript classes to create the stack. I will implement the stack then explain what's going on. You can also try to figure out what's going on.&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;class&lt;/span&gt; &lt;span class="nx"&gt;Stack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;size&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;peek&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our stack will be an object and we will use the length variable to keep track of the size of the stack.&lt;/p&gt;

&lt;p&gt;The push method accepts the value we want to add on the top of the stack. Instead of indices, each value will be paired to a property in which case the property will be the position of the value in the stack. This will allow us to still use the concept of indices to access items. Finally we increment the length.&lt;/p&gt;

&lt;p&gt;The pop method does not accept an argument because it simply returns the item on top of the stack. Since the length keeps track of the stack's size, the length will represent the last item in the stack. We store the last item in the result variable before deleting it from the stack.&lt;/p&gt;

&lt;p&gt;The size method is probably the simplest because all we do is simply return the length of the stack. That will be it's size.&lt;/p&gt;

&lt;p&gt;And lastly the peek method simply returns the item on top of the stack. We subtract one from the length because the first item in the stack is stored at position 0 not 1. So whereas the length might be for example five, the first value is at position 0 and the last at 4.&lt;/p&gt;

&lt;p&gt;Now let's see if indeed our stack works.&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;const&lt;/span&gt; &lt;span class="nx"&gt;myStack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;75&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;28&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;91&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;19&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myStack&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;36&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;myStack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 6&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;myStack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 36&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;myStack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 5&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;myStack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;peek&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// 19&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This was a simple implementation of the Stack Data Structure in JavaScript. I hope you learnt something. I put this code in a &lt;a href="https://github.com/mojpm/algorithms-data-structures"&gt;repository&lt;/a&gt; on github in case you would like to refer to it later.&lt;br&gt;
If you have any feedback or would just like to say hi feel free to do so via my Twitter account @joelpmugalu&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>algorithms</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>All the resources you need for Frontend development</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Sun, 01 Nov 2020 16:21:16 +0000</pubDate>
      <link>https://forem.com/codingknite/all-the-resources-you-need-for-frontend-development-3jeo</link>
      <guid>https://forem.com/codingknite/all-the-resources-you-need-for-frontend-development-3jeo</guid>
      <description>&lt;p&gt;I've read many articles about resources for Frontend development. But every time I needed a resource that I'd read about,  I had to go through the hustle of looking for the article again.&lt;/p&gt;

&lt;p&gt;To solve this problem I decided to put all these resources in &lt;a href="https://github.com/developer-resources"&gt;one place&lt;/a&gt;. Somewhere I could just look if I needed a resource.&lt;/p&gt;

&lt;p&gt;I also decided to include some resources for those that are learning new technologies.&lt;/p&gt;

&lt;p&gt;In the list I included resources for HTML, CSS, JavaScript, React, Icons, Illustrations, fonts and many more.&lt;/p&gt;

&lt;p&gt;I combined all these resources and put them in &lt;a href="https://github.com/developer-resources/frontend-development"&gt;this Repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I also made the repo open source so that others can include resources that I didn't. &lt;/p&gt;

&lt;p&gt;Feel free to check it out and contribute to it if you can. I hope it helps you out.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>resources</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Data Types and Operators in JavaScript: Everything You Need To Know</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Mon, 24 Aug 2020 14:07:41 +0000</pubDate>
      <link>https://forem.com/codingknite/data-types-and-operators-in-javascript-everything-you-need-to-know-ah1</link>
      <guid>https://forem.com/codingknite/data-types-and-operators-in-javascript-everything-you-need-to-know-ah1</guid>
      <description>&lt;p&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Data_type"&gt;Wikipedia&lt;/a&gt;: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. This data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In simple terms a data type is a type of value.  A data type tells the programming language how the value is meant to be used and the operations that can be carried out on it.&lt;/p&gt;

&lt;p&gt;In this article we are going to explore all the details of different data types in JavaScript and the operations that can be carried out on them. This is an in depth article so you might want to grab a pen and paper.&lt;/p&gt;

&lt;p&gt;JavaScript has two main types of data types: primitive data types and objects. Let's explore both of them.&lt;/p&gt;

&lt;h1&gt;
  
  
  Primitive Data Types
&lt;/h1&gt;

&lt;p&gt;A primitive data type can be understood  as a basic data type in JavaScript. Some primitive data types only accept a set value(s) and others accept certain type of values.Primitive data types are immutable. That means their values cannot be changed or mutated. I'll further explain this in the article.&lt;br&gt;
Let's look at the primitive data types in JavaScript.&lt;/p&gt;
&lt;h2&gt;
  
  
  Numbers
&lt;/h2&gt;

&lt;p&gt;Values of the number type are numeric values written as usual numbers like &lt;code&gt;12&lt;/code&gt;, &lt;code&gt;67&lt;/code&gt; and &lt;code&gt;85&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript uses 64 bits to store a number. Given 64 bits JavaScript can represent up to &lt;strong&gt;18  quintillion&lt;/strong&gt;  numbers. You don't have to remember that number. The point is we can write very huge numbers with JavaScript.&lt;/p&gt;

&lt;p&gt;All operations carried out on whole numbers are guaranteed to be precise and accurate.&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;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="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//79&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="mi"&gt;1234597654&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;987654132476&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//988888730130&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sadly that is not the case with floating point numbers. In JavaScript floating point numbers are numbers that have decimal points.&lt;br&gt;
Take a look at 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="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="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&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="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//0.30000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at the example you would expect that adding &lt;code&gt;0.1 + 0.2&lt;/code&gt; would result in &lt;code&gt;0.3&lt;/code&gt;. Instead we get &lt;code&gt;0.30000000000000004&lt;/code&gt;. Why is that?&lt;/p&gt;

&lt;p&gt;In real math we have an infinite set of numbers to work with. In JavaScript we only have 64 bits (18 quintillion numbers). Therefore we cannot precisely represent floating point numbers with only 64 bits. When you add &lt;code&gt;0.1 + 0.2&lt;/code&gt; JavaScript returns the closest available number. This doesn't need to get you worried unless you want to calculate the precise age of the universe.&lt;/p&gt;

&lt;p&gt;Let's look at the operations we can carry out on numbers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arithmetic Operations
&lt;/h3&gt;

&lt;p&gt;You've probably guessed already that we can carry out arithmetic operations on numbers in JavaScript.&lt;/p&gt;

&lt;p&gt;Just like usual math we can add, subtract, multiply and divide numbers. The symbols used to carry out these operations are called operators. The &lt;code&gt;+&lt;/code&gt; operator is used for addition, &lt;code&gt;-&lt;/code&gt; for subtraction, &lt;code&gt;*&lt;/code&gt; for multiplication and &lt;code&gt;/&lt;/code&gt; for division.&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;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="mi"&gt;1&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="c1"&gt;//3&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="mi"&gt;10&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;//5 &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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//200&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="mi"&gt;120&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="c1"&gt;//60&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when working with operators we must look out for something called &lt;strong&gt;operator precedence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://developer.mozilla.org/en-US/"&gt;Mozilla Developer Network&lt;/a&gt; (MDN):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Operator precedence determines how operators are parsed concerning each other. Operators with higher precedence become the operands of operators with lower precedence.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's look at this code&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;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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Operations in JavaScript do not occur from left to right. Rather some operators take precedence over others. So &lt;code&gt;2 + 2 * 10&lt;/code&gt; is not &lt;code&gt;4 * 10 = 40&lt;/code&gt; but &lt;code&gt;2 + 20 = 22&lt;/code&gt; because &lt;code&gt;*&lt;/code&gt; has a higher precedence than &lt;code&gt;+&lt;/code&gt; so that operation happens first.&lt;/p&gt;

&lt;p&gt;If you would like to carry out arithmetic operations left to right, you can do so with parenthesis.&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;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="mi"&gt;2&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="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read more about operator precedence &lt;a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Operator_Precedence"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Special Numbers
&lt;/h3&gt;

&lt;p&gt;As it turns out, not all numbers have a numeric value in JavaScript. JavaScript has three special numbers. Infinity for positive infinities, -Infinity for negative infinities and NaN which means "Not a Number".&lt;br&gt;
These special numbers are used to represent foul operations.&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;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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//Infinity&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//-Infinity&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="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NaN is of special interest because it's quite the trouble causer. It's a number that means "Not A Number". This can be very confusing at times. &lt;/p&gt;

&lt;p&gt;According to MDN:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are five different types of operations that return NaN:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number cannot be parsed (e.g. parseInt("blabla") or Number(undefined))&lt;/li&gt;
&lt;li&gt;Math operation where the result is not a real number (e.g. Math.sqrt(-1))&lt;/li&gt;
&lt;li&gt;Operand of an argument is NaN (e.g. 7 ** NaN)&lt;/li&gt;
&lt;li&gt;Indeterminate form (e.g. 0 * Infinity)&lt;/li&gt;
&lt;li&gt;Any operation that involves a string and is not an addition operation (e.g. "foo"/3)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can test for NaN using the method &lt;code&gt;Number.isNaN(number)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, simply put NaN is a numeric value that represents an invalid result.&lt;/p&gt;

&lt;p&gt;Let's look at another data type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Strings
&lt;/h2&gt;

&lt;p&gt;A string is another data type in JavaScript. Strings represent text. This text can be enclosed in either single quotes &lt;code&gt;''&lt;/code&gt;, double quotes &lt;code&gt;""&lt;/code&gt; or back ticks &lt;code&gt;(&lt;/code&gt;&lt;code&gt;)&lt;/code&gt;.&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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is text&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This is also text&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;Interestingly though, strings are not just text in JavaScript. Behind the scenes each letter in a string is a number. If you've ever heard of the ASCII standard then this is it. Each character in a computer has a number assigned to it. For example lower case a is 65 and uppercase A is 97. Same with all the other letters and characters.&lt;/p&gt;

&lt;p&gt;However, the ASCII standard was limited in the number of characters it could represent. This led to the birth of the Unicode standard. With the Unicode standard, just about any character can be represented with a number. Even Emojis. That was just an interesting fact.&lt;/p&gt;

&lt;p&gt;We can't carry out subtraction, multiplication and division on strings. Doing so would yield to &lt;code&gt;NaN&lt;/code&gt; which we just talked about.&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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No&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="s2"&gt;Arithmetic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//NaN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, we can use the addition operator on strings. This is called string concatenation. This way we can join two strings into one.&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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yes&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="s2"&gt; Concatenation&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//Yes Concatenation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use bracket notation to access individual characters in a string. But we cannot change these characters. As I mentioned earlier this is because primitive data types are immutable. If we try to mutate strings, JavaScript will throw an error if in &lt;a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Strict_mode"&gt;strict mode&lt;/a&gt;&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myUsername&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;codingknite&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myUsername[0]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//c&lt;/span&gt;
&lt;span class="nx"&gt;myUsername&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&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;k&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Throws error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Boolean
&lt;/h2&gt;

&lt;p&gt;Boolean is another data type in JavaScript with only two values written as &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;. Logical operations can be carried out with Boolean. Think of boolean as answers to yes or no questions that we ask JavaScript.&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;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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;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;//true&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's quite a number of operators we can use to carry out operations on boolean.&lt;/p&gt;

&lt;h3&gt;
  
  
  Equality Operators
&lt;/h3&gt;

&lt;p&gt;Equality operators are used to compare whether or not two values are equal to each other. The result is a boolean value.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The (==) operator denotes "equal to"&lt;/li&gt;
&lt;li&gt;The (!=) operator denotes "not equal to"&lt;/li&gt;
&lt;li&gt;The (===) operator denotes "strictly equal to"&lt;/li&gt;
&lt;li&gt;The (!==) operator denotes "strictly not equal to"
&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="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="mi"&gt;2&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="c1"&gt;//True &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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&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="s2"&gt;pineapple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JavaScript&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="s2"&gt;JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JavaScript&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="s2"&gt;Java&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is one value in JavaScript which in not equal to itself. And it's none other than NaN&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;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="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;According to MDN:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Unlike all other possible values in JavaScript, it is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN or not, because both NaN == NaN and NaN === NaN evaluate to false. Hence, the necessity of an isNaN function.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The issue with NaN not being equal to NaN is historical. Just Accept it as a fact of life. If you're interested in reading more about NaN and why it's not equal to itself, consider reading this &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN"&gt;article&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a one difference between the equality operator and the strict equality operator which i'll get to in a second.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison Operators
&lt;/h3&gt;

&lt;p&gt;Comparison operators are used to compare two or more values. The result is either of the boolean values.&lt;/p&gt;

&lt;p&gt;These are the most common comparison operators.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The ( &amp;gt; ) operator is used to denote "greater than" &lt;/li&gt;
&lt;li&gt;The ( &amp;lt; ) operator is used to denote "less than"
console.log(5 &amp;gt; 3) //true 
console.log(10 &amp;lt; 15) //false&lt;/li&gt;
&lt;li&gt;The ( &amp;gt;= ) operator denotes "greater than or equal to"&lt;/li&gt;
&lt;li&gt;The ( &amp;lt;= ) operator denotes "less than or equal to"&lt;/li&gt;
&lt;li&gt;The ( == ) operator denotes "equal to"&lt;/li&gt;
&lt;li&gt;The ( === ) operator denotes "strictly equal to"&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Logical Operators
&lt;/h3&gt;

&lt;p&gt;Logical Operators are used to compare two conditions. JavaScript has three main logical operators.&lt;/p&gt;

&lt;h4&gt;
  
  
  AND Operator
&lt;/h4&gt;

&lt;p&gt;The AND operator written as &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; compares two values and returns true if both values on the left and right equate to true. Otherwise is returns false.&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;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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;&amp;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;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  OR Operator
&lt;/h4&gt;

&lt;p&gt;The OR operator written as &lt;code&gt;||&lt;/code&gt; compares two values and returns true if either value on the left or right equates to true. Otherwise it returns false.&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;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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;  &lt;span class="mi"&gt;10&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;//true&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="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  NOT Operator
&lt;/h4&gt;

&lt;p&gt;The NOT operator written as &lt;code&gt;!&lt;/code&gt; flips any value given to it. In other words !true becomes false and !false becomes true.&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;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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&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="s2"&gt;pineapple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Automatic Type Coercion
&lt;/h3&gt;

&lt;p&gt;When JavaScript receives the wrong values, it changes the data type of the resulting value.&lt;/p&gt;

&lt;p&gt;Let's Look at some code&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;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="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//36&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;50&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//38&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="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//13&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Thirteen&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;//NaN&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="kc"&gt;false&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="c1"&gt;//1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we see in the code above JavaScript secretly changes the types when it receives unusual values. The string '3' on the first line becomes the number 3. Same as the string "50". On the third line &lt;code&gt;true&lt;/code&gt; becomes 1 and &lt;code&gt;false&lt;/code&gt; becomes 0.&lt;/p&gt;

&lt;p&gt;Type coercion is what creates the difference between the equality operator and the strict equality 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="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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true &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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The equality operator carries out type coercion on the values it receives where as the strict operator does not carry out type coercion. This is why most JavaScript developers consider it a good practice to use the strict equality operator. To avoid unnecessary type coercion.&lt;/p&gt;

&lt;p&gt;Let's now look at the last two primitive data types&lt;/p&gt;

&lt;h2&gt;
  
  
  Null
&lt;/h2&gt;

&lt;p&gt;Null is a primitive data type in JavaScript used to represent an intentionally missing value. Null has only one value and that is &lt;code&gt;null&lt;/code&gt;. Null is a falsy value because it returns false in all boolean operations&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;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="o"&gt;!&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Undefined
&lt;/h2&gt;

&lt;p&gt;Undefined is also a primitive data type in JavaScript and just like Null it has only one value &lt;code&gt;undefined&lt;/code&gt;. It represents an unintentionally missing value. Undefined is also considered a falsy value because it returns false in boolean operations. When comparing &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; it's very important to look out for the equality and strict equality operators.&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;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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&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="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//false&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="o"&gt;!&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you have it. These are the primitive data types in JavaScript. But that's not all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Truthy and Falsy Values
&lt;/h3&gt;

&lt;p&gt;Falsy values are values that are return false in a condition.&lt;br&gt;
JavaScript has 5 basic falsy value: &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;''&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Truthy values are all the other values that are !falsy values (&amp;gt;_-)&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="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&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="nx"&gt;age&lt;/span&gt; &lt;span class="o"&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;0&lt;/span&gt;&lt;span class="p"&gt;)&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Age is defined&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;else&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Age is not defined&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;// returns 'Age is defined';&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to figure out why the above code logs 'Age is defined'&lt;/p&gt;

&lt;h3&gt;
  
  
  Unary Operator
&lt;/h3&gt;

&lt;p&gt;A Unary operator is an operator that accepts only one value.&lt;/p&gt;

&lt;p&gt;The best example of a unary operator is the &lt;code&gt;typeof&lt;/code&gt; operator which returns the type of value specified. In fact we can use this operator to check out all the data types we've talked about.&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;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="k"&gt;typeof&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//string&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="k"&gt;typeof&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//number&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="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//boolean&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="k"&gt;typeof&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;//boolean&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="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//object&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="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you noticed, the typeof null returned object. I will explain why that is so in the next article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Binary Operators
&lt;/h3&gt;

&lt;p&gt;Binary Operators are operators that carry out operations on two 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="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="mi"&gt;1&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="c1"&gt;//2&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="mi"&gt;12&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;//7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ternary Operator
&lt;/h3&gt;

&lt;p&gt;The ternary operator is used to check a condition and return a value based on whether or not the condition is true. It's like a quick if statement.&lt;/p&gt;

&lt;p&gt;The basic frame of a ternary operator is:&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;condition&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;value&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;true&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;value&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at this code&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="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;12&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;15 is greater than 12&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;15 is less than 12&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 15 is greater than 12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that's everything you need to know about primitive data types.&lt;br&gt;
What is the second type of data types in JavaScript? &lt;/p&gt;

&lt;h2&gt;
  
  
  Objects and Functions
&lt;/h2&gt;

&lt;p&gt;Now i don't know about you but that's enough data types for one day. In my next article am going to talk about objects and everything you need to know about them. So stay tuned. &lt;/p&gt;

&lt;p&gt;However, if you're interested I've written a blog post on functions. You can check it out &lt;a href="https://dev.to/codingknite/javascript-functions-broken-down-4fgh"&gt;here&lt;/a&gt; if you wish.&lt;/p&gt;

&lt;h2&gt;
  
  
  SUMMARY
&lt;/h2&gt;

&lt;p&gt;So, what have we seen.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A data type is basically the way a programming language understands the data it receives telling it how the data is to be used.&lt;/li&gt;
&lt;li&gt;Operations are basically the way we use the data received
*There are two types of data types&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Primitive Data Types&lt;/strong&gt;&lt;br&gt;
There are five main primitive data types&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numeric Values &lt;/li&gt;
&lt;li&gt;Arithmetic operations like Addition, Subtraction,     Multiplication and division can be carried out on them.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Strings&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How text is represented &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; can be used on them for concatenation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used for logical operations
-Two values written as true and false&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intentionally missing values&lt;/li&gt;
&lt;li&gt;Only one value null&lt;/li&gt;
&lt;li&gt;Falsy value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Undefined&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unintentionally missing values&lt;/li&gt;
&lt;li&gt;Only one value undefined &lt;/li&gt;
&lt;li&gt;Also a falsy value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;I hope you enjoyed this article. If you would like to follow my coding journey and be the first to know when I release a new article, be sure to follow me on &lt;a href="https://twitter.com/codingknite"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>If you could start learning to code from zero....what would you do differently?</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Tue, 07 Jul 2020 20:04:45 +0000</pubDate>
      <link>https://forem.com/codingknite/if-you-could-start-learning-to-code-from-zero-what-would-you-do-differently-4d0p</link>
      <guid>https://forem.com/codingknite/if-you-could-start-learning-to-code-from-zero-what-would-you-do-differently-4d0p</guid>
      <description></description>
      <category>discuss</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Comprehensive Introduction To Computer Algorithms</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Tue, 07 Jul 2020 11:33:50 +0000</pubDate>
      <link>https://forem.com/codingknite/a-comprehensive-introduction-to-computer-algorithms-35ge</link>
      <guid>https://forem.com/codingknite/a-comprehensive-introduction-to-computer-algorithms-35ge</guid>
      <description>&lt;p&gt;Problem solving makes up a huge part of computer science. In fact computer programming is basically the process of solving a problem with code. These problems are solved by means of algorithms. An algorithm is a step by step instruction to solve a problem.&lt;/p&gt;

&lt;p&gt;We implement algorithms in many aspects of our lives even without knowing it. For example if I wanted to make a cup of tea, I would take the following steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Walk to the kitchen&lt;/li&gt;
&lt;li&gt;Find the electric kettle &lt;/li&gt;
&lt;li&gt;Grab the electric kettle&lt;/li&gt;
&lt;li&gt;Walk to the sink&lt;/li&gt;
&lt;li&gt;Fill the kettle with water to capacity&lt;/li&gt;
&lt;li&gt;Boil the water to 100 degrees&lt;/li&gt;
&lt;li&gt;Put tea into teapot and add hot water&lt;/li&gt;
&lt;li&gt;Pour tea from teapot into teacup&lt;/li&gt;
&lt;li&gt;Add 3 teaspoons of sugar&lt;/li&gt;
&lt;li&gt;Stir the sugar&lt;/li&gt;
&lt;li&gt;Drink Tea&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Perhaps I missed something or I took weird steps but that's not important. What I've written above is what is commonly known as pseudo code. Its good to write pseudo code before solving an algorithm just to give you an idea of the steps you would take to solve the algorithm.&lt;/p&gt;

&lt;p&gt;The above steps are used an an example in this article. A human would take the above steps to make tea without a problem. But that is not the case with a computer. In order to write an algorithm similar to the above we would need to use building blocks for writing algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;Functions are like verbs or actions that tell a computer what to do. Functions are usually written for actions that would need to be repeated several times. For example in our steps we have several actions like &lt;strong&gt;walk&lt;/strong&gt; &lt;strong&gt;boil&lt;/strong&gt; &lt;strong&gt;grab&lt;/strong&gt; &lt;strong&gt;fill&lt;/strong&gt; etc. For such it would be ideal to write a function other than define them everywhere they need to be used.&lt;br&gt;
After writing the function we would simply call the function where it needs to be used.&lt;/p&gt;

&lt;p&gt;When writing functions, it's always good to keep the following in mind&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A Function should do only one thing. Like walk boil or fill. A function should never carry out multiple actions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Its a good practice to try to keep functions as short as possible. A good rule of thumbs is the &lt;strong&gt;10-10&lt;/strong&gt;. 10 functions in a program and 10 lines in a function. Of course this is not a commandment but it's something good to keep in mind.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wrote an article about functions in JavaScript. Feel free to check it out &lt;a href="https://dev.to/codingknite/javascript-functions-broken-down-4fgh"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Conditions
&lt;/h2&gt;

&lt;p&gt;Conditions are like branches that tell a computer what to do under certain conditions or at certain situations. Going back to our tea making algorithm, how would we know that the water has boiled to 100 degrees? In such a situation we could use a condition to check whether the water is 100 degrees and then stop boiling. Conditions start with the &lt;strong&gt;if&lt;/strong&gt; keyword and they can be nested with the &lt;strong&gt;else if&lt;/strong&gt; keyword to check for multiple conditions. Its also possible to set a default outcome if none of the conditions are met using the &lt;strong&gt;else&lt;/strong&gt; keyword.&lt;/p&gt;

&lt;p&gt;In pseudo code code, this would be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (water degree &amp;lt; 100 degrees) {
  //continue boiling 
} else if (water degree == 100 degrees || water degree &amp;gt; 100 degrees) {
 //stop boiling 
 //water is ready
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that I used symbols such as &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;==&lt;/code&gt;. These are called operators. &lt;/p&gt;

&lt;h2&gt;
  
  
  Loops
&lt;/h2&gt;

&lt;p&gt;A loop is a cycle that repeats something again and again. There are 3 basic types of loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  While Loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {
// Execute this code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The while loop is a loop that repeats a cycle until a certain condition is met. At every iteration the loop checks whether the condition is true or false. If the condition evaluates to true the loop runs again. Else if the condition evaluates to false the loop stops iterating.&lt;/p&gt;

&lt;p&gt;In our tea making algorithm we could use a while loop to implement  step 5 to fill the kettle to capacity. Note that this is a repetitive activity because we are continuously filling the kettle with water. But that only stops when the kettle is a at it's maximum water holding capacity. &lt;br&gt;
Using a while loop the pseudo code for that step could be written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (water level &amp;lt;= maximum kettle capacity) {
    // Continue filling kettle with water
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Do.....While Loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {
 //Carry out once
} while (condition)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The do...while loop is quite similar to the while loop. The only difference is that it must run at least once. Unlike the while loop which checks the condition before running, the do...while loop runs then checks the condition. Like the while loop, it stops running once the condition evaluates to false.&lt;/p&gt;

&lt;p&gt;We can also use the do...while loop to implement step 5 of our tea  making algorithm. This is because we by all means need some water in order to carry out step 6 which is boiling the water.&lt;br&gt;
Using a do...while loop the pseudo code would be written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {
  // add some water
} while (water level &amp;lt;= maximum kettle capacity)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (variable i; i &amp;lt; numberOfTimes; i++) {
//Code for each iteration
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A for loop is another type of loop. A for loop works best when we want to repeat an action a certain number of times. Its body has three parts each separated by a semicolon.&lt;/p&gt;

&lt;p&gt;In the first part a counter variable is initialized. This variable keeps track of   the loop.&lt;br&gt;
The condition goes in the second part of the loop. This part of the loop tells the loop when to stop. The loop checks this condition before     iterating again. &lt;br&gt;
The third part of the loop updates the counter variable.&lt;/p&gt;

&lt;p&gt;In our tea making algorithm, we can use the for loop to implement step 9. This is because in this step we are adding sugar to the tea a total of 3 times&lt;br&gt;
Using a for loop the pseudo code would be such as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (variable i = 0; i &amp;lt; 3; i++) {
   // Add sugar  to the tea
}; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Boolean
&lt;/h2&gt;

&lt;p&gt;Boolean are like questions that we ask a computer and we get a yes/no answer or more accurately true/false. We use boolean to check for certain things. &lt;br&gt;
In our tea making algorithm we could use boolean to check whether we added enough sugar to the tea. &lt;br&gt;
Using boolean this would be implemented In pseudo code such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (tea has enough sugar) {
return true;
}
return false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The goal of this article was to give a gentle introduction to algorithms and provide a sort of mental model for how to solve algorithms and how to use the building blocks. As you might have noted the code in the examples is not language specific. I would advise you to do some research on how each of these building block is implemented in your programming language. The syntax changes but the general idea remains. Feel free to reach out to me or connect on Twitter &lt;a href="https://twitter.com/codingknite"&gt;@codingknite&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>JavaScript Functions Broken Down</title>
      <dc:creator>Joel P. Mugalu</dc:creator>
      <pubDate>Mon, 18 May 2020 16:27:03 +0000</pubDate>
      <link>https://forem.com/codingknite/javascript-functions-broken-down-4fgh</link>
      <guid>https://forem.com/codingknite/javascript-functions-broken-down-4fgh</guid>
      <description>&lt;h4&gt;
  
  
  A comprehensive introduction to JavaScript functions
&lt;/h4&gt;

&lt;p&gt;Functions are a very important concept in JavaScript. Functions can be compared to building blocks. So Understanding them is one step toward true JavaScript mastery. In this article i am going to go over the basics of functions.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a Function?
&lt;/h1&gt;

&lt;p&gt;Think of functions as vocabulary in human language. Different vocabularies help us to avoid repeating the same words. For example, Instead of saying &lt;em&gt;“human being between the age of 13 and 19”&lt;/em&gt;. You can use one vocabulary, &lt;em&gt;teenager&lt;/em&gt;. That gives you the freedom to use the word teenager to form different sentences without having to confuse yourself.&lt;/p&gt;

&lt;p&gt;Functions follow a similar pattern, they allow us to wrap a whole program into one single expression. We can then call this expression our new vocabulary. We can then use it anywhere in our program to do different things.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Use Functions?
&lt;/h1&gt;

&lt;p&gt;The ability to wrap a whole program into one single expression is very powerful.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can make our code readable and maintainable.&lt;/li&gt;
&lt;li&gt;In case we have to make changes we can do that in only one place. The place where we defined what the function should do and not where we used it.&lt;/li&gt;
&lt;li&gt;Functions help us to avoid repetition. We define once and use in different places. This can save us from lots of bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Function Declarations
&lt;/h1&gt;

&lt;p&gt;JavaScript allows us to declare functions using the &lt;strong&gt;function&lt;/strong&gt; keyword. This is then followed by the name of the function.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function functionName(parameter) {
    // Your Code Here
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Functions accept &lt;strong&gt;parameters&lt;/strong&gt; and &lt;strong&gt;arguments&lt;/strong&gt;. Think of parameters as the ingredients of the function. These ingredients are what we tell the function to receive. Then inside the curly braces (&lt;code&gt;{}&lt;/code&gt;) we define what the function does with these ingredients. Parameters are only assigned a value during the function call. The values that a function receives when being called are then the arguments.&lt;/p&gt;

&lt;p&gt;When the &lt;strong&gt;return&lt;/strong&gt; keyword is used inside a function, the function stops execution at that point. The result of the function execution is then assigned to the function caller. Functions without the return keyword are assigned the value undefined. The function is then called or invoked by typing the function name with parentheses.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function testFunction() {
    return "Hello World";
};
testFunction(); // returns hello world

function addTen(number) {
   return number + 10;
};
addTen(20) // returns 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above examples the &lt;code&gt;testFunction&lt;/code&gt; does not accept any arguments. It simply returns the string Hello World. It is called by typing the function name and using parenthesis after that.&lt;/p&gt;

&lt;p&gt;The second function &lt;code&gt;addTen&lt;/code&gt; accepts one argument and adds 10 to it. Functions can accept an unlimited number of parameters.&lt;/p&gt;

&lt;p&gt;When a function receives more arguments than preset parameters, it uses the received arguments and ignores the rest. When it receives less, it assigns undefined to the parameters that did not receive arguments.&lt;/p&gt;

&lt;p&gt;We can do different things with functions. For example we can assign them to variables and we can also use variables as parameters.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isLegal (name, age) {
    if (age &amp;gt;= 18) {
        return `Hey ${name}, You're Legal`
    } 
  return `Hey ${name}, You're still a kid`;
};

let johnLegal, janeLegal;
johnLegal = isLegal("John", 25);
janeLegal = isLegal("Jane", 14);

johnLegal; // returns "Hey John, You're Legal"
janeLegal; // returns "Hey Jane, You're still a kid"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The example demonstrates a function &lt;code&gt;isLegal&lt;/code&gt; which accepts two arguments. Pay particular attention to how the functions were assigned to the variables. Also look out for ow the variables were passed as function parameters. I suggest you try this out on your own.&lt;/p&gt;

&lt;h1&gt;
  
  
  Function Expressions
&lt;/h1&gt;

&lt;p&gt;Function expressions is another way of creating functions in JavaScript.&lt;br&gt;
Consider the following example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = function (name) {
return `Howdy ${name}`;
};
let greetJohn = greeting("John");
greetJohn; // returns Howdy John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The example above demonstrates a function expression.The variable &lt;code&gt;greeting&lt;/code&gt; is assigned the value of a function. This time we did not use the function keyword. Rather we declared a variable and assigned it the value of a function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrow Functions
&lt;/h2&gt;

&lt;p&gt;ES6 or ES2015+ introduced a new way of creating functions. This form is function expression is quite different. Instead of using the function keyword. We use an equal sign (&lt;code&gt;=&lt;/code&gt;) after the function name then declare the function parameters. We then use a equal sign (&lt;code&gt;=&lt;/code&gt;) and a greater than sign (&lt;code&gt;&amp;gt;&lt;/code&gt;) together such as (&lt;code&gt;=&amp;gt;&lt;/code&gt;). The following block is where we define what the function will do.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const functionName = parameters =&amp;gt; {
    // Execute this code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Its can be thought of as &lt;strong&gt;“This function takes these parameters and executes this code”&lt;/strong&gt;&lt;br&gt;
Consider the following example&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const isLegal = (name, age) =&amp;gt; {
    if (age &amp;gt;= 18) {
        return `Hey ${name}. You're Legal`
    } 
return `Hey ${name}. You're not Legal`
};

let denisLegal = isLegal("Denis", 21);
denisLegal; // returns Hey Denis. You're Legal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;One plus with arrow functions is that they provide a shorter way of writing functions. They can allow us to omit the parentheses after the equal sign if the function takes only one argument. The return keyword can also be omitted if the function returns something immediately.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const weatherCondition = weather =&amp;gt; `It is currently ${weather}`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There is one main difference between function declarations and function expressions. Function declarations begin with the function keyword. But, function expressions are functions assigned to a variable.&lt;/p&gt;

&lt;h1&gt;
  
  
  Hoisting
&lt;/h1&gt;

&lt;p&gt;Hoisting means that variable and function declarations are taken on top of their scope before execution. This makes them available to be used before the execution phase.&lt;/p&gt;

&lt;p&gt;In JavaScript, all function declarations and arguments are stored in one object. The Variable object. This object is created before code execution, during the creation phase. During the creation phase all function declarations and arguments are stored into memory.&lt;/p&gt;

&lt;p&gt;The creation phase happens in three steps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code is ran line by line for function declarations and function arguments.&lt;/li&gt;
&lt;li&gt;The variable object is then created. All the function declarations and arguments in the program are stored inside this object.&lt;/li&gt;
&lt;li&gt;The function declarations then stored in the variable object point to the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hoisting is step 2 and 3. Hoisting makes it possible for us to use function declarations and define the function later. Once the function is defined anywhere in the program it is stored in memory. So it’s available even before the program starts executing. It’s important to remember that hoisting only works for function declarations. With function expressions, we must define the function first then use it.&lt;/p&gt;

&lt;p&gt;The following example demonstrates hoisting of functions.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fullName = "Thanos";
let age = 33;
introduction(fullName, age); // returns Hey everyone. I'm Thanos and I'm 33
function introduction(name, age) {
    return `Hey everyone. I'm ${name} and I'm ${age}`
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Notice how we were able to use the &lt;code&gt;introduction&lt;/code&gt; function before declaration. That is because the function was hoisted.&lt;/p&gt;

&lt;h1&gt;
  
  
  Good Practices
&lt;/h1&gt;

&lt;p&gt;By now you must be very excited to start using functions right away. But there are some safe practices when using functions.&lt;/p&gt;

&lt;p&gt;A good rule of thumbs is to try and keep your functions as short as 10–15 lines. Try to write functions that complete only one task.&lt;/p&gt;

&lt;p&gt;Remember functions are like vocabulary, their to avoid repetition. So if you find yourself repeating one thing twice then consider writing a function for it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Functions are a very powerful programming paradigm in JavaScript. Practice is key in understanding them and how they work. Try solving algorithmic challenges with functions. That’ll help for sure. If you’d like to connect with me i am very active on &lt;strong&gt;&lt;a href="https://www.instagram.com/codingknite/"&gt;Instagram&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://twitter.com/codingknite"&gt;Twitter&lt;/a&gt;&lt;/strong&gt;. Do reach out.&lt;/p&gt;

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