<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Halil Can Ozcelik</title>
    <description>The latest articles on DEV Community by Halil Can Ozcelik (@halilcanozcelik).</description>
    <link>https://dev.to/halilcanozcelik</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%2F262321%2F97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg</url>
      <title>DEV Community: Halil Can Ozcelik</title>
      <link>https://dev.to/halilcanozcelik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/halilcanozcelik"/>
    <language>en</language>
    <item>
      <title>Effective Object Usage Examples in JavaScript</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Wed, 15 Jul 2020 10:18:00 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-objects-in-use-1e12</link>
      <guid>https://dev.to/halilcanozcelik/javascript-objects-in-use-1e12</guid>
      <description>&lt;p&gt;In this article, I try to suggest effective solutions with objects in JavaScript for common use cases in the real world.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objects instead of array search
&lt;/h3&gt;

&lt;p&gt;Using objects in an array search decreases the time complexity of your solution in quite a lot of cases. Let’s continue explaining with examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;findMaxOccured&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;list&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maxOcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;times&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="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;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// this filter is a nested loop actually!&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;occ&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;i&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;occ&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;maxOcc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;times&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;maxOcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;times&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;occ&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;maxOcc&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;In the example above, we find the max occurred element in the list. There is a nested loop in here (filter method) because we are searching the whole list to find the occurrence times for each element of the list. So, the time complexity is O(n²) for this solution which is not good enough!&lt;br&gt;
The possible object-related approach can be below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;findMaxOccured&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;list&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;occMap&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;maxOcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;times&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="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;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;occMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;occMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&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="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="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;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;occMap&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;occMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;maxOcc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;times&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;maxOcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;times&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;occMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;maxOcc&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;First, we generate an occurrence map for the list. Then find the max occurred element in the map by iterating through it. Here there is no nested loop so time complexity is O(n) which is better!&lt;/p&gt;

&lt;h3&gt;
  
  
  Objects instead of conditions
&lt;/h3&gt;

&lt;p&gt;In some cases, we need to call different functions or assign different values according to the value of a variable. For these cases, using a matching object instead of several condition blocks can be more effective solutions.&lt;/p&gt;

&lt;p&gt;Let’s give an example:&lt;br&gt;
The following code block is the first thing that comes to mind mostly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;conditional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="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="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="k"&gt;else&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;param&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be refactored like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;objectMatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&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;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;c&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This alternative also is conceivable for switch cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;conditional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&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;param&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;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;break&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;b&lt;/span&gt;&lt;span class="dl"&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;c&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;break&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="nx"&gt;func3&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;break&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;In addition to the first one, we need to call the function &lt;code&gt;()&lt;/code&gt; after getting from the mapping object. Again my suggestion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;objectMatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param&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;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;c&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;func3&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;correspondingFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;correspondingFunc&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;Additionally, this mapping objects can be moved to a higher scope if it doesn’t need to change in function just like our examples. Of course, for more complex conditions this approach couldn’t be the best fit but for simple cases like my examples, you can consider using objects.&lt;/p&gt;

&lt;p&gt;The examples can be increased but I hope these explain the main idea.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>computerscience</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Interview Coding Questions - 5</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Wed, 22 Jan 2020 20:24:17 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-5-djj</link>
      <guid>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-5-djj</guid>
      <description>&lt;p&gt;In this article, I will add questions about JavaScript Classes. Let's begin:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;This one is about converting constructor function to class. It is a beneficial coding exercise to understand JavaScript class knowledge.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rewrite the following consturctor function as a Class
function Animal(name) {
  this.name = name;
}
Animal.prototype.duck = function () {
  console.log(this.name, 'duck');
};

const animal = new Animal('daffy');
animal.duck();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The answer will be below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// The answer is below
class Animal {
  constructor(name) {
    this.name = name;
  }

  duck() {
    console.log(this.name, 'duck');
  }
}
const animal = new Animal('daffy'); // new keyword is mandatory
animal.duck();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And one more related question after converting to class.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 3. What will be the following console output?
console.log(typeof Animal);
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The answer is:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Classes?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This one is about differences in declaration of class and functions.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. What will be the output?
const car = new Car('Clio');

function Car(model) {
  this.model = model;
}
Car.prototype.getModel = function () {
  return this.model;
};

console.log('car model:', car.getModel());

// 2. What will be the output?
const bike = new Bike('Bianchi');

class Bike {
  constructor(model) {
    this.model = model;
  }

  getModel() {
    return this.model;
  }
}

console.log('bike model:', bike.getModel());
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The console output will be below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;car model: Clio
ReferenceError: Bike is not defined
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;function definitions are hoisted so we can create an instance before declaration. However, &lt;strong&gt;class definitions are not initialized until their definition is evaluated&lt;/strong&gt; so it gives &lt;code&gt;Bike is not defined&lt;/code&gt; error. You can read &lt;a href="https://stackoverflow.com/questions/31219420/are-variables-declared-with-let-or-const-not-hoisted-in-es6/31222689#31222689"&gt;This stackoverflow answer&lt;/a&gt; for more detailed information.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Declaration-Class-vs-Function?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next question is about inheritance in JavaScript classes.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. What will be the console outputs?
class Parent {
  constructor(name) {
    this.name = name;
  }

  getName() {
    return this.name;
  }
}

class Child extends Parent {
  constructor(name) {
    super(name);
  }

  getMessage() {
    return `My name is ${super.getName()}`;
  }
}

const child = new Child('Halil');

console.log(child.getMessage());
console.log(child.getName());
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The outputs will be as below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My name is Halil
Halil
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;So, although there is no &lt;code&gt;getName()&lt;/code&gt; method in &lt;code&gt;Child&lt;/code&gt; class it is inherited from &lt;code&gt;Parent&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;You can test it below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Class-Inheritance?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write a generator function which takes an array and returns its every member in each call.&lt;br&gt;
The answer can be as below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function* sendNumber(list) {
  for (let item of list) {
    yield item;
  }
}

const iterator = sendNumber([1, 2, 3]);

// What will be written?
console.log(iterator.next());
// What will be written?
console.log(iterator.next());
// What will be written?
console.log(iterator.next());
// What will be written?
console.log(iterator.next());
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And the console outputs will be:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ value: 1, done: false }
{ value: 2, done: false }
{ value: 3, done: false }
{ value: undefined, done: true }
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Generator-Functions?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;You can read the previous articles of this series from the links below:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-1-4alk" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 1&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 4 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-2-3o0i" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 2&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 6 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-3-13gn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions - 3&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 7 '20 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-4-1fo7" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions - 4&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 14 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>career</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Interview Coding Questions - 4</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Tue, 14 Jan 2020 05:51:43 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-4-1fo7</link>
      <guid>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-4-1fo7</guid>
      <description>&lt;p&gt;Continuing to questions… As I said in first blog, these are generally evaluation based code snippets.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;This one is about scope differences of Arrow &amp;amp; Regular function definitions.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. What will be logged? Why?
const module1 = {
  x: 55,
  getX: function () {
    console.log('x:', this.x);
  }
};

const module2 = {
  x: 55,
  getX: () =&amp;gt; {
    console.log('x:', this.x);
  }
};

(function() {
  this.x = 66;
  module1.getX();
  module2.getX();
})();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The console output will be following:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x: 55
x: 66
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Because &lt;code&gt;this&lt;/code&gt; refers to wrapper object in regular function so &lt;code&gt;this.x&lt;/code&gt; logs &lt;code&gt;x&lt;/code&gt; property of wrapper &lt;code&gt;module1&lt;/code&gt; object in first example. On the other side, arrow functions don't bind their own scope, but inherit it from the parent one, which is &lt;code&gt;Window&lt;/code&gt; or the &lt;code&gt;global&lt;/code&gt; object in this case.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Arrow-vs-Regular-Functions?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Let's examine same issue in a different example.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 2. What will be logged? Why?
const message1 = {
  hello : 'Hello',
  names : ['Sue', 'Joe'],
  showMessage: function () {
    this.names.forEach(function(name) {
      console.log(`${this.hello} ${name}`);
    });
  }
}
message1.showMessage();

const message2 = {
  hello : 'Hello',
  names : ['Sue', 'Joe'],
  showMessage: function () {
    this.names.forEach(name =&amp;gt; {
      console.log(`${this.hello} ${name}`);
    });
  }
}
message2.showMessage();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The console output will be following:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;undefined Sue
undefined Joe
Hello Sue
Hello Joe
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;In &lt;code&gt;message1&lt;/code&gt;, the function inside &lt;code&gt;this.names.forEach&lt;/code&gt; is defined as regular function, so &lt;code&gt;this&lt;/code&gt; equals to the global object by default (&lt;code&gt;Window&lt;/code&gt; in browsers, &lt;code&gt;global&lt;/code&gt; in Node.js) and it has no &lt;code&gt;hello&lt;/code&gt; property. &lt;strong&gt;&lt;code&gt;this&lt;/code&gt; equals to &lt;code&gt;undefined&lt;/code&gt; by default in strict mode!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, in &lt;code&gt;message2&lt;/code&gt;, the function inside &lt;code&gt;this.names.forEach&lt;/code&gt; is defined as arrow function. Arrow functions don't have own scope, so it equals to owner's (which is &lt;code&gt;showMessage&lt;/code&gt; in this case) scope. The scope of &lt;code&gt;showMessage&lt;/code&gt; is the wrapper object &lt;code&gt;message2&lt;/code&gt;. For this reason, we can reach &lt;code&gt;hello&lt;/code&gt; property of &lt;code&gt;message2&lt;/code&gt; by using &lt;code&gt;this.hello&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Arrow-vs-Regular-Functions?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This question is to evaluate knowledge about promises in JavaScript.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promiser = ms =&amp;gt; new Promise((resolve, reject) =&amp;gt; {
  setTimeout(() =&amp;gt; { resolve('wait wait..') }, ms)
});

const timeout = new Promise((resolve, reject) =&amp;gt; {
  setTimeout(() =&amp;gt; { resolve('timeout!') }, 2000)
});

const race1 = Promise.race([promiser(1000), timeout]);
const race2 = Promise.race([promiser(3000), timeout]);

// What will be the output?
race1.then(res =&amp;gt; console.log('race1:', res))
  .catch(err =&amp;gt; console.log('race1:',  err));

// What will be the output?
race2.then(res =&amp;gt; console.log('race2:', res))
  .catch(err =&amp;gt; console.log('race2:', err));
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The result will be below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;race1: wait wait..
race2: timeout!
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;Promise.race()&lt;/code&gt; returns a winner promise which fulfills or rejects sooner. Our &lt;code&gt;timeout&lt;/code&gt; promise is resolved in 2 seconds. The &lt;code&gt;promiser&lt;/code&gt; is taking resolving time as parameter. In first race, it resolved in 1 second so wins the race, but in the second race it takes 3 seconds as parameter so &lt;code&gt;timeout&lt;/code&gt; is resolved earlier.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Promise-Race?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;You can read the previous articles of this series from the links below:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-1-4alk" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 1&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 4 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-2-3o0i" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 2&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 6 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-3-13gn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions - 3&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 7 '20 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>career</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript Interview Coding Questions - 3</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Tue, 07 Jan 2020 10:01:14 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-3-13gn</link>
      <guid>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-3-13gn</guid>
      <description>&lt;p&gt;I am trying to explain some possible coding questions in software developer interviews. I will mention recursion and array mutation in this third article. These two topics are important in functional programming paradigm. Also, the last example is about prototypal inheritance which is crucial to understand inheritance in JavaScript.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write a recursive function to calculate the total of numbers between 1 to n?&lt;br&gt;
&lt;code&gt;n&lt;/code&gt; will be the parameter of our function. So we should call this calculator function until reaching to &lt;code&gt;1&lt;/code&gt; which is our end point. So, one of the possible effective solutions will be below code:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function calculateTotal(number, total = 1) {
  return number &amp;gt; 1 ?
    calculateTotal(number - 1, total + number) :
    total;
}

console.log(calculateTotal(10));
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can examine the code in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Recursion?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write a recursive factorial calculator function.&lt;br&gt;
We can easily adapt same logic to factorial calculation as below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function factorial(number, product = 1) {
  return number &amp;gt; 0 ?
    factorial(number - 1, product * number) :
    product;
}

console.log(factorial(5));
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;!! The recursive functions above will cause stack overflow error for large inputs. In order to prevent it, Trampoline Pattern can be used as below:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// recursive optimization to prevent stack overflow error
function trampoline(fn) {
  return (...args) =&amp;gt; {
    let result = fn(...args);
    while (typeof result === 'function') {
      result = result();
    }
    return result;
  };
}

// Write a recursive function to calculate the total of numbers between 1 to n?
function calculateTotal(number, total = 1) {
  return number &amp;gt; 1 ?
    () =&amp;gt; calculateTotal(number - 1, total + number) :
    total;
}

const totalCalculator = trampoline(calculateTotal);
console.log(totalCalculator(100000));

// Write a recursive factorial calculator function
function factorial(number, product = 1) {
  return number &amp;gt; 0 ?
    () =&amp;gt; factorial(number - 1, product * number) :
    product;
}

const factorialCalculator = trampoline(factorial);
console.log(factorialCalculator(100));
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can examine the code in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Recursion?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This one is about mutator methods in JavaScript arrays. Immutability of variables is an important topic in functional programming.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr = [1, 2, 3, 7, 4];
// Which of the followings will mutate variables?
// Find a functional alternative for mutator ones.
arr.push(5);          =&amp;gt; mutator
arr.shift();          =&amp;gt; mutator
arr.concat(6, 7);     =&amp;gt; non-mutator
arr.map(a =&amp;gt; a * a);  =&amp;gt; non-mutator
arr.sort();           =&amp;gt; mutator
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And these can be alternative solutions for mutator ones.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr = [1, 2, 3, 7, 4];
// Which of the followings will mutate variables?
// Find a functional alternative for mutator ones.
arr.push(5);          =&amp;gt; arr.concat(5);
arr.shift();          =&amp;gt; arr.slice(1);
arr.concat(6, 7);     =&amp;gt; non-mutator
arr.map(a =&amp;gt; a * a);  =&amp;gt; non-mutator
arr.sort();           =&amp;gt; arr.concat().sort()
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can examine the code in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Functional-Programming?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This one is to examine your understanding about Prototypal Inheritance.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person() {}

// 1st definition for 'sayHi' method
Person.prototype.sayHi = function () {
  console.log('Hi!');
};

var person = new Person();

// What will be the printed message?
person.sayHi();

// 2nd definition for 'sayHi' method
Person.prototype.sayHi = function () {
  console.log('Hello!');
};

// What will be the printed message?
person.sayHi();

// What will be returned?
person.hasOwnProperty('sayHi');
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The output will be below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hi!
Hello!
false
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;person&lt;/code&gt; object doesn't have own &lt;code&gt;sayHi()&lt;/code&gt; method because &lt;code&gt;Person&lt;/code&gt; function doesn't have any method. When we instantiate an object with &lt;code&gt;new&lt;/code&gt; keyword, it inherits all &lt;code&gt;prototype&lt;/code&gt; methods of the function as its &lt;code&gt;__proto__&lt;/code&gt; property. So, in first execution of &lt;code&gt;sayHi()&lt;/code&gt; the defined one is logging &lt;code&gt;Hi!&lt;/code&gt; so it is executed. But after second definition of &lt;code&gt;sayHi()&lt;/code&gt; the newer one will be called. Because, &lt;code&gt;person.sayHi()&lt;/code&gt; points to the same function due to prototypal inheritance. Finally, &lt;code&gt;person.hasOwnProperty('sayHi')&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt; because this is not a property of &lt;code&gt;person&lt;/code&gt; object, it is inherited by prototype chain.&lt;/p&gt;

&lt;p&gt;You can examine the code in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Prototypal-Inheritance?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;My some other articles:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-1-4alk" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 1&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 4 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-2-3o0i" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 2&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 6 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Create a Multi-Language Website with React Context API&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Nov 7 '19 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>career</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Interview Coding Questions — 2</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Mon, 06 Jan 2020 18:10:09 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-2-3o0i</link>
      <guid>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-2-3o0i</guid>
      <description>&lt;p&gt;Let’s continue to coding assessment questions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;This one is about testing hoisting knowledge in JavaScript.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// What will be the console outputs? Why?
callMe1();
callMe2();

function callMe1() {
  console.log('I am here');
}

var callMe2 = function () {
  console.log('I am here too');
};
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You will get an error for &lt;code&gt;callMe2()&lt;/code&gt;. Console log will be below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I am here
TypeError: callMe2 is not a function
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;In JavaScript, basically function and variable definitions are moved to top (&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting"&gt;which is named as hoisting&lt;/a&gt;). The &lt;code&gt;callMe2&lt;/code&gt; variable is defined but it is not a function! &lt;strong&gt;This is because, hoisting only moves up to declarations not initializations.&lt;/strong&gt; So, our &lt;code&gt;callMe2&lt;/code&gt; variable is declared but the function is not assigned to it.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Hoisting?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This one is for testing the knowledge about &lt;code&gt;const&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;var&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. What will be output?
var v;
let l;
const c;
console.log({ v, l, c });
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Again you will get an error.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const c;
      ^
SyntaxError: Missing initializer in const declaration
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;You must assign a value while declaring a &lt;code&gt;const&lt;/code&gt; variable!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Variable-Declarations?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Another question about variable declarations.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 2. What will be outputs? Try one by one!
console.log('a:', a);
var a = 1;

console.log('b:', b);
let b = 2;

console.log('c:', c);
const c = 3;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If you try them one by one you will see the following console logs:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: undefined
ReferenceError: b is not defined
ReferenceError: c is not defined
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;This is because variables which are declared with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;  are not initialized until their definition is evaluated!&lt;/strong&gt; So it will throw &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError"&gt;ReferenceError&lt;/a&gt;. You can read &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone"&gt;Temporal Dead Zone&lt;/a&gt; part for more detailed information. &lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Variable-Declarations?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;My some other articles:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-1-4alk" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 1&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 4 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-3-13gn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions - 3&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 7 '20 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/chrome-devtool-tips-2eb" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Chrome DevTool Tips&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Dec 20 '19 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#todayilearned&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Create a Multi-Language Website with React Context API&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Nov 7 '19 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>career</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Interview Coding Questions — 1</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Sat, 04 Jan 2020 20:48:27 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-1-4alk</link>
      <guid>https://dev.to/halilcanozcelik/javascript-interview-coding-questions-1-4alk</guid>
      <description>&lt;p&gt;Online coding is a crucial part of software developer job interviews. In this article, I will try to add several coding questions. These will be evaluation focused code snippets instead of task based coding questions. Additionally, I will share online code links at the end of every question.&lt;/p&gt;

&lt;p&gt;Let’s start with one of the most well-known one:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In this question, closure and asynchronous code handling knowledge is assessed.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// What will be the console log of the code below?
for (var i = 0; i &amp;lt; 4; i++) {
  setTimeout(() =&amp;gt; console.log(i), 0);
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;It will write 4, 4, 4, 4 in console because &lt;code&gt;setTimeout()&lt;/code&gt; is a &lt;br&gt;
asynchronous function and it will be executed after &lt;code&gt;for&lt;/code&gt; cycle is completed. &lt;code&gt;i&lt;/code&gt; is defined outside scope of &lt;code&gt;for&lt;/code&gt; loop and it will be equal to 4 when &lt;code&gt;console.log()&lt;/code&gt; starts to write.&lt;br&gt;
How can you fix it to write 0, 1, 2, 3? Here is the possible solutions:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Solution 1:
for (let i = 0; i &amp;lt; 4; i++) {
  setTimeout(() =&amp;gt; console.log(i), 0);
}

// Solution 2:
for (var i = 0; i &amp;lt; 4; i++) {
  (function (i) {
    setTimeout(() =&amp;gt; console.log(i), 0);
  })(i);
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Solution 1:&lt;/strong&gt; You can change declaration of &lt;code&gt;i&lt;/code&gt; from &lt;code&gt;var&lt;/code&gt; to &lt;code&gt;let&lt;/code&gt; &lt;br&gt;
because &lt;code&gt;let&lt;/code&gt; is block scoped variable but &lt;code&gt;var&lt;/code&gt; is function scoped variable.&lt;br&gt;
&lt;strong&gt;Solution 2:&lt;/strong&gt; You can wrap &lt;code&gt;setTimeout()&lt;/code&gt; with a function to limit &lt;br&gt;
the scope of &lt;code&gt;i&lt;/code&gt; variable. But you should pass &lt;code&gt;i&lt;/code&gt; as parameter to your IIFE (Immediately-invoked Function Expression).&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Scope?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This one is about scope of this.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// What will be the logs in console?
function nameLogger() {
  this.name = 'halil';
  console.log('first:', this.name);
}

console.log('second:', this.name);
nameLogger();
console.log('third:', this.name);
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Console output will be following:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;second: undefined
first: halil
third: halil
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;While “second” is executed &lt;code&gt;this.name&lt;/code&gt; is undefined but after &lt;code&gt;nameLogger()&lt;/code&gt; function is executed it will be defined. &lt;strong&gt;Because, &lt;code&gt;this&lt;/code&gt; refers to the global object in a function.&lt;/strong&gt; So the others log "halil" as expected.&lt;br&gt;
&lt;strong&gt;!! It will not work with &lt;code&gt;'use strict'&lt;/code&gt; because in a function, in strict mode, &lt;code&gt;this&lt;/code&gt; equals &lt;code&gt;undefined&lt;/code&gt; instead of global object.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Scope-this?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The last one is about &lt;code&gt;this&lt;/code&gt; and &lt;code&gt;bind&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// What will be written?
const module = {
  x: 55,
  getX: function () {
    console.log('x:', this.x);
  }
};
const unboundX = module.getX;
unboundX();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Console output will be &lt;code&gt;x: undefined&lt;/code&gt; because &lt;code&gt;this&lt;/code&gt; refers to current owner object. So when you assign only &lt;code&gt;getX&lt;/code&gt; method to a new object &lt;code&gt;unboundX&lt;/code&gt;, &lt;code&gt;this&lt;/code&gt; will refers to it. And it has no &lt;code&gt;x&lt;/code&gt; property, that’s why &lt;code&gt;this.x&lt;/code&gt; equals to &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
You can fix it by using &lt;code&gt;bind()&lt;/code&gt; as below:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const boundX = unboundX.bind(module);
boundX();
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Now you bind module object to &lt;code&gt;unboundX&lt;/code&gt; function. Then it can reach the &lt;code&gt;x&lt;/code&gt; property of module.&lt;/p&gt;

&lt;p&gt;You can test it in below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@hco/Function-bind?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;You can read some of my other articles from the links below:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-2-3o0i" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions — 2&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 6 '20 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/javascript-interview-coding-questions-3-13gn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;JavaScript Interview Coding Questions - 3&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Jan 7 '20 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#career&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/halilcanozcelik" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tYaHOdZa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--hEyTDDVA--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/262321/97073ce4-c2f9-4ae1-9abe-ac3af4a48dec.jpg" alt="halilcanozcelik"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/halilcanozcelik/chrome-devtool-tips-2eb" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Chrome DevTool Tips&lt;/h2&gt;
      &lt;h3&gt;Halil Can Ozcelik ・ Dec 20 '19 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#productivity&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#todayilearned&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>career</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Chrome DevTool Tips</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Fri, 20 Dec 2019 22:57:49 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/chrome-devtool-tips-2eb</link>
      <guid>https://dev.to/halilcanozcelik/chrome-devtool-tips-2eb</guid>
      <description>&lt;p&gt;In this article, I will write down some tips for more productive Chrome developer tools usage. Tips are grouped according to the tabs of Chrome DevTools.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Elements&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fb62w4lw723hak6p901bv.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fb62w4lw723hak6p901bv.png" alt="DOM debuger"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add a breakpoint to DOM elements by clicking the 3 dots (...) on the left of elements panel lines. If you select the "Break on" option you will see 3 kinds of breakpoints. These are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;subtree modification:&lt;/strong&gt; Stop if any child elements changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;attribute modifications:&lt;/strong&gt; Stop if any attribute of the element is changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;node removal:&lt;/strong&gt; Stop if the element is removed from DOM.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Console&lt;br&gt;
In this part, I will mention some helpful commands you can use in the Console panel of Chrome DevTool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firstly there is an easy way to get selected elements in Console.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;$0&lt;/code&gt;: Returns the element which is currently selected in the Elements tab.&lt;br&gt;
&lt;code&gt;$1&lt;/code&gt;: Returns the element which is previously selected in the Elements tab.&lt;br&gt;
&lt;code&gt;$2&lt;/code&gt;: Returns the element which is twice previously selected in the Elements tab. So on and so forth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondly there is built-in selectors in devtool which quite similar to JQuery.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;$(&amp;lt;css selector&amp;gt;)&lt;/code&gt;: Returns the first matching element. Such as &lt;code&gt;document.querySelector()&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt; &lt;code&gt;$('div.head')&lt;/code&gt;: select the first div element which has 'head' class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$$(&amp;lt;css selector&amp;gt;)&lt;/code&gt;: Returns all matching elements. Such as &lt;code&gt;document.querySelectorAll()&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt; &lt;code&gt;$('div.head')&lt;/code&gt;: select the all div elements which have 'head' class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Also, you can find an element in the Elements tab by using Console.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;inspect(&amp;lt;selector&amp;gt;)&lt;/code&gt;: Select the element in Elements tab.&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt; &lt;code&gt;inspect($('div'))&lt;/code&gt;: Selects the first div element in Elements tab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another helpful command is for monitoring events in Console.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;monitorEvents(selector, event)&lt;/code&gt;: Write event objects to Console when the defined event is triggered for the selected element.&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt; &lt;code&gt;monitorEvents($(‘button’), ‘click’)&lt;/code&gt;: Write event object to console while the selected button is clicked.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;unmonitorEvents(&amp;lt;selector&amp;gt;)&lt;/code&gt;: Remove event monitoring for the selected element.&lt;br&gt;
&lt;strong&gt;Ex:&lt;/strong&gt; &lt;code&gt;unmonitorEvents($(‘button’))&lt;/code&gt;: Remove event logging for the selected button element.&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Source&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frgendqkh0xgcancc06qf.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frgendqkh0xgcancc06qf.png" alt="Source Snippets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add snippets by selecting "Snippets" tab from the left panel in the Source tab. It is a helpful tool for debugging &amp;amp; testing. You can run these snippets by right click &amp;amp; "Run" or "Cmd + Enter" shortcut.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvtof2wp9j9hqzj92uqi2.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvtof2wp9j9hqzj92uqi2.png" alt="XHR breakpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;XHR breakpoints can be added for any requests or URL filtered ones. In the screenshot above XHR breakpoint added for the requests which contain "age" in its URL. So the DevTool stops whenever these type of request is sent.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkquoaft7opkns4brmkcr.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkquoaft7opkns4brmkcr.png" alt="Conditional Breakpoint Menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, you can add conditional breakpoints by right-clicking the breakpoint and selecting "Edit breakpoint" from the menu. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn7pan4i97cvz6my4dsxs.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn7pan4i97cvz6my4dsxs.png" alt="Conditional Breakpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It stops only the entered condition is satisfied. For the screenshot above, it only stops if &lt;code&gt;k&lt;/code&gt; is bigger than 4.&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Network&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8sma55ahprgifd12s35t.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8sma55ahprgifd12s35t.png" alt="Network Speed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can adjust your internet speed by changing "Throttling" setting under the Network tab. So, you can simulate slower connections for testing specific cases. It is very beneficial when you trying to handle loading states etc.&lt;/p&gt;


&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>productivity</category>
      <category>todayilearned</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create a Multi-Language Website with React Context API</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Thu, 07 Nov 2019 21:30:45 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27</link>
      <guid>https://dev.to/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27</guid>
      <description>&lt;p&gt;In this article, I will try to explain my approach to develop a multi-language website with React Context API. If you are used to reading code better than words, you can examine the example project from &lt;a href="https://github.com/hcoz/react-context-multilang" rel="noopener noreferrer"&gt;this Github repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And here is the &lt;a href="https://nice-cliff-047044a03.azurestaticapps.net" rel="noopener noreferrer"&gt;live POC of the project.&lt;/a&gt;&lt;br&gt;
(This link exists on the Github Repo too)&lt;/p&gt;

&lt;p&gt;First, I strongly suggest taking a glance at &lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;the React Context API&lt;/a&gt; and &lt;a href="https://reactjs.org/docs/hooks-reference.html#usecontext" rel="noopener noreferrer"&gt;useContext Hook&lt;/a&gt; documents from the official React website.&lt;/p&gt;

&lt;p&gt;And here we go! This is the folder structure of the project:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnspc3g3al3iwvhyivzlx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnspc3g3al3iwvhyivzlx.png" alt="Folder Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Texts are stored as JSON for each language. You can see the example for English below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "exploreHeader": "Explore",
  "welcomeDescription": "This is a demo app for multi-language website with React Context API",
  "clickMe": "Click Me",
  "aboutMe": "For more info about the author",
  "buttonClicked": "You clicked to button!"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of them are stored in a dictionary object and it will be shown according to the selected language which I will explain later in this article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import tr from './tr.json';
import en from './en.json';
import de from './de.json';

export const dictionaryList = { en, tr, de };

export const languageOptions = {
  en: 'English',
  tr: 'Türkçe',
  de: 'Deutsch'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The language selector is filled by &lt;code&gt;languageOptions&lt;/code&gt;. User can change the language of the website from there.&lt;/p&gt;

&lt;p&gt;I will create a context that contains the selected language and dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { languageOptions, dictionaryList } from '../languages';

// create the language context with default selected language
export const LanguageContext = createContext({
  userLanguage: 'en',
  dictionary: dictionaryList.en
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then define the Context Provider. We can set the selected language and get related texts from the dictionary by this context provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// it provides the language context to app
export function LanguageProvider({ children }) {
  const defaultLanguage = window.localStorage.getItem('rcml-lang');
  const [userLanguage, setUserLanguage] = useState(defaultLanguage || 'en');

  const provider = {
    userLanguage,
    dictionary: dictionaryList[userLanguage],
    userLanguageChange: selected =&amp;gt; {
      const newLanguage = languageOptions[selected] ? selected : 'en'
      setUserLanguage(newLanguage);
      window.localStorage.setItem('rcml-lang', newLanguage);
    }
  };

  return (
    &amp;lt;LanguageContext.Provider value={provider}&amp;gt;
      {children}
    &amp;lt;/LanguageContext.Provider&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the language selector is changed, it will call the &lt;code&gt;userLanguageChange()&lt;/code&gt; method of the provider.&lt;/p&gt;

&lt;p&gt;You can examine the &lt;strong&gt;LanguageSelector.js&lt;/strong&gt; below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useContext } from 'react';

import { languageOptions } from '../languages';
import { LanguageContext } from '../containers/Language';

export default function LanguageSelector() {
  const { userLanguage, userLanguageChange } = useContext(LanguageContext);

  // set selected language by calling context method
  const handleLanguageChange = e =&amp;gt; userLanguageChange(e.target.value);

  return (
    &amp;lt;select
      onChange={handleLanguageChange}
      value={userLanguage}
    &amp;gt;
      {Object.entries(languageOptions).map(([id, name]) =&amp;gt; (
        &amp;lt;option key={id} value={id}&amp;gt;{name}&amp;lt;/option&amp;gt;
      ))}
    &amp;lt;/select&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we need to wrap the main component which is &lt;strong&gt;App.js&lt;/strong&gt; with  &lt;code&gt;LanguageProvider&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  return (
    &amp;lt;LanguageProvider&amp;gt;
      &amp;lt;div className="App"&amp;gt;
        &amp;lt;header className="App-header"&amp;gt;
          &amp;lt;LanguageSelector /&amp;gt;
        &amp;lt;/header&amp;gt;

        &amp;lt;Explore /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/LanguageProvider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we define &lt;code&gt;Text&lt;/code&gt; component to translate our texts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// get text according to id &amp;amp; current language
export function Text({ tid }) {
  const languageContext = useContext(LanguageContext);

  return languageContext.dictionary[tid] || tid;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can use this component to gather related text according to the selected language from predefined language objects (which I mentioned at the beginning of the article).&lt;br&gt;
Also, we can call the language context directly to use such as the input placeholder example below.&lt;br&gt;
Here are several usage examples in a component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Explore() {
  const [clickText, setClickText] = useState();
  const { dictionary } = useContext(LanguageContext);

  const handleClick = () =&amp;gt; {
    setClickText(&amp;lt;Text tid="buttonClicked" /&amp;gt;);
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;&amp;lt;Text tid="exploreHeader" /&amp;gt;&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;&amp;lt;Text tid="welcomeDescription" /&amp;gt;&amp;lt;/p&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;input type="text" placeholder={dictionary.enterText} /&amp;gt;
        &amp;lt;button onClick={handleClick}&amp;gt;
          &amp;lt;Text tid="clickMe" /&amp;gt;
        &amp;lt;/button&amp;gt;
        &amp;lt;p&amp;gt;{clickText}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;a href="https://halilcanozcelik.com" target="_blank" rel="noopener noreferrer"&amp;gt;
        &amp;lt;Text tid="aboutMe" /&amp;gt;
      &amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, the selected language should be stored in the database or local storage of the browsers and context states filled by this option at the beginning. An option of languageOptions can be used for a fallback scenario, I used English (“en”) in this project. Also, I have stored the selected language in local storage and reading from there at the beginning. If there is no info, then using browser language as the default language.&lt;br&gt;
I hope it will be helpful.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Very Basics of Cloud Services and AWS</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Sun, 03 Nov 2019 08:48:19 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/very-basics-of-cloud-services-and-aws-30g7</link>
      <guid>https://dev.to/halilcanozcelik/very-basics-of-cloud-services-and-aws-30g7</guid>
      <description>&lt;p&gt;Cloud services, especially AWS, become more popular every day. So, “what is the cloud?” is an important question to understand whether we need it or not in our projects. In this article, I will try to explain briefly what I understood in &lt;a href="https://www.udemy.com/aws-concepts"&gt;AWS Concepts course of Linux Academy&lt;/a&gt;. I strongly suggest this short course (totally around 1 hour) to whom wonder cloud services and AWS basics. Then you can continue with &lt;a href="https://www.udemy.com/aws-essentials"&gt;AWS Essentials&lt;/a&gt; course of the same lecturer if you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of Cloud Systems:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;High Availability:&lt;/strong&gt; Your files are always available for any device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fault-Tolerant:&lt;/strong&gt; If some problem occurs there is an available backup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Increase your processor power, storage, database based on demand to your system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elasticity:&lt;/strong&gt; Decrease your processor power, storage, database based on demand to your system.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Amazon Web Service (AWS)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MM0EIjp0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/2988/1%2AGKncqEpK7u_IKHlvIacjbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MM0EIjp0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/2988/1%2AGKncqEpK7u_IKHlvIacjbg.png" alt="Basic structure of Amazon Web Service" width="800" height="509"&gt;&lt;/a&gt;&lt;br&gt;
Let’s talk about these basic AWS elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;EC2:&lt;/strong&gt; A virtual computer which is primarily used for its computing power. You can think of it as a basic computer which includes CPU, RAM, Firewall, Operating System, etc. It generally used as a web hosting part of the system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RDS:&lt;/strong&gt; Database of AWS. You can store information such as inventory catalog or customer info in there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S3:&lt;/strong&gt; It is a massive storage bucket. It commonly used for storing media files such as images, videos, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VPC:&lt;/strong&gt; Virtual Private Cloud is your private section on AWS, where you can allow/restrict access to them.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oI_5KHyv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/2412/1%2AqK3UniXOB_oodE8qorhilQ.png" alt="Availability Region &amp;amp; Zone" width="800" height="598"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Availability Zone:&lt;/strong&gt; Physical location of Amazon Data Centers. They have separated geographically in each AWS region also.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Region:&lt;/strong&gt; A geographical region which includes AWS Availability Zones, such as Tokyo, Dublin. It helps decreasing latency due to geographical distances.&lt;/p&gt;

&lt;p&gt;Generally, there are more than one Availability Zones in an AWS region in order to provide ‘High Availability’ and ‘Fault Tolerant’ as we mentioned above. For instance, if there is a disaster or power outage in an Availability zone you can connect the other one.&lt;/p&gt;

&lt;p&gt;As a result, these are the very basics of cloud services and especially Amazon Web Services. If you want to dig into more about this topic, I strongly suggest the courses which I mentioned in the introduction passage.&lt;/p&gt;

&lt;p&gt;My some other articles:&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27"&gt;Create a Multi-Language Website with React Context API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/chrome-devtool-tips-2eb"&gt;Chrome Devtool Tips&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/an-nlp-command-line-application-with-node-js-33na"&gt;An NLP Command Line Application with Node.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>webdev</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>An NLP CLI App for Terminal Commands</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Sat, 02 Nov 2019 19:00:18 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/an-nlp-command-line-application-with-node-js-33na</link>
      <guid>https://dev.to/halilcanozcelik/an-nlp-command-line-application-with-node-js-33na</guid>
      <description>&lt;p&gt;This project is an approach for a command-line application which is working with human language. The main benefits of using such a tool at first glance are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You don’t need to find different commands for the same job according to operating systems. For instance, you must use &lt;code&gt;ls&lt;/code&gt; in a Linux based OS, but you have to use &lt;code&gt;dir&lt;/code&gt; in Windows for the same job. Of course, this is a very basic example but if you think about more complicated and less-known commands and also take into consideration the number of different operating systems, working independently of operating systems will be very beneficial.&lt;/li&gt;
&lt;li&gt;No need to memorize commands &amp;amp; parameters anymore. Again if you think about well-known easy commands, writing &lt;code&gt;list files&lt;/code&gt; instead of &lt;code&gt;ls&lt;/code&gt; doesn’t seem effective to you. But if more advanced commands come in or you need several parameters while executing commands, writing a sentence instead of searching them on the internet makes sense.&lt;/li&gt;
&lt;li&gt;You can use your native language for the command line. This application supports all languages which are available in &lt;a href="https://wit.ai"&gt;Wit.ai&lt;/a&gt; service. It includes almost all widely used languages such as Chinese, English, French, German, Russian, Spanish, Turkish, etc. &lt;a href="https://wit.ai/faq"&gt;You can check the list of all supported languages from this link.&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When it comes to the technical part, it has two sub-projects. Both client and server sides of it are developed with Node.js. Here is a more detailed explanation of them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client-side project:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/sem-cli"&gt;It is an npm package.&lt;/a&gt; It basically sends requests to the server. According to the response whether executing the related command or show an error or confirmation messages. &lt;a href="https://github.com/hcoz/sem-cli"&gt;You can check the GitHub link if you want to examine it in detail.&lt;/a&gt; Or you can install it directly by running &lt;code&gt;npm install sem-cli -g&lt;/code&gt; in your terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server-side project:&lt;/strong&gt; This project is developed with Azure Functions (Node.js) + CosmosDB + &lt;a href="https://wit.ai"&gt;Wit.ai&lt;/a&gt;. It is developed as a serverless system in Azure Cloud. &lt;a href="https://github.com/hcoz/sem-cli-serverless"&gt;Here is the Github repository of this project.&lt;/a&gt; The server side of the project contains the main logic. I will try to explain in detail below.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the client-side package, there are three commands which are sem-exec, sem-look, and sem-suggest. The first one is for running a command, the second one is to search for a command with human language and the last one is for suggesting new intent &amp;amp; command relations. The command coverage of this project will increase under the favor of these suggestions from users.&lt;br&gt;
Now let’s dig into how these commands work. But first I want to give information about parameters in these commands. So we can understand easier the rest of this article.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;intent:&lt;/strong&gt; It is a short explanation for the purpose of this command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;command:&lt;/strong&gt; It is the related command.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;message:&lt;/strong&gt; It is the client’s message with the human language. No need to write it without any typo. Our AI service can handle many typo errors. Also, it supports many different languages. You can use your native language, but I give all the examples in English for this article.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dangerLevel:&lt;/strong&gt; It shows how dangerous to run this command. It can be “low”, “medium” or “high”. (“high” dangerous commands will not be run before a client approval)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The workflow of running command by &lt;code&gt;sem-exec&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wFdgmqt1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2Ap_8D7h0pbWN6HODp6m9jCg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wFdgmqt1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/700/1%2Ap_8D7h0pbWN6HODp6m9jCg.png" alt="sem-exec workflow" width="700" height="416"&gt;&lt;/a&gt;&lt;br&gt;
Let’s go through step by step according to numbers in the schema:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user enters a message. You don’t need to enter messages with %100 correctly typed. Thanks to Wit.ai, we can analyze sentences although some typos.&lt;/li&gt;
&lt;li&gt;The server asks Wit.ai to find out related intent, in other words, the meaning of the user’s sentence.&lt;/li&gt;
&lt;li&gt;Then we got the intent, if there is no result, the server returns an error message to the client.&lt;/li&gt;
&lt;li&gt;Query database to find related command according to the intent &amp;amp; operating system of the request.&lt;/li&gt;
&lt;li&gt;And then get the result from the database.&lt;/li&gt;
&lt;li&gt;If there is a command, return it with danger level information otherwise return a “not found” error message. On the client-side, it runs the command or shows the error or confirmation message.&lt;/li&gt;
&lt;li&gt;For commands with a “high” danger level, our program asks for client confirmation. &lt;code&gt;Are you sure to run: &amp;lt;result-command&amp;gt;? (type 'y' for yes, 'n' for no)&lt;/code&gt; If the user accepts it, then the command will be executed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The workflow of running command by &lt;code&gt;sem-look&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This command has the same process as &lt;code&gt;sem-exec&lt;/code&gt;.&lt;br&gt;
However, it returns the corresponding command instead of executing it. For instance, if you run&lt;br&gt;
&lt;code&gt;sem-look compare files p="a.txt b.txt"&lt;/code&gt;&lt;br&gt;
as command then it returns the following message:&lt;br&gt;
&lt;code&gt;Your command: "cmp a.txt b.txt" with danger level: "low" for your current operating system.&lt;/code&gt;&lt;br&gt;
The current operating system is Mac OS for this example.&lt;/p&gt;

&lt;h3&gt;
  
  
  The logic of &lt;code&gt;sem-suggest&lt;/code&gt; is much simpler
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qP7z70qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/610/1%2ATI5qHmWdWZrC7OwlO-v7wA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qP7z70qf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/610/1%2ATI5qHmWdWZrC7OwlO-v7wA.png" alt="sem-suggest workflow" width="610" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user sends a suggestion triples that must contain intent, command, and danger level.&lt;/li&gt;
&lt;li&gt;The server adds this new suggestion to the database. These records are stored in the suggestion table. They will be evaluated manually in the current scenario.&lt;/li&gt;
&lt;li&gt;We got a response from the database.&lt;/li&gt;
&lt;li&gt;The server returns a success or error message to the client.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally, I want to mention the database. There are two containers with the same document structure.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;commands

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;intent&lt;/strong&gt; (the aim of the command)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;command&lt;/strong&gt; (executable command)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;os&lt;/strong&gt; (the operating system which the command can work)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dangerLevel&lt;/strong&gt; (danger level of the command)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;suggestions

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;intent&lt;/strong&gt; (the aim of the command)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;command&lt;/strong&gt; (executable command)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;os&lt;/strong&gt; (the operating system which the command can work)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dangerLevel&lt;/strong&gt; (danger level of the command)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By the way, &lt;strong&gt;you don’t need to write your operating system&lt;/strong&gt; either for &lt;code&gt;sem-look&lt;/code&gt; or &lt;code&gt;sem-suggest&lt;/code&gt;, because it is detected by the client-side program and added to the requests as a parameter. So, please suggest a command which is working on your current operating system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Current Status
&lt;/h2&gt;

&lt;p&gt;The project is working as expected. However, there is not enough data in the commands table. So, it is not covering a wide variety of command requests for now. For this reason, &lt;strong&gt;the enrichment of the commands list is the most important point in the current situation.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Future Improvements &amp;amp; Challenges
&lt;/h2&gt;

&lt;p&gt;In my opinion, the main challenge in front of this project is the enrichment of the database with new commands. It will be very difficult if only several people add new commands. Suggestion functionality is added to give permission for proposing new commands to everyone. After checking these suggestions, beneficial ones will be added to the database. This evaluation process is done manually for now.&lt;br&gt;
Additionally, distinguishing the parameter differences of commands in the semantic analysis will be another challenging point. Although we handle the finding correct command for human sentence requests when it comes to detecting differences in the manner of command parameters, &lt;strong&gt;training of AI is the crucial point.&lt;/strong&gt; User messages and intents are matched on Wit.ai panel and it increases the analysis power of our tool. The more this tool is used, the more matching occurs and it increases the confirmation rate (which is between 0 and 1). So we can increase our threshold for matchings, it also helps us for detecting the differences in quite similar messages such as &lt;code&gt;list files =&amp;gt; ls&lt;/code&gt; and &lt;code&gt;list all files =&amp;gt; ls -a&lt;/code&gt;. Again this one is a very basic example, it is already detectable by our system :)&lt;/p&gt;

&lt;p&gt;Here is my project about an NLP approach to command line usage. If you think it can be useful and you have some ideas, I will be happy to hear. Also, I am eager for collaboration.&lt;/p&gt;

</description>
      <category>contributorswanted</category>
      <category>node</category>
      <category>javascript</category>
      <category>bash</category>
    </item>
    <item>
      <title>Building a web server with pure Node.js</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Sat, 02 Nov 2019 18:54:09 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/building-a-web-server-with-pure-node-js-4g6i</link>
      <guid>https://dev.to/halilcanozcelik/building-a-web-server-with-pure-node-js-4g6i</guid>
      <description>&lt;p&gt;There are many frameworks for Node.js to build a web server application. I am adding several of the most well-known ones below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://expressjs.com"&gt;Express&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://koajs.com"&gt;Koa&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hapijs.com"&gt;hapi.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, what if we don’t want to use any of them? We can build a web server by using pure Node.js. Of course, these frameworks make our life easier. Personally, I often use Express framework mostly but I will use pure Node.js API from now on as much as possible, especially for small projects :) This is simply because of the fact that these frameworks add many dependencies to our project so it causes huge &lt;strong&gt;node_modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qBDxAlsI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/proxy/1%2AtLmdca91O3WXf_ZTiy8JFA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qBDxAlsI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/proxy/1%2AtLmdca91O3WXf_ZTiy8JFA.jpeg" alt="node_modules becomes really huge in projects if you use many frameworks and libraries&amp;lt;br&amp;gt;
" width="800" height="575"&gt;&lt;/a&gt;&lt;br&gt;
A simple web application or server can be built equally easily by using built-in modules making our apps more lightweight and easy to manage/maintain.&lt;br&gt;
If you are used to reading code better than words, here’s a simple web server application built without any frameworks on Node.js. &lt;a href="https://github.com/hcoz/pure-nodejs-web-server"&gt;You can also check on GitHub from this link&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const http = require('http');
/** handle GET request */
function getHandler(req, res, reqUrl) {
  res.writeHead(200);
  res.write('GET parameters: ' + reqUrl.searchParams);
  res.end();
}

/** handle POST request */
function postHandler(req, res, reqUrl) {
  req.setEncoding('utf8');
  req.on('data', (chunk) =&amp;gt; {
    res.writeHead(200);
    res.write('POST parameters: ' + chunk);
    res.end();
  });
}

/** if there is no related function which handles the request, then show error message */
function noResponse(req, res) {
  res.writeHead(404);
  res.write('Sorry, but we have no response..\n');
  res.end();
}

http.createServer((req, res) =&amp;gt; {
  // create an object for all redirection options
  const router = {
    'GET/retrieve-data': getHandler,
    'POST/send-data': postHandler,
    'default': noResponse
  };
  // parse the url by using WHATWG URL API
  let reqUrl = new URL(req.url, 'http://127.0.0.1/');
  // find the related function by searching "method + pathname" and run it
  let redirectedFunc = router[req.method + reqUrl.pathname] || router['default'];
  redirectedFunc(req, res, reqUrl);
}).listen(8080, () =&amp;gt; {
  console.log('Server is running at http://127.0.0.1:8080/');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firstly, I am creating an HTTP server by using &lt;code&gt;createServer()&lt;/code&gt; method from the HTTP API of Node.js. In the request listener part of it, I am detecting the request and redirecting the related function.&lt;/p&gt;

&lt;p&gt;As you can see, I have three functions which are &lt;code&gt;getHandler()&lt;/code&gt;, &lt;code&gt;postHandler()&lt;/code&gt; and &lt;code&gt;noResponse()&lt;/code&gt;. They are handling the related URL request. URL and function couples are stored in &lt;code&gt;router&lt;/code&gt; object as &lt;code&gt;{ method/url: function }&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then, I parse the URL by using the &lt;a href="https://nodejs.org/api/url.html#url_the_whatwg_url_api"&gt;WHATWG URL API&lt;/a&gt;. One of the reasons for this, I can get many URL functionalities such as pathname, host, origin, etc and I can handle easily without struggling string manipulations. After that, I construct my request key which is &lt;code&gt;req.method + reqUrl.pathname&lt;/code&gt; for searching related function.&lt;/p&gt;

&lt;p&gt;And finally, find the related function from &lt;code&gt;router&lt;/code&gt; and call it by passing &lt;code&gt;request&lt;/code&gt; and &lt;code&gt;response&lt;/code&gt; objects. If there is no related function in the object then I call the default one which is &lt;code&gt;noResponse()&lt;/code&gt; in our case.&lt;/p&gt;

&lt;p&gt;Here is my approach to creating a simple web server with pure Node.js. In my opinion, working on a software language without any framework is also important to understand the basics of it.&lt;/p&gt;

&lt;p&gt;You can read this &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework"&gt;MDN documentation&lt;/a&gt; for an extended example of a pure Node.js server. And of course, &lt;a href="https://nodejs.org/api/"&gt;Node.js API&lt;/a&gt; is the most important document which helps you!&lt;/p&gt;

&lt;p&gt;Additionally, you can check the &lt;a href="https://github.com/hcoz/sem-cli-server"&gt;server-side of my NLP Command Line App project&lt;/a&gt; for a more detailed implementation of the pure Node.js server. Also, read &lt;a href="https://dev.to/halilcanozcelik/an-nlp-command-line-application-with-node-js-33na"&gt;my article about this project&lt;/a&gt; if you want to learn more about it.&lt;/p&gt;

&lt;p&gt;My some other articles:&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/create-a-multi-language-website-with-react-context-api-4i27"&gt;Create a Multi-Language Website with React Context API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/chrome-devtool-tips-2eb"&gt;Chrome Devtool Tips&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/halilcanozcelik/an-nlp-command-line-application-with-node-js-33na"&gt;An NLP Command Line Application with Node.js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Essais on REST API</title>
      <dc:creator>Halil Can Ozcelik</dc:creator>
      <pubDate>Fri, 01 Nov 2019 21:32:44 +0000</pubDate>
      <link>https://dev.to/halilcanozcelik/essais-on-rest-api-5dc2</link>
      <guid>https://dev.to/halilcanozcelik/essais-on-rest-api-5dc2</guid>
      <description>&lt;p&gt;REST (Representational State Transfer) is based on HTTP. I will write some basic information about the REST API. It is not a structured REST explanation, I will write down some notes about it.&lt;/p&gt;

&lt;p&gt;If a request is cached, the response can be sent from one of the intermediaries (Proxy or Gateway) without reaching to server.&lt;/p&gt;

&lt;h3&gt;
  
  
  REST Methods
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET:&lt;/strong&gt; Retrieve information about the REST API resource&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST:&lt;/strong&gt; Create a REST API resource&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PUT:&lt;/strong&gt; Update a REST API resource wholly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DELETE:&lt;/strong&gt; Delete a REST API resource or related component&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PATCH:&lt;/strong&gt; Update a REST API resource partially or wholly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HEAD:&lt;/strong&gt; Identical to GET requests but only returns HTTP headers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OPTIONS:&lt;/strong&gt; Describes the communication options for the target resource&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CONNECT:&lt;/strong&gt; Establishes a tunnel to the server identified by the target resource&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TARGET:&lt;/strong&gt; Performs a message loop-back test along the path to the target resource&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here are some helpful information about various REST methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET requests can be cached POST requests never cached&lt;/li&gt;
&lt;li&gt;GET requests to remain in browser history POST request does NOT&lt;/li&gt;
&lt;li&gt;GET request can be bookmarked POST requests can NOT&lt;/li&gt;
&lt;li&gt;GET requests to have length restrictions POST request have NOT&lt;/li&gt;
&lt;li&gt;PUT requests insert or update a record depending upon whether the given record exists&lt;/li&gt;
&lt;li&gt;PATCH requests set or update selected properties only and NOT the whole data.&lt;/li&gt;
&lt;li&gt;Idempotent requests: Making multiple identical requests has the same effect as making a single request.&lt;/li&gt;
&lt;li&gt;POST, CONNECT and PATCH methods are NOT idempotent.&lt;/li&gt;
&lt;li&gt;GET, HEAD, OPTIONS, PUT, DELETE and TRACE methods are idempotent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information, I suggest you visit the related page in &lt;a href="//w3.org"&gt;W3C&lt;/a&gt; and the related &lt;a href="https://developer.mozilla.org"&gt;Mozilla Developer Network page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
