<?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: Ankit Kumar</title>
    <description>The latest articles on DEV Community by Ankit Kumar (@architectak).</description>
    <link>https://dev.to/architectak</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%2F89963%2F1f622fa8-60d1-4948-8866-96499cb8839d.jpg</url>
      <title>DEV Community: Ankit Kumar</title>
      <link>https://dev.to/architectak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/architectak"/>
    <language>en</language>
    <item>
      <title>Understanding React Concurrency</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Mon, 29 May 2023 10:35:07 +0000</pubDate>
      <link>https://dev.to/architectak/understanding-react-concurrency-1hpi</link>
      <guid>https://dev.to/architectak/understanding-react-concurrency-1hpi</guid>
      <description>&lt;p&gt;React v18.0 has broken ground by introducing a long-awaited feature: Concurrency! Concurrency refers to having more than one task in progress at once, and concurrent tasks can overlap depending on which is more urgent.&lt;/p&gt;




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

&lt;p&gt;It is a way to structure a program by breaking it into pieces that can be executed independently. This is how we can break the limits of using a single thread, and make our application more efficient.&lt;/p&gt;

&lt;p&gt;The basic premise of React concurrency is to re-work the rendering process such that while rendering the next view, the current view is kept responsive.&lt;/p&gt;

&lt;p&gt;Concurrent Mode was a proposal the React team had to improve application performance. The idea was to break up the rendering process into interruptible units of work.&lt;/p&gt;

&lt;p&gt;Under the hood, this would be implemented by wrapping component renders in a requestIdleCallback() call, keeping applications responsive during the rendering process.&lt;/p&gt;

&lt;p&gt;So hypothetically, if Blocking Mode were implemented like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderBlocking&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;Child&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;renderBlocking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Child&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;Then Concurrent Mode would be implemented like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderConcurrent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Interrupt rendering process if state out-dated&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;isCancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&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;Child&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Wait until browser isn't busy (no inputs to process)&lt;/span&gt;
        &lt;span class="nf"&gt;requestIdleCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;renderConcurrent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Child&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;If you’re curious how React does this in reality, take a peek at the &lt;a href="https://github.com/facebook/react/blob/5309f102854475030fb91ab732141411b49c1126/packages/scheduler/src/forks/Scheduler.js#L209-L277" rel="noopener noreferrer"&gt;implementation of React’s scheduler package&lt;/a&gt;.&lt;br&gt;
After initially using requestIdleCallback, React switched to requestAnimationFrame, and later to a user-space timer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Good bye to (Concurrent) Mode, Only Features
&lt;/h2&gt;

&lt;p&gt;The Concurrent Mode plan did not materialize for backward-compatibility reasons.&lt;/p&gt;

&lt;p&gt;Instead, the React team pivoted to Concurrent Features, a set of new APIs selectively enabling concurrent rendering. So far, React has introduced two new hooks to opt into a concurrent render.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;startTrnsition&lt;/li&gt;
&lt;li&gt;useTransiiton&lt;/li&gt;
&lt;li&gt;useDefferedValue&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Lets now understand all of them with examples&lt;/p&gt;

&lt;h2&gt;
  
  
  startTransition
&lt;/h2&gt;

&lt;p&gt;The startTransition hook introduced with React 18 helps us keep our app responsive without blocking your user interactions by allowing you to mark specific updates as transitions.&lt;/p&gt;

&lt;p&gt;There are two categories of state updates in React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Urgent updates: show direct interaction like clicking, typing, etc.&lt;/li&gt;
&lt;li&gt;Transition updates: change UI views&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React considers state updates wrapped in startTransition as non-urgent, so they can be suspended or interrupted by urgent updates.&lt;/p&gt;

&lt;p&gt;For example, as a user, it would feel more natural to see the letters as you type in a search input field for filtering data, but as expected, the search result may take a while, and that’s OK.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

 &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Urgent&lt;/span&gt;
&lt;span class="nf"&gt;setInputValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Mark any state updates inside as transitions&lt;/span&gt;
&lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;// Transition&lt;/span&gt;
   &lt;span class="nf"&gt;setSearchQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  useTransition
&lt;/h2&gt;

&lt;p&gt;React can also track and update pending state transitions using the useTransition hook with an isPending flag. This lets you display loading feedback to your users, letting them know that work is happening in the background.&lt;/p&gt;

&lt;p&gt;The useTransition hook returns two items:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boolean flag isPending, which is true if a concurrent render is in progress&lt;/li&gt;
&lt;li&gt;Function startTransition, which dispatches a new concurrent render&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use it, wrap setState calls in a startTransition callback.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTransition&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Run this update concurrently&lt;/span&gt;
            &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increment&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;Count&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pending&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Not Pending&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="c1"&gt;// Component which benefits from concurrency&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ManySlowComponents&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Conceptually, state updates detect if they are wrapped in a startTransition to decide whether to schedule a blocking or concurrent render.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stateUpdates&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;isInsideTransition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;stateUpdates&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;isInsideTransition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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;isInsideTransition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Schedule concurrent render&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="c1"&gt;// Schedule blocking render&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;An important caveat of useTransition is that it cannot be used for controlled inputs. For those cases, it is best to use useDeferredValue.&lt;/p&gt;




&lt;h2&gt;
  
  
  useDeferredValue
&lt;/h2&gt;

&lt;p&gt;The useDeferredValue hook is a convenient hook for cases where you do not have the opportunity to wrap the state update in startTransition but still wish to run the update concurrently.&lt;/p&gt;

&lt;p&gt;useDefferedValue takes in a state value and a timeout in milliseconds and returns the deferred version of that state value. The timeout tells React how long it should delay the deferred value.&lt;/p&gt;

&lt;p&gt;Conceptually, useDeferredValue is a debounce effect and can be implemented as such:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useDeferredValue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deferredValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDeferredValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;timeoutMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 

      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyList&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;deferredValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;With what we have in the code snippet above, the input value will be displayed immediately when a user starts typing, but useDeferredValue will display a previous version of the MyList component for at most 3000 milliseconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  Concurrent Features &amp;amp; Suspense
&lt;/h3&gt;

&lt;p&gt;The useTransition and useDeferredValue hooks have a purpose beyond opting in concurrent rendering: they also wait for Suspense components to complete.&lt;/p&gt;




&lt;p&gt;If you like this post, &lt;a href="https://www.buymeacoffee.com/ArchitectAK" rel="noopener noreferrer"&gt;you can buy me a coffee&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/ArchitectAK" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--BSV4goFV--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_800%2Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzir1erzg7v28nvyuue09.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, to be notified about my new articles and stories: Follow me on &lt;a href="https://architectak.medium.com/" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK" rel="noopener noreferrer"&gt;YouTube Channel&lt;/a&gt; for educational content on similar topics&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://hashnode.com/@ArchitectAK" rel="noopener noreferrer"&gt;Hashnode&lt;/a&gt; and &lt;a href="https://github.com/ArchitectAK" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, for connecting quickly&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/ArchitectAK" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; as it’s a professional network for people like me and you.&lt;/p&gt;

&lt;p&gt;Cheers!!!!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Functional Programming Principles in JavaScript</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Thu, 25 May 2023 13:13:00 +0000</pubDate>
      <link>https://dev.to/letstechtalks/functional-programming-principles-1m0n</link>
      <guid>https://dev.to/letstechtalks/functional-programming-principles-1m0n</guid>
      <description>&lt;p&gt;Before going to it’s principles, let first understand a bit about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Functional Programming
&lt;/h2&gt;

&lt;p&gt;Functional programming is a paradigm which has its roots in mathematics, primarily stemming from lambda calculus.&lt;br&gt;
Its main focus is on “what to solve” in contrast to an imperative style where the main focus is “how to solve”.&lt;br&gt;
Functional programming aims to be declarative and treats applications as the result of pure functions which are composed with one another.&lt;/p&gt;

&lt;p&gt;The primary aim of this style of programming is to avoid the problems that come with shared state, mutable data and side effects which are common place in object oriented programming.&lt;br&gt;
Functional programming tends to be more predictable and easier to test than object oriented programming but can also seem dense and difficult to learn for new comers but functional programming isn’t as difficult as it would at first seem.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why do we need Functional Programming?
&lt;/h2&gt;

&lt;p&gt;There are a few major benefits to Functional Programming and minor drawbacks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More readability, thus maintainability&lt;/li&gt;
&lt;li&gt;Less buggy, especially in concurrent contexts&lt;/li&gt;
&lt;li&gt;A new way of thinking about problem solving&lt;/li&gt;
&lt;li&gt;(Personal bonus) Just great to learn about!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drawbacks:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can have performance issues&lt;/li&gt;
&lt;li&gt;Less intuitive to work with when dealing with state and I/O&lt;/li&gt;
&lt;li&gt;Unfamiliar for most people + math terminology that slows the learning process&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Functional programming tends to be more predictable and easier to test than object oriented programming.&lt;/p&gt;


&lt;h2&gt;
  
  
  Principles
&lt;/h2&gt;

&lt;p&gt;On broader level, there mainly 6 principles of Functional Programming&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Purity&lt;/li&gt;
&lt;li&gt;Immutability&lt;/li&gt;
&lt;li&gt;Disciplined state&lt;/li&gt;
&lt;li&gt;First class functions and high order functions&lt;/li&gt;
&lt;li&gt;Type systems&lt;/li&gt;
&lt;li&gt;Referential transparency&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Lets see them in details below.&lt;/p&gt;
&lt;h3&gt;
  
  
  Purity
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A Pure Function is a function (a block of code) that always returns the same result if the same arguments are passed.&lt;/li&gt;
&lt;li&gt;It does not depend on any state or data change during a program’s execution. Rather, it only depends on its input arguments.&lt;/li&gt;
&lt;li&gt;Also, a pure function does not produce any observable side effects such as network requests or data mutation, etc.&lt;/li&gt;
&lt;li&gt;It has no side effects like modifying an argument or global variable or outputting something.&lt;/li&gt;
&lt;li&gt;Pure functions are predictable and reliable. Most of all, they only calculate their result. The only result of calling a pure function is the return value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets see an example below for calculating GST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateGST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;productPrice&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.05&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;ul&gt;
&lt;li&gt;The computation in square function depends on the inputs. No matter how many times we call a square function with the same input, it will always return the same output.
Example below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sqaureIt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Immutability
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Immutable data cannot change its structure or the data in it.&lt;/li&gt;
&lt;li&gt;Once you assign a value to something, that value won’t change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Immutability is at the core of functional programming. This eliminates side effects (anything outside of the local function scope), for instance, changing other variables outside the function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Immutability helps to maintain state throughout the runtime of a program.&lt;/li&gt;
&lt;li&gt;It makes code simple, testable, and able to run on distributed and multi-threaded systems&lt;/li&gt;
&lt;li&gt;Since function has a disciplined state and does not change other variables outside of the function, we don’t need to look at the code outside the function definition.&lt;/li&gt;
&lt;li&gt;Immutability comes into play frequently when we work with data structures. Many array methods in JavaScript directly modify the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, &lt;code&gt;.pop()&lt;/code&gt; directly removes an item from the end of the array and &lt;code&gt;.splice()&lt;/code&gt; allows you to take a section of an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// We are mutating myArr directly&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;myArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// [1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, within the functional paradigm, we would copy the array and in that process remove the element we are looking to eliminate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// We are copying the array without the last element and storing it to a variable&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myNewArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// [1, 2]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Disciplined state
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Disciplined state is the opposite of shared, mutable state.&lt;/li&gt;
&lt;li&gt;A shared mutable state is hard to keep correct since there are many functions that have direct access to this state. It is also hard to read and maintain.&lt;/li&gt;
&lt;li&gt;With mutable state, we need to look up for all the functions that use shared variables, in order to understand the logic. - It’s hard to debug for the very same reason.&lt;/li&gt;
&lt;li&gt;When we are coding with functional programming principles in mind, you avoid, as much as possible, having a shared mutable state.&lt;/li&gt;
&lt;li&gt;Of course we can have state, but you should keep it local, which means inside our function. This is the state discipline : we use state, but in a very disciplined way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An example of the drawbacks of shared, mutable state would be the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;React&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Typescript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;=== Before sorting ===&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;logElements&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;=== After sorting ===&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;logElements&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// === Before sorting ===&lt;/span&gt;
&lt;span class="c1"&gt;// "Node"&lt;/span&gt;
&lt;span class="c1"&gt;// "React"&lt;/span&gt;
&lt;span class="c1"&gt;// "Javascript"&lt;/span&gt;
&lt;span class="c1"&gt;// "Typescript"&lt;/span&gt;

&lt;span class="c1"&gt;// === After sorting ===&lt;/span&gt;
&lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can see that the second call produces no result since the first call emptied the input array and thus mutated the application state generating an unexpected output.&lt;/p&gt;

&lt;p&gt;To fix this we turn to immutability and the use of copies to keep the initial state transparent and immutable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;React&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Typescript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;=== Before sorting ===&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;logElements&lt;/span&gt;&lt;span class="p"&gt;([...&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Change in line&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sorted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Assign sorted items to another variable&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;=== After sorting ===&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;logElements&lt;/span&gt;&lt;span class="p"&gt;([...&lt;/span&gt;&lt;span class="nx"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Change in line&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// === Before sorting ===&lt;/span&gt;
&lt;span class="c1"&gt;// "Node"&lt;/span&gt;
&lt;span class="c1"&gt;// "React"&lt;/span&gt;
&lt;span class="c1"&gt;// "Javascript"&lt;/span&gt;
&lt;span class="c1"&gt;// "Typescript"&lt;/span&gt;

&lt;span class="c1"&gt;// === After sorting ===&lt;/span&gt;
&lt;span class="c1"&gt;// "Javascript"&lt;/span&gt;
&lt;span class="c1"&gt;// "Node"&lt;/span&gt;
&lt;span class="c1"&gt;// "React"&lt;/span&gt;
&lt;span class="c1"&gt;// "Typescript"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  First class functions and high order functions
&lt;/h3&gt;

&lt;p&gt;Higher order functions are functions which do at least one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes one or more functions as arguments&lt;/li&gt;
&lt;li&gt;Returns a function as its result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Functional programming treats functions as first-class citizens.&lt;/p&gt;

&lt;p&gt;This means that functions are able to be passed as arguments to other functions, returned as values from other functions, stored in data structures and assigned to variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;plusFive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// f is assigned the value of plusFive&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;plusFive&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;plusFive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;

&lt;span class="c1"&gt;// Since f has a function value, it can be invoked. &lt;/span&gt;

&lt;span class="nf"&gt;f&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="c1"&gt;// 14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Higher order function is the function that takes one or more functions as arguments or returns a function as its result.&lt;/p&gt;




&lt;h3&gt;
  
  
  Type systems
&lt;/h3&gt;

&lt;p&gt;By using types we leverage a compiler to help us avoid common mistakes and errors that can occur during the development process.&lt;/p&gt;

&lt;p&gt;With JavaScript we could do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;span class="nf"&gt;add&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "5"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is bad because now we are getting an unexpected output which could have been caught by a compiler.&lt;/p&gt;

&lt;p&gt;Let’s look at the same code written with Typescript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;span class="nf"&gt;add&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// error!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see the compiler in action protecting us from such basic issues, of course much more is possible with a statically typed approach to developing but this should give you the gist of why it is useful to use.&lt;/p&gt;




&lt;h3&gt;
  
  
  Referential transparency
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Referential transparency is a fancy way of saying that if you were to replace a function call with its return value, the behaviour of the programme would be as predictable as before.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Referentially transparent functions only rely on their inputs and thus are closely aligned with pure functions and the concept of immutability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program’s behaviour.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To achieve referential transparency, a function must be pure. This has benefits in terms of readability and speed. Compilers are often able to optimise code that exhibits referential transparency.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;two&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;four&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;two&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;two&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;four&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;two&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;four&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;two&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;four&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Conclusions
&lt;/h3&gt;

&lt;p&gt;Functional programming gives us some principles which make our code more readable, predictable and testable.&lt;/p&gt;

&lt;p&gt;This allows us to have code which contains less bugs, easier onboarding and a generally nicer codebase from my experience.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/ArchitectAK" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--BSV4goFV--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_800%2Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzir1erzg7v28nvyuue09.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, to be notified about my new articles and stories: Follow me on &lt;a href="https://architectak.medium.com" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK" rel="noopener noreferrer"&gt;YouTube Channel&lt;/a&gt; for educational content on similar topics&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://architectak.medium.com" rel="noopener noreferrer"&gt;Medium&lt;/a&gt; and &lt;a href="https://github.com/ArchitectAK" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; for connecting quickly.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/ArchitectAK" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; as it’s a professional network for people like me and you.&lt;/p&gt;

&lt;p&gt;Cheers!!!!&lt;/p&gt;

</description>
      <category>functional</category>
      <category>programming</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to create custom Decorator for Circuit Breaker in Typescript/Javascript Applications</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 04 Jan 2023 07:53:34 +0000</pubDate>
      <link>https://dev.to/architectak/how-to-create-custom-decorator-for-circuit-breaker-in-typescriptjavascript-applications-186k</link>
      <guid>https://dev.to/architectak/how-to-create-custom-decorator-for-circuit-breaker-in-typescriptjavascript-applications-186k</guid>
      <description>&lt;p&gt;To understand “How to create Decorators in Typescript for Circuit Breakers”, we need to understand&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are decorators in typescript?&lt;/li&gt;
&lt;li&gt;What are circuit breakers in software systems?&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Let's first read a bit about decorators
&lt;/h3&gt;

&lt;p&gt;Decorators are a way to decorate functions, members of a class, or a class itself, with extra functionality.&lt;/p&gt;

&lt;p&gt;When you apply a decorator to a function, a class, or a class member, you are actually calling a function that is going to receive details of what is being decorated, and the decorator implementation will then be able to transform the code dynamically, adding extra functionality, and reducing boilerplate code.&lt;/p&gt;

&lt;p&gt;They are a way to have metaprogramming in TypeScript, which is a programming technique that enables the programmer to create code that uses other code from the application itself as data.&lt;/p&gt;




&lt;h3&gt;
  
  
  Let’s now see what are circuit breakers
&lt;/h3&gt;

&lt;p&gt;A circuit breaker is an electrical safety device designed to protect an electrical circuit from damage caused by an overcurrent or short circuit. Its basic function is to interrupt current flow to protect equipment and to prevent the risk of fire. Unlike a fuse, which operates once and then must be replaced, a circuit breaker can be reset (either manually or automatically) to resume normal operation.&lt;/p&gt;

&lt;p&gt;The basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, which monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the protected call being made at all. Usually, you’ll also want some kind of monitor alert if the circuit breaker trips.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://architectak.medium.com/decorating-circuit-breaker-in-typescript-javascript-applications-6732e248f27"&gt;Read full article&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/ArchitectAK"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dznQKPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--BSV4goFV--/c_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zir1erzg7v28nvyuue09.jpg" width="350" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>circuitbreaker</category>
      <category>decaorator</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Marketing Yourself as a Job Candidate: Key points to Stand Out from the Crowd</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 27 Jul 2022 00:57:34 +0000</pubDate>
      <link>https://dev.to/architectak/marketing-yourself-as-a-job-candidate-key-points-to-stand-out-from-the-crowd-28ko</link>
      <guid>https://dev.to/architectak/marketing-yourself-as-a-job-candidate-key-points-to-stand-out-from-the-crowd-28ko</guid>
      <description>&lt;p&gt;Job searching is more than just submitting your CV and waiting for a positive response.&lt;br&gt;
In a competitive and vast Information Technology job market, it is vital that you stand out from the crowd. Having the needed skills and experience is not always enough to crack the interview. To be noticed by employers, effective self-marketing is key.&lt;br&gt;
However, self-marketing for a job can be tricky, especially if you’re a fresh job seeker or a worker planning a mid-career switch. Being the former means you’re new to the job search game while the latter puts you out of touch with the latest job search trends.&lt;br&gt;
If you are scratching your head on what to do, stop getting afraid of it because I am putting together some tips for marketing yourself effectively that will up your chances of landing that job you’ve been eyeing.&lt;br&gt;
You are welcome !!&lt;br&gt;
Read full article at&lt;br&gt;
&lt;a href="https://link.medium.com/ss8GRMLvZrb"&gt;https://link.medium.com/ss8GRMLvZrb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>interview</category>
      <category>job</category>
      <category>preparation</category>
      <category>tips</category>
    </item>
    <item>
      <title>How do you handle toxic environment at your work?</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 13 Jul 2022 13:58:55 +0000</pubDate>
      <link>https://dev.to/architectak/how-do-you-handle-toxic-environment-at-your-office-2olo</link>
      <guid>https://dev.to/architectak/how-do-you-handle-toxic-environment-at-your-office-2olo</guid>
      <description></description>
      <category>work</category>
      <category>toxic</category>
      <category>office</category>
      <category>environment</category>
    </item>
    <item>
      <title>What are Arrow functions?</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Sun, 13 Jun 2021 08:56:39 +0000</pubDate>
      <link>https://dev.to/letstechtalks/what-are-arrow-functions-32d1</link>
      <guid>https://dev.to/letstechtalks/what-are-arrow-functions-32d1</guid>
      <description>&lt;ul&gt;
&lt;li&gt;An arrow function expression is a compact alternative to a traditional function expression, but is limited and can't be used in all situations.

&lt;ul&gt;
&lt;li&gt;Does not have its own bindings to this or super, and should not be used as methods.&lt;/li&gt;
&lt;li&gt;Does not have arguments, or new.target keywords.&lt;/li&gt;
&lt;li&gt;Not suitable for call, apply and bind methods, which generally rely on establishing a scope.&lt;/li&gt;
&lt;li&gt;Can not be used as constructors.&lt;/li&gt;
&lt;li&gt;Can not use yield, within its body.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Arrow Functions are a new way of making functions in JavaScript.&lt;/li&gt;
&lt;li&gt;Arrow Function has a cleaner syntax than a function expression &lt;/li&gt;
&lt;li&gt;We omit the function keyword from traditional function in making arrow function&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Examples of Arrow Functions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//ES5 Version
var getCurrentDate = function () {
 return new Date();
};

//ES6 Version
const getCurrentDate = () =&amp;gt; new Date();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//ES5 Version
function greet(name) {
 return "Hello " + name + "!";
}

//ES6 Version
const greet = (name) =&amp;gt; `Hello ${name}`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparing traditional functions to arrow functions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function
function (a) {
 return a + 100;
}

// Arrow Function Break Down

// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) =&amp;gt; {
 return a + 100;
}

// 2. Remove the body brackets and word "return" -- the return is implied.
(a) =&amp;gt; a + 100;

// 3. Remove the argument parentheses
a =&amp;gt; a + 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As shown in this code, the { brackets }, ( parentheses ) and "return" are optional, but may be required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have multiple arguments or no arguments, you'll need to re-introduce parentheses around the arguments&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function
function (a, b){
 return a + b + 100;
}

// Arrow Function
(a, b) =&amp;gt; a + b + 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function (no arguments)

let a = 4;
let b = 2;
function (){
 return a + b + 100;
}

// Arrow Function (no arguments)
let a = 4;
let b = 2;
() =&amp;gt; a + b + 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Arrow Functions do not magically guess what or when you want to "return".&lt;/li&gt;
&lt;li&gt;If the body requires additional lines of processing, you'll need to re-introduce brackets PLUS the "return"
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function
function (a, b){
 let chuck = 42;
 return a + b + chuck;
}
// Arrow Function
(a, b) =&amp;gt; {
 let chuck = 42;
 return a + b + chuck;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For named functions, arrow expressions like variables are treated like variables
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Function
function bob (a){
 return a + 100;
}
// Arrow Function
let bob = a =&amp;gt; a + 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = {
 result: 0,
 nums: [1, 2, 3, 4, 5],
 computeResult() {
   // "this" here refers to the "data" object
   const addAll = () =&amp;gt; {
     // arrow functions "copies" the "this" value of the lexical enclosing function
     return this.nums.reduce((total, cur) =&amp;gt; total + cur, 0)
   };
   this.result = addAll();
 }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Arrow functions don't have their own this value.&lt;/li&gt;
&lt;li&gt;It captures or gets the this value of lexically enclosing function,&lt;/li&gt;
&lt;li&gt;The function addAll() copies the this value of the computeResult() and if we declare an arrow function in the global scope the value of this would be the window object.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/CodeWithAK_"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there.&lt;/p&gt;

&lt;p&gt;If you are Instagram person, follow me &lt;a href="https://www.instagram.com/code.with.ak"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>guide</category>
      <category>interview</category>
    </item>
    <item>
      <title>What's the difference between var, let and const keywords?</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Sat, 12 Jun 2021 13:03:00 +0000</pubDate>
      <link>https://dev.to/letstechtalks/what-s-the-difference-between-var-let-and-const-keywords-5ape</link>
      <guid>https://dev.to/letstechtalks/what-s-the-difference-between-var-let-and-const-keywords-5ape</guid>
      <description>&lt;h1&gt;
  
  
  JavaScript has three ways to declare variables.
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var width = 100;
let height = 200;
const key = "Tech Talks";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  var
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;The scope of a variable defined with the keyword “var” is limited to the “function” within which it is defined.&lt;/li&gt;
&lt;li&gt;If it is defined outside any function, the scope of the variable is global.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; is &lt;code&gt;function scoped&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Block Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 var a = 10;
 console.log(a);
} //block 1
{
 a++;
 console.log(a);
} //block 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We are using the keyword &lt;code&gt;var&lt;/code&gt; to define the &lt;code&gt;variable a&lt;/code&gt;, the scope of a is limited to the function within which it is defined.&lt;/li&gt;
&lt;li&gt;Since a is not defined within any function, the scope of the &lt;code&gt;variable a&lt;/code&gt; is global, which means that a is recognized within block 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Function Example&lt;/strong&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 fun1() {
 var a = 10;
 console.log(a);
} //function scope of fun1

function fun2() {
 a++;
 console.log(a);
} //function scope of fun2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Since we have enclosed &lt;code&gt;fun1&lt;/code&gt; and &lt;code&gt;fun2&lt;/code&gt;, within separate functions, the scope of &lt;code&gt;var a=10&lt;/code&gt;, is limited to &lt;code&gt;fun1&lt;/code&gt; and &lt;code&gt;a&lt;/code&gt; is not recognized in &lt;code&gt;fun2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  let:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;The let keyword was introduced as part of ES6 syntax, as an alternative to var to define variables in Javascript.&lt;/li&gt;
&lt;li&gt;The scope of a variable defined with the keyword &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; is limited to the &lt;code&gt;block&lt;/code&gt; defined by curly braces i.e. {}&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; is &lt;code&gt;block scoped&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Block Example&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let us rewrite the code using the keyword &lt;code&gt;let&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 let a = 10;
 console.log(a);
} //block 1
{
 a++;
 console.log(a);
} //block 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Since we are using &lt;code&gt;let a=10&lt;/code&gt;, scope of &lt;code&gt;a&lt;/code&gt; is limited to &lt;code&gt;block 1&lt;/code&gt; and &lt;code&gt;a&lt;/code&gt; is not recognized in &lt;code&gt;block 2&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Function Example&lt;/strong&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 fun1() {
 let a = 10;
 console.log(a);
} //function scope of fun1

function fun2() {
 a++;
 console.log(a);
} //function scope of fun2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Since we have enclosed fun1 and fun2, within separate functions, the scope of &lt;code&gt;let a=10&lt;/code&gt;, is limited to fun1 and "a" is not recognized in fun2.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  const:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;If a variable is defined with keyword const, it cannot be reassigned.&lt;/li&gt;
&lt;li&gt;If a variable is defined using the const keyword, its scope is limited to the block scope&lt;/li&gt;
&lt;li&gt;It is important to understand that const does NOT mean that the value is fixed and immutable.&lt;/li&gt;
&lt;li&gt;It CAN be mutated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&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 a = 10;
 console.log(a);
} //block 1
{
 a++;
 console.log(a);
} //block 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Since we are using &lt;code&gt;const a=10&lt;/code&gt;, scope of "a" is limited to block 1 and "a" is not recognized in block 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example to show that the value of the variable defined within the const keyword is mutable, i.e. it can be changed&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 const a = [1, 2, 3];
 const b = { name: "hello" };
 a.push(4, 5); //mutating the value of constant "a"
 b.name = "World"; //mutating the value of constant "b"

 console.log(a); //this will show [1,2,3,4,5]
 console.log(b); //this will show {name: "World"}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This code will run without any errors, and shows that we CAN mutate the values that are defined by "const"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Note that these variables defined by const cannot be re-assigned&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 const name = "Tech Talks";
 const PI = 3.14;
 const a = [1, 2, 3];
 const b = { name: "Hello" };
 name = "Ankit Kumar"; //Throws an error, since we are attempting to re-assign "name” to a different value.
 PI = PI + 1; //Throws an error, since we are attempting to re-assign PI to a different value.
 a = [1, 2, 3, 4, 5]; //Throws an error, since we are attempting to re-assign "a" to a different value.
 b = { name: "Hello Ankit" }; //Throws an error, since we are attempting to re-assign "b" to a different value.
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;h2&gt;
  
  
  var:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;function scoped&lt;/li&gt;
&lt;li&gt;undefined when accessing a variable before it's declared&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  let:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;block scoped&lt;/li&gt;
&lt;li&gt;ReferenceError when accessing a variable before it's declared&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  const:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;block scoped&lt;/li&gt;
&lt;li&gt;ReferenceError when accessing a variable before it's declared&lt;/li&gt;
&lt;li&gt;can't be reassigned&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/CodeWithAK_"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there.&lt;/p&gt;

&lt;p&gt;If you are Instagram person, follow me &lt;a href="https://www.instagram.com/code.with.ak"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>node</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Top 100 JavaScript Interview Questions and Answers - Part 2</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Fri, 19 Feb 2021 05:07:18 +0000</pubDate>
      <link>https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-2-4dc1</link>
      <guid>https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-2-4dc1</guid>
      <description>&lt;p&gt;We are going to learn JavaScript, by answering the most frequently asked javascript interview questions.&lt;/p&gt;




&lt;p&gt;JavaScript Interview Questions and Answers Series&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-1-443o" title="Published Feb 14"&gt;&lt;br&gt;
            &lt;span&gt;1&lt;/span&gt;&lt;br&gt;
            &lt;span&gt;Top 100 JavaScript Interview Questions and Answers - Part 1&lt;/span&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-2-4dc1" title="Published Feb 19"&gt;&lt;br&gt;
            &lt;span&gt;2&lt;/span&gt;&lt;br&gt;
            &lt;span&gt;Top 100 JavaScript Interview Questions and Answers - Part 2&lt;/span&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Welcome to &lt;strong&gt;Tech Talks&lt;/strong&gt; tutorial.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you guys want to practice for JavaScript Interview on mock video interview, please drop me an email at &lt;a href="//mailto:admin@ankitkumar.dev"&gt;admin@ankitkumar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Questions
&lt;/h2&gt;

&lt;p&gt;Question 22. How to remove duplicates from an array?&lt;/p&gt;

&lt;p&gt;Question 23. How to check if a value is an Array?&lt;/p&gt;

&lt;p&gt;Question 24. Implement the &lt;code&gt;Array.prototype.map()&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Question 25. Implement the &lt;code&gt;Array.prototype.filter()&lt;/code&gt; method&lt;/p&gt;

&lt;p&gt;Question 26. Implement the &lt;code&gt;Array.prototype.reduce()&lt;/code&gt; method&lt;/p&gt;

&lt;p&gt;Question 27. What is a &lt;code&gt;name function&lt;/code&gt; in JavaScript?&lt;/p&gt;

&lt;p&gt;Question 28. Can you assign an anonymous function to a variable and pass it as an argument to another function?&lt;/p&gt;

&lt;p&gt;Question 29. What is the &lt;code&gt;arguments object&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Question 30. Can you convert arguments object into an array?&lt;/p&gt;

&lt;p&gt;Question 31. Does arguments object work on ES6 arrow functions?&lt;/p&gt;

&lt;p&gt;Question 32. How to create an object without a prototype?&lt;/p&gt;

&lt;p&gt;Question 33. What are the scopes of a variable in JavaScript?&lt;/p&gt;

&lt;p&gt;Question 34. What is the purpose of &lt;code&gt;this&lt;/code&gt; in JavaScript?&lt;/p&gt;

&lt;p&gt;Question 35. What is &lt;code&gt;Callback&lt;/code&gt; in JavaScript?&lt;/p&gt;

&lt;p&gt;Question 36. How does &lt;code&gt;typeOf&lt;/code&gt; Operator work?&lt;/p&gt;

&lt;p&gt;Question 37. Explain &lt;code&gt;equality&lt;/code&gt; in JavaScript&lt;/p&gt;

&lt;p&gt;Question 38. What is the difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Question 39. What is &lt;code&gt;ECMAScript&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Question 40. What are the new features in &lt;code&gt;ES6&lt;/code&gt; or &lt;code&gt;ECMAScript 2015&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Question 41. What does &lt;code&gt;use strict&lt;/code&gt; do?&lt;/p&gt;



&lt;p&gt;&lt;em&gt;If you feel lazy to read more text, you can watch a video covering all questions here&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;YouTube: &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/3RM9Tp4PU00"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  22. How to remove duplicates from an array?
&lt;/h2&gt;

&lt;p&gt;There can be multiple ways of removing duplicates from an array, but let me tell three the most popular ways to do it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using Filter&lt;/strong&gt; -  It is possible to remove duplicates from an array in JavaScript by applying a filter to the same. To call the &lt;code&gt;filter()&lt;/code&gt; method, three arguments are required. These are namely array as &lt;code&gt;self&lt;/code&gt;, current element as &lt;code&gt;elem&lt;/code&gt;, and index of the current element as &lt;code&gt;index&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let language = ['JavaScript', 'Dart', 'Kotlin', 'Java', 'Swift', 'Dart']
function unique_array(arr) {
   let unique_array = arr.filter(function (elem, index, self) {
       return index == self.indexOf(elem);
   });
   return unique_array
}
console.log(unique_array(language));

// Logs [ 'JavaScript', 'Dart', 'Kotlin', 'Java', 'Swift' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using Loop&lt;/strong&gt; — In this method of removing duplicate elements from an array, an empty array is used for storing all the repeating
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let language = ['JavaScript', 'Dart', 'Kotlin', 'Java', 'Swift', 'Dart', 'JavaScript'];
function dups_array(language) {
   let unique = {};
   langugae.forEach(function (i) {
       if(!unique[i]) {
          unique[i] = true;
       }
   });
   return Object.keys(unique);
}
console.log(dups_array(language));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using Set&lt;/strong&gt; — This is the simplest approach of removing duplicate elements from an array in JS. A set is an inbuilt object for storing unique values in an array. Here’s how to use it for eliminating repeating elements from an array
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const set = new Set (['JavaScript', 'Dart', 'Kotlin', 'Java', 'Swift', 'Dart']);
function uniquearray() {
   let unique_array = Array.from(set);
   return unique_array;
}
console.log(uniquearray());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  23. How to check if a value is an Array?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can check if a value is an Array by using the Array.isArray() method available from the Array global object. &lt;/li&gt;
&lt;li&gt;It returns true when the parameter pass to it is an Array otherwise false.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Array.isArray(5));  //logs false
console.log(Array.isArray("")); //logs false
console.log(Array.isArray()); //logs false
console.log(Array.isArray(null)); //logs false
console.log(Array.isArray({ length: 5 })); //logs false
console.log(Array.isArray([])); //logs true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If your environment does not support this method you can use the polyfill implementation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isArray(value){
   return Object.prototype.toString.call(value) === "[object Array]"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  24. Implement the Array.prototype.map() method.
&lt;/h2&gt;

&lt;p&gt;As the MDN description of the &lt;code&gt;Array.prototype.map method&lt;/code&gt;, the &lt;code&gt;map()&lt;/code&gt; method creates a new array with the results of calling a provided function on every element in the calling array.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax of &lt;code&gt;map()&lt;/code&gt; method is
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newArray = arr.map(callback(currentValue[, index[, array]]) {
  // return element for newArray, after executing something
}[, thisArg]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And here is the implementation of it
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function map(arr, mapCallback) {
  // Check if the parameters passed are right.
  if (!Array.isArray(arr) || !arr.length || typeof mapCallback !== 'function') {
    return [];
    }
    else {
      let result = [];
      // Avoid mutating the original array.
      for (let i = 0, len = arr.length; i &amp;lt; len; i++) {
        result.push(mapCallback(arr[i], i, arr));
        // push the result of the mapCallback in the 'result' array
        }
        return result; // return the result array
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  25. Implement the Array.prototype.filter() method.
&lt;/h2&gt;

&lt;p&gt;As the MDN description of the Array.prototype.filter method, the &lt;code&gt;filter()&lt;/code&gt; method creates a new array with all elements that pass the test implemented by the provided function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax is
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newArray = arr.filter(callback(currentValue[, index[, array]]) {
  // return element for newArray, if true
}[, thisArg]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Implementations is
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function filter(arr, filterCallback) {
  // Check if the parameters passed are right.
  if (!Array.isArray(arr) || !arr.length || typeof filterCallback !== 'function') {
    return [];
    }
    else {
      let result = [];
      // Avoid mutating the original array.
      for (let i = 0, len = arr.length; i &amp;lt; len; i++) {
        // check if the return value of the filterCallback is true or "truthy"
        if (filterCallback(arr[i], i, arr)) {
        // push the current item in the 'result' array if the condition is true
        result.push(arr[i]);
      }
    }
    return result; // return the result array
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  26. Implement the Array.prototype.reduce() method.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;reduce()&lt;/code&gt; method executes a reducer function (that you provide) on each element of the array, resulting in single output value.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The reducer function takes four arguments:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Accumulator, Current Value, Current Index ,Source Array&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Syntax is&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr.reduce(callback( accumulator, currentValue, [, index[, array]] )[, initialValue])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function reduce(arr, reduceCallback, initialValue) {
  // Check if the parameters passed are right.
  if (!Array.isArray(arr) || !arr.length || typeof reduceCallback !== 'function'){
    return [];
  }
  else {
    // If no initialValue has been passed to the function we're gonna use the
    let hasInitialValue = initialValue !== undefined;
    let value = hasInitialValue ? initialValue : arr[0];
    // first array item as the initialValue, Start looping at index 1 if there is no
    // initialValue has been passed to the function else we start at 0 if there is an initialValue.
    for (let i = hasInitialValue ? 0 : 1, len = arr.length; i &amp;lt; len; i++) {
      // Then for every iteration we assign the result of the reduceCallback to the variable value.
      value = reduceCallback(value, arr[i], i, arr);
    }
    return value;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  27. What is a name function in JavaScript?
&lt;/h2&gt;

&lt;p&gt;A named function declares a name as soon as it is defined. It can be defined using function keyword as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function named() {
   // write code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  28. Can you assign an anonymous function to a variable and pass it as an argument to another function?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Yes! An anonymous function can be assigned to a variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can also be passed as an argument to another function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let show = function () {
  console.log('Anonymous function');
};
show();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  29. What is the arguments object?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The arguments object is a collection of parameter values pass in a function.&lt;/li&gt;
&lt;li&gt;It's an Array-like object because it has a length property and we can access individual values using array indexing notation arguments[1]&lt;/li&gt;
&lt;li&gt;But it does not have the built-in methods in an array forEach, reduce, filter and map.&lt;/li&gt;
&lt;li&gt;It helps us know the number of arguments pass in a function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  30. Can you convert arguments object into an array?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt;, We can convert the arguments object into an array using the Array.prototype.slice.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function one() {
   return Array.prototype.slice.call(arguments);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;However, if there is a need to &lt;code&gt;automatically&lt;/code&gt; execute a function at the place where it is given and not be called again, then &lt;code&gt;anonymous functions&lt;/code&gt; can be used.
Such functions have no name. So the name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  31. Does arguments object work on ES6 arrow functions?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;No&lt;/strong&gt;, the arguments object does not work on ES6 arrow functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function one() {
   return arguments;
}
const two = function () {
   return arguments;
}
const three = function three() {
   return arguments;
}
const four = () =&amp;gt; arguments;
four(); // Throws an error  - arguments is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we invoke the function four it throws a ReferenceError: arguments is not defined error.&lt;/p&gt;

&lt;p&gt;We can solve this problem if your environment supports the rest syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const four = (...args) =&amp;gt; args;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This puts all parameter values in an array automatically.&lt;/p&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  32. How to create an object without a prototype?
&lt;/h2&gt;

&lt;p&gt;We can create an object without a prototype using the &lt;code&gt;Object.create method&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;const o1 = {};
console.log(o1.toString());
// logs [object Object] get this method to the Object.prototype

const o2 = Object.create(null);
// the first parameter is the prototype of the object "o2" which in this case will be null specifying we don't want any prototype
console.log(o2.toString());
// throws an error o2.toString is not a function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  33. What are the scopes of a variable in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The scope of a variable is the region of your program in which it is defined.&lt;br&gt;
JavaScript variable will have only two scopes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global Variables&lt;/strong&gt; − A global variable has global scope which means it is visible everywhere in your JavaScript code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Variables&lt;/strong&gt; − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  34. What is the purpose of this in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The JavaScript this keyword refers to the object it belongs to.&lt;/p&gt;

&lt;p&gt;This has different values depending on where it is used.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a method, this refers to the owner object&lt;/li&gt;
&lt;li&gt;In a function, this refers to the global object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  35. What is Callback in JavaScript?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A callback is a plain JavaScript function passed to some method as an argument or option.&lt;/li&gt;
&lt;li&gt;It is a function that is to be executed after another function has finished executing, hence the name ‘callback’.&lt;/li&gt;
&lt;li&gt;In JavaScript, functions are objects, So functions can take functions as arguments, and can be returned by other functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  36. How does typeOf Operator work?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;typeof&lt;/code&gt; operator is used to get the data type of its operand.&lt;/li&gt;
&lt;li&gt;The operand can be either a literal or a data structure such as a variable, a function, or an object.&lt;/li&gt;
&lt;li&gt;It is a unary operator that is placed before its single operand, which can be of any type.&lt;/li&gt;
&lt;li&gt;Its value is a string indicating the data type of the operand.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  37. Explain equality in JavaScript.
&lt;/h2&gt;

&lt;p&gt;JavaScript has both strict and type–converting comparisons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strict comparison&lt;/strong&gt; (e.g., ===) checks for value equality without allowing coercion&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstract comparison&lt;/strong&gt; (e.g. ==) checks for value equality with coercion allowed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = "42";
var b = 42;
a == b; // true
a === b; // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some simple equality rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;If either value&lt;/code&gt; (aka side) in a comparison &lt;code&gt;could be the true or false&lt;/code&gt; value, &lt;code&gt;avoid == and use ===&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;If either value&lt;/code&gt; in a comparison could be of these specific values &lt;code&gt;(0, "", or [] -- empty array)&lt;/code&gt;, &lt;code&gt;avoid == and use ===&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In all other cases, you're safe to &lt;code&gt;use ==&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;Not only it is safe, but in many cases it simplifies your code in a way that improves readability.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  38. What is the difference between == and ===?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; is the abstract equality operator while === is the strict equality operator.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;==&lt;/code&gt; operator will compare for equality after doing any necessary type conversions.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;===&lt;/code&gt; operator will not do type conversion, so if two values are not the same type === will simply return false.&lt;/li&gt;
&lt;li&gt;When using &lt;code&gt;==&lt;/code&gt;, funky things can happen, such as:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 == "1"; // true
1 == [1]; // true
1 == true; // true
0 == ""; // true
0 == "0"; // true
0 == false; // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  39. What is ECMAScript?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ECMAScript is a standard for making scripting languages which means that JavaScript follows the specification changes in ECMAScript standard because it is the blueprint of JavaScript.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read more about ECMAScript &lt;a href="https://www.ecma-international.org/publications-and-standards/standards/ecma-262/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  40. What are the new features in ES6 or ECMAScript 2015?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arrow Functions&lt;/li&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Template Strings&lt;/li&gt;
&lt;li&gt;Enhanced Object literals&lt;/li&gt;
&lt;li&gt;Object Destructuring&lt;/li&gt;
&lt;li&gt;Promises&lt;/li&gt;
&lt;li&gt;Generators&lt;/li&gt;
&lt;li&gt;Modules&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;li&gt;Proxies&lt;/li&gt;
&lt;li&gt;Sets&lt;/li&gt;
&lt;li&gt;Default Function parameters&lt;/li&gt;
&lt;li&gt;Rest and Spread Operators&lt;/li&gt;
&lt;li&gt;Block Scoping with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  41. What does use strict do?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;use strict&lt;/code&gt; is a ES5 feature in JavaScript that makes our code in Strict Mode in functions or entire scripts.&lt;/li&gt;
&lt;li&gt;Strict Mode helps us avoid bugs early on in our code and adds restrictions to it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let look on restrictions that Strict Mode gives us.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assigning or Accessing a variable that is not declared.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function returnA() {
  "use strict";
  a = 3245;
  return a;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Assigning a value to a read-only or non-writable global variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use strict";
var NaN = NaN;
var undefined = undefined;
var Infinity = "and beyond";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deleting an undeletable property
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict";
const obj = {};
Object.defineProperty(obj, 'x', {
     value : '1'
}); 

delete obj.x;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Duplicate parameter names
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict";

function someFunc(a, b, b, c){

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Creating variables with the use of the eval function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict";

eval("var x = 1;");
console.log(x); //Throws a Reference Error x is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The default value of this will be undefined
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"use strict";

function showMeThis(){
 return this;
}
showMeThis(); //returns undefined

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

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;If you guys want to practice for JavaScript Interview on mock video interview, please drop me an email at &lt;a href="//mailto:admin@ankitkumar.dev"&gt;admin@ankitkumar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/why-flutter/" rel="noopener noreferrer"&gt;Top Flutter Advantages and Why You Should Try Flutter on Your Next Project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/react-native-deeplink-with-react-navigation/" rel="noopener noreferrer"&gt;How to implement deep linking in React Native app with React Navigation v5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/ArchitectAK" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--BSV4goFV--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_800%2Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzir1erzg7v28nvyuue09.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK" rel="noopener noreferrer"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/KumarrAnkitt" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there.&lt;/p&gt;

&lt;p&gt;Cheers!!! Happy coding!!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Top 100 JavaScript Interview Questions and Answers - Part 1</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Sun, 14 Feb 2021 05:17:52 +0000</pubDate>
      <link>https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-1-443o</link>
      <guid>https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-1-443o</guid>
      <description>&lt;p&gt;JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB, and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.&lt;/p&gt;

&lt;p&gt;We are going to learn JavaScript, by answering the most frequently asked javascript interview questions.&lt;/p&gt;




&lt;p&gt;JavaScript Interview Questions and Answers Series&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-1-443o" title="Published Feb 14"&gt;&lt;br&gt;
            &lt;span&gt;1&lt;/span&gt;&lt;br&gt;
            &lt;span&gt;Top 100 JavaScript Interview Questions and Answers - Part 1&lt;/span&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/letstechtalks/100-most-asked-javascript-interview-questions-and-answers-part-2-4dc1" title="Published Feb 19"&gt;&lt;br&gt;
            &lt;span&gt;2&lt;/span&gt;&lt;br&gt;
            &lt;span&gt;Top 100 JavaScript Interview Questions and Answers - Part 2&lt;/span&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Welcome to the &lt;strong&gt;Tech Talks&lt;/strong&gt; tutorial.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you guys want to practice for JavaScript Interview on mock video interview, please drop me an email at &lt;a href="//mailto:admin@ankitkumar.dev"&gt;admin@ankitkumar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Questions
&lt;/h2&gt;

&lt;p&gt;Question 1. What is &lt;code&gt;JavaScript&lt;/code&gt;?&lt;br&gt;
Question 2. What are the &lt;code&gt;primitive types&lt;/code&gt; in JavaScript?&lt;br&gt;
&lt;code&gt;or&lt;/code&gt;&lt;br&gt;
Explain the various JavaScript &lt;code&gt;data types&lt;/code&gt;?&lt;br&gt;
Question 3. What's the difference between &lt;code&gt;undefined&lt;/code&gt; and &lt;code&gt;null&lt;/code&gt; in JavaScript?&lt;br&gt;
Question 4. What are the escape characters in JavaScript?&lt;br&gt;
Question 5. What does the &lt;code&gt;Logical AND (&amp;amp;&amp;amp;)&lt;/code&gt; operator do?&lt;br&gt;
Question 6. What does the &lt;code&gt;Logical OR (||)&lt;/code&gt; operator do?&lt;br&gt;
Question 7. What is the fastest way to convert a string to a number?&lt;br&gt;
Question 8. What are the different types of Error Name values in JavaScript?&lt;br&gt;
Question 9. Please explain &lt;code&gt;Self Invoking Function&lt;/code&gt;&lt;br&gt;
Question 10. Explain difference between function declaration and function expression.&lt;br&gt;
Question 11. What is the DOM?&lt;br&gt;
Question 12. Please explain difference between &lt;code&gt;attributes&lt;/code&gt; and &lt;code&gt;property&lt;/code&gt;?&lt;br&gt;
Question 13. What are &lt;code&gt;cookies&lt;/code&gt;? How will you &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;read&lt;/code&gt;, and &lt;code&gt;delete&lt;/code&gt; a cookie using JavaScript?&lt;br&gt;
Question 14. What is &lt;code&gt;Event Propagation&lt;/code&gt;?&lt;br&gt;
Question 15. What is Event Bubbling?&lt;br&gt;
Question 16. What is Event Capturing?&lt;br&gt;
Question 17. Explain difference between &lt;code&gt;event.preventDefault()&lt;/code&gt; and &lt;code&gt;event.stopPropagation()&lt;/code&gt; methods?&lt;br&gt;
Question 18. How to know if the &lt;code&gt;event.preventDefault()&lt;/code&gt; method was used in an element?&lt;br&gt;
Question 19. What is Closure?&lt;br&gt;
Question 20. How many ways can you create an array in JavaScript?&lt;br&gt;
Question 21. How will you empty an array in JavaScript?&lt;/p&gt;



&lt;p&gt;&lt;em&gt;If you feel lazy to read more text, you can watch a video covering all questions here&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;YouTube: &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/kkKpgNNsB_8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  1. What is JavaScript?
&lt;/h2&gt;

&lt;p&gt;** High-level definition of JavaScript is:**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.&lt;/li&gt;
&lt;li&gt;JavaScript is the most popular web scripting language, used for both client-side and server-side development. &lt;/li&gt;
&lt;li&gt;Supporting object-oriented programming abilities.&lt;/li&gt;
&lt;li&gt;JavaScript code can be inserted into HTML pages that can be understood
and executed by web browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What are the primitive types in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The data types supported by JavaScript are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;li&gt;BigInt&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  3. What's the difference between undefined and null in JavaScript?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt; is the default value of&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a variable that has not been assigned a specific value.&lt;/li&gt;
&lt;li&gt;a function that has no explicit return value. for example
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(12);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;a property that does not exist in an object.
The JavaScript engine does this for us the assigning undefined values.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let _undefinedVar;
  const doNothing = () =&amp;gt; {};
  const someObj = {
    ab : “Tech Talks”,
    bc : “With AK”,
    cd : “Subscribe, Link in Bio”,
  };
  console.log(_undefinedVar); // undefined
  console.log(doNothing()); // undefined
  console.log(someObj[“d”]); // undefined

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;null&lt;/code&gt; is&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a value that represents no value.&lt;/li&gt;
&lt;li&gt;value that has been explicitly defined to a variable.&lt;/li&gt;
&lt;li&gt;Example we get a value of null when the fs.readFile method does not throw an error.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fs.readFile('path/to/file', (err,data) =&amp;gt; {
     console.log(e); //prints null when no error occurred
     if(e){
       console.log(e);
     }
     console.log(data);
   }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;comparing &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When comparing &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; we get &lt;code&gt;true&lt;/code&gt; when using &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; when using &lt;code&gt;===&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(null == undefined); // logs true
console.log(null === undefined); // logs false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What are the Escape Characters in JavaScript?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We use escape characters &lt;code&gt;backslash (\)&lt;/code&gt; while working with special characters, such as &lt;code&gt;ampersands (&amp;amp;)&lt;/code&gt;, &lt;code&gt;apostrophes (‘)&lt;/code&gt;, &lt;code&gt;double quotes (“ ”)&lt;/code&gt;, and &lt;code&gt;single quotes (‘ ’)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Whatever enclosed within the escape characters gets displayed by the JavaScript.&lt;/li&gt;
&lt;li&gt;Six additional escape characters are also available in JavaScript:

&lt;ul&gt;
&lt;li&gt;\b – Backspace&lt;/li&gt;
&lt;li&gt;\f – Form feed&lt;/li&gt;
&lt;li&gt;\n – Newline&lt;/li&gt;
&lt;li&gt;\r – Carriage return&lt;/li&gt;
&lt;li&gt;\t – Horizontal tabulator&lt;/li&gt;
&lt;li&gt;\v – Vertical tabulator&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;These aren’t in anyway executed in the HTML or JS code.&lt;/li&gt;

&lt;li&gt;These were originally designed for controlling fax machines, teletypes, and typewriters.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What does the Logical AND operator do?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;Logical AND&lt;/code&gt; operator finds the first false expression in its operands and returns it.&lt;/li&gt;
&lt;li&gt;If it does not find any false expression it returns the last expression.&lt;/li&gt;
&lt;li&gt;It employs short-circuiting to prevent unnecessary work.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   console.log(false &amp;amp;&amp;amp; 10 &amp;amp;&amp;amp; []); // false
   console.log(" " &amp;amp;&amp;amp; true &amp;amp;&amp;amp; 10); // 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What does the Logical OR operator do?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;||&lt;/code&gt; or &lt;code&gt;Logical OR&lt;/code&gt; operator finds the first truthy expression in its operands and returns it.&lt;/li&gt;
&lt;li&gt;This too employs short-circuiting to prevent unnecessary work.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(null || 10 || undefined); //prints 10

function printChannelName(name) {
  var n = name || "Tech Talks With AK";
  console.log(n);
}

printChannelName(); //prints "Tech Talks With AK"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  7. What is the fastest way to convert a string to a number?
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators#Unary_plus" rel="noopener noreferrer"&gt;MDN Documentation&lt;/a&gt; the &lt;code&gt;Unary Plus (+)&lt;/code&gt; is the fastest way of converting a string to a number because it does not perform any operations on the value if it is already a number.&lt;/p&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  8. What are the different types of Error Name values in JavaScript?
&lt;/h2&gt;

&lt;p&gt;There are 6 Error Name values in JavaScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Eval Error&lt;/strong&gt; – Thrown when coming across an error in eval() (Newer JS releases don’t have it)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Range Error&lt;/strong&gt; – Generated when a number outside the specified range is used&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reference Error&lt;/strong&gt; – It comes into play when an undeclared variable is used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Syntax Error&lt;/strong&gt; – When the incorrect syntax is used, we get this error&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type Error&lt;/strong&gt; – This error is thrown when a value outside the range of data types is tried to be used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;URI Error&lt;/strong&gt; – Generated due to the use of illegal characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Please explain Self Invoking Function.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions that are automatically invoked are termed as &lt;code&gt;Self Invoking Functions&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;These are also known as &lt;code&gt;Immediately Invoked Function Expressions&lt;/code&gt; and &lt;code&gt;Self Executing Anonymous Functions&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The general syntax of a &lt;code&gt;Self Invoking Function&lt;/code&gt; is:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// A function is defined and then invoked
(function_name () {
    return ()
}) ();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;However, if there is a need to &lt;code&gt;automatically&lt;/code&gt; execute a function at the place where it is given and not be called again, then &lt;code&gt;anonymous functions&lt;/code&gt; can be used.
Such functions have no name. So the name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Explain difference between function declaration and function expression.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;function declaration&lt;/code&gt; and &lt;code&gt;function expression&lt;/code&gt;&lt;/strong&gt; can be differentiated on the basis of&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Definition&lt;/li&gt;
&lt;li&gt;Strict Mode&lt;/li&gt;
&lt;li&gt;Time of Use&lt;/li&gt;
&lt;li&gt;When to Use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A function declared as a separate statement in the main code flow is termed the &lt;code&gt;function declaration&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When a function is created inside an expression or another syntax construct, it is called a &lt;code&gt;function expression&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Strict Mode&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a function declaration is &lt;code&gt;within a code block in the Strict mode&lt;/code&gt;, it is visible everywhere inside that block but not outside of it.&lt;/li&gt;
&lt;li&gt;This isn’t the case for a function expression.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Time of Use&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A function expression is created &lt;code&gt;when the execution reaches it&lt;/code&gt;. The function expression is usable from that moment onwards.&lt;/li&gt;
&lt;li&gt;A function declaration, on the other hand, &lt;code&gt;can be called before the same is defined&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to Use&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function declaration offers &lt;code&gt;better readability&lt;/code&gt; and offers &lt;code&gt;more freedom in organizing the code&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Function expressions are typically &lt;code&gt;restricted to be used when there is a need for a conditional declaration&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  11. What is the DOM?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;DOM stands for Document Object Model is an interface (API) for HTML and XML documents.&lt;/li&gt;
&lt;li&gt;When the browser first reads (parses) HTML document it creates a big object, a really big object based on the HTML document this is the DOM.&lt;/li&gt;
&lt;li&gt;It is a tree-like structure that is modeled from the HTML document.&lt;/li&gt;
&lt;li&gt;The DOM is used for interacting and modifying the DOM structure or specific Elements or Nodes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
   &amp;lt;meta charset="UTF-8"&amp;gt;
   &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
   &amp;lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&amp;gt;
   &amp;lt;title&amp;gt;Document Object Model&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
   &amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt;
        &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;/p&amp;gt;
    &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
    &amp;lt;input&amp;gt;   // other elements
   &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The graphical representation of the DOM of the code above looks like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2FJSQuestion%2Fdom.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2FJSQuestion%2Fdom.png" alt="Alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The document object in JavaScript represents the DOM.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It provides us many methods that we can use to selecting elements to update element contents and many more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript can change all the HTML elements in the page&lt;/li&gt;
&lt;li&gt;JavaScript can change all the HTML attributes in the page&lt;/li&gt;
&lt;li&gt;JavaScript can change all the CSS styles in the page&lt;/li&gt;
&lt;li&gt;JavaScript can remove existing HTML elements and attributes&lt;/li&gt;
&lt;li&gt;JavaScript can add new HTML elements and attributes&lt;/li&gt;
&lt;li&gt;JavaScript can react to all existing HTML events in the page&lt;/li&gt;
&lt;li&gt;JavaScript can create new HTML events in the page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Please explain difference between attributes and property?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;JS DOM objects have properties that are like instance variables for particular elements.&lt;/li&gt;
&lt;li&gt;A property can be of various data types.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Properties are accessible by interacting with the object in Vanilla JS or using jQuery’s prop() method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rather than in the DOM, attributes are in the HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are similar to properties but not as capable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s recommended to work with properties rather than attributes if the former is available. Unlike a property, an attribute is of the string data type&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  13. What are cookies? How will you create, read, and delete a cookie using JavaScript?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A cookie is simply data, usually small, sent from a website and stored on the user’s computer by the web browser used to access the website.&lt;/li&gt;
&lt;li&gt;It is a reliable way for websites to remember stateful information and record the user's browsing activity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Creating a Cookie:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most basic way of creating a cookie using JS is to assign a string value to the document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.cookie = “key1 = value1; key2 = value2; … ; keyN= valueN; expires = date”;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reading a Cookie:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading a cookie using JS is as simple as creating.&lt;/li&gt;
&lt;li&gt;Cookie object is the cookie, use this string whenever you wish to access the cookie.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;document.cookie&lt;/code&gt; string keeps a list of &lt;code&gt;name = value&lt;/code&gt; pairs, where a &lt;code&gt;semicolon separates each pair&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;name&lt;/code&gt; represents a cookie's name, and the &lt;code&gt;value&lt;/code&gt; represents the respective cookie’s string value.&lt;/li&gt;
&lt;li&gt;For breaking the string into key and value, you can use the &lt;code&gt;split()&lt;/code&gt; method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Deleting a Cookie:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simply &lt;code&gt;setting the expiration date&lt;/code&gt; (expires) to a time that’s already passed.&lt;/li&gt;
&lt;li&gt;Some web browsers don’t let you delete a cookie unless you don’t specify the cookie's path.&lt;/li&gt;
&lt;li&gt;Hence, defining the &lt;code&gt;cookie path&lt;/code&gt; is important to ensure that the right cookie is &lt;code&gt;deleted.assign&lt;/code&gt; a string value to the document.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  14. What is Event Propagation?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When an event occurs on a DOM element, that event does not entirely occur on that just one element.&lt;/li&gt;
&lt;li&gt;In the Bubbling Phase, the event bubbles up or it goes to its parent, to its grandparents, to its grandparent's parent until it reaches all the way to the window while in the Capturing Phase the event starts from the window down to the element that triggered the event or the event.target.&lt;/li&gt;
&lt;li&gt;This process is called Event Propagation.&lt;/li&gt;
&lt;li&gt;It has 3 phases.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Capturing Phase&lt;/code&gt; – The event starts from the window then goes down to every element until it reaches the target element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Target Phase&lt;/code&gt; – The event has reached the target element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Bubbling Phase&lt;/code&gt; – The event bubbles up from the target element then goes up every element until it reaches the window.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/..%2F..%2Fassets%2Fimages%2Fpost%2FJSQuestion%2Fevent.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/..%2F..%2Fassets%2Fimages%2Fpost%2FJSQuestion%2Fevent.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  15. What is Event Bubbling?
&lt;/h2&gt;

&lt;p&gt;When an event occurs on a DOM element, that event does not entirely occur on that just one element.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;Bubbling Phase&lt;/code&gt;, the event bubbles up or it goes to its parent, to its grandparents, to its grandparent's parent until it reaches all the way to the window.&lt;/p&gt;

&lt;p&gt;If we have an example markup like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="grandparent"&amp;gt;
    &amp;lt;div class="parent"&amp;gt;
          &amp;lt;div class="child"&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;And javascript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addEvent(el, event, callback, isCapture = false) {
       if (!el || !event || !callback || typeof callback !== 'function') return;
       if (typeof el === 'string') {
        el = document.querySelector(el);
       }; 
       el.addEventListener(event, callback, isCapture);
}
addEvent(document, 'DOMContentLoaded', () =&amp;gt; {

       const child = document.querySelector('.child');
       const parent = document.querySelector('.parent');
       const grandparent = document.querySelector('.grandparent');

     addEvent(child, 'click', function (e) {
    console.log('child');
       });
      addEvent(parent, 'click', function (e) {
    console.log('parent');
      });
     addEvent(grandparent, 'click', function (e) {
    console.log('grandparent');
     });
     addEvent(document, 'click', function (e) {
    console.log('document');
     });
     addEvent('html', 'click', function (e) {
    console.log('html');
     });
     addEvent(window, 'click', function (e) {
    console.log('window');
     });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;addEventListener()&lt;/code&gt; method has a third optional parameter useCapture with a default value of false the event will occur in the &lt;code&gt;Bubbling phase&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;useCapture&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, the event will occur in the &lt;code&gt;Capturing Phase&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If we click on the child element it logs &lt;code&gt;child, parent, grandparent, html, document and window&lt;/code&gt; respectively on the console.&lt;/li&gt;
&lt;li&gt;This whole event is Event Bubbling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  16. What is Event Capturing?
&lt;/h2&gt;

&lt;p&gt;When an event occurs on a DOM element, that event does not entirely occur on that just one element.&lt;br&gt;
In Capturing Phase, the event starts from the window all the way down to the element that triggered the event.&lt;/p&gt;

&lt;p&gt;If we have an example markup like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="grandparent"&amp;gt;
    &amp;lt;div class="parent"&amp;gt;
          &amp;lt;div class="child"&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And javascript code is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addEvent(el, event, callback, isCapture = false) {
     if (!el || !event || !callback || typeof callback !== 'function') return;
     if (typeof el === 'string') {
    el = document.querySelector(el);
     };
     el.addEventListener(event, callback, isCapture);
}
addEvent(document, 'DOMContentLoaded', () =&amp;gt; {
     const child = document.querySelector('.child');
     const parent = document.querySelector('.parent');
     const grandparent = document.querySelector('.grandparent');

     addEvent(child, 'click', function (e) {
    console.log('child');
     }, true);
     addEvent(parent, 'click', function (e) {
    console.log('parent');
     }, true);
  addEvent(grandparent, 'click', function (e) {
    console.log('grandparent');
  }, true);

  addEvent(document, 'click', function (e) {
    console.log('document');
  }, true);

  addEvent('html', 'click', function (e) {
    console.log('html');
  }, true)

  addEvent(window, 'click', function (e) {
    console.log('window');
  }, true)

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;addEventListener()&lt;/code&gt; method has a third optional parameter useCapture with a default value of false the event will occur in the &lt;code&gt;Bubbling phase&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;useCapture&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, the event will occur in the &lt;code&gt;Capturing Phase&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If we click on the child element it logs &lt;code&gt;window, document, html, grandparent, parent and child&lt;/code&gt; respectively on the console.&lt;/li&gt;
&lt;li&gt;This is Event Capturing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  17. Explain difference between event.preventDefault() and event.stopPropagation() methods?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The event.preventDefault() method prevents the default behavior of an element.&lt;/li&gt;
&lt;li&gt;If used in a form element it prevents it from submitting.&lt;/li&gt;
&lt;li&gt;If used in an anchor element it prevents it from navigating.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If used in a context menu it prevents it from showing or displaying.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While the event.stopPropagation() method stops the propagation of an event.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It stops the event from occurring in the bubbling or capturing phase.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  18. How to know if the event.preventDefault() method was used in an element?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can use the event.defaultPrevented property in the event object.&lt;/li&gt;
&lt;li&gt;It returns a boolean indicating if the event.preventDefault() was called in a particular element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  19. What is Closure?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Closures&lt;/code&gt; are created whenever a variable, defined outside the current scope, is accessed from within some inner scope.&lt;/li&gt;
&lt;li&gt;It gives us access to an outer function’s scope from an inner function.&lt;/li&gt;
&lt;li&gt;In other words, a closure is a locally declared variable that is related to a function and stays in the memory when the related function has returned.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The closure contains all local variables that were in-scope at the time of the closure creation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In JavaScript, closures are created every time a function is created.&lt;br&gt;
To use a closure, simply define a function inside another function and expose it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Without Closure
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(message) {
  console.log(message);
}
function greeter(name, number) {
  return name + " says Hey!! He has " + age + " subscribers";
}
var message = greeter("Tech Talks", 1026);
greet(message);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;With Closure
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greeter(name, age) {
  var message = name + " says Hey!! He has " + age + " subscribers";
  return function greet() {
    console.log(message);
  };
}
// Generate the closure
var TechTalksGreeter = greeter("Tech Talks", 1026);
// Use the closure
TechTalksGreeter();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  20. How many ways can you create an array in JavaScript?
&lt;/h2&gt;

&lt;p&gt;There are three different ways of creating an array in JavaScript, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By creating an instance of an array:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var someArray = new Array();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  By array constructor:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var someArray = new Array(‘value1’, ‘value2’,…, ‘valueN’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;By using an array literal:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var someArray = [value1, value2,…., valueN];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;

&lt;h2&gt;
  
  
  21. How will you empty an array in JavaScript?
&lt;/h2&gt;

&lt;p&gt;There are four ways to empty an array in JavaScript&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By assigning an empty array:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var array1 = [1, 22, 24, 46];
array1 = [ ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;By assigning array length to 0:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var array1 = [1, 22, 24, 46];
array1.length=0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;By popping the elements of the array:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var array1 = [1, 22, 24, 46];
while(array1.length &amp;gt; 0) {
array1.pop();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;By using the splice array function:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var array1 = [1, 22, 24, 46];
array1.splice(0, array1.length)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Top ↑&lt;/p&gt;




&lt;p&gt;Originally posted on &lt;a href="https://ankitkumar.dev/100-JS-interview-question-part1/" rel="noopener noreferrer"&gt;AnkitKumar.Dev&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you guys want to practice for JavaScript Interview on mock video interview, please drop me an email at &lt;a href="//mailto:admin@ankitkumar.dev"&gt;admin@ankitkumar.dev&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/why-flutter/" rel="noopener noreferrer"&gt;Top Flutter Advantages and Why You Should Try Flutter on Your Next Project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/react-native-deeplink-with-react-navigation/" rel="noopener noreferrer"&gt;How to implement deep linking in React Native app with React Navigation v5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksWithAK" rel="noopener noreferrer"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/KumarrAnkitt" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there.&lt;/p&gt;

&lt;p&gt;Cheers!!! Happy coding!!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Why Flutter loves Dart</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 20 Jan 2021 05:39:04 +0000</pubDate>
      <link>https://dev.to/letstechtalks/why-flutter-loves-dart-3gn7</link>
      <guid>https://dev.to/letstechtalks/why-flutter-loves-dart-3gn7</guid>
      <description>&lt;p&gt;Dart is a simple and powerful language, which is, in its nature, complies to be efficient with everybody’s own javascript.&lt;/p&gt;




&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What Is Dart?&lt;/li&gt;
&lt;li&gt;Why Flutter uses Dart?&lt;/li&gt;
&lt;li&gt;How Dart enables developers to develop a Flutter app quickly and deploy it to multiple platforms?&lt;/li&gt;
&lt;li&gt;Dart SDK - Libraries, Tools, Dart VM, Dart Compiler to JS&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;&lt;strong&gt;Dart&lt;/strong&gt; is a&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;client-optimized&lt;/code&gt; programming language for fast apps on any platform,&lt;/li&gt;
&lt;li&gt;After lots of experiments, the Google team found dart to be &lt;code&gt;faster&lt;/code&gt;, &lt;code&gt;smoother&lt;/code&gt;, and &lt;code&gt;pretty efficient&lt;/code&gt; to be used for developing applications, including client-side and also server-side applications&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Object oriented&lt;/code&gt; &amp;amp; &lt;code&gt;Class defined&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C Styled syntax&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What makes Dart so versatile?
&lt;/h2&gt;

&lt;p&gt;What makes Dart so versatile is the fact that it compiles to its own format but also trans-compiles into javascript, which is readable by most of the devices today.&lt;/p&gt;

&lt;p&gt;So Dart can be used cross-platform mobile applications, web applications using Angular Dart, and command-line applications or server-side applications&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you feel lazy to read more text, you can watch a video on the topic below&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;YouTube: &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4PstaG3YdRs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Dart? / Why Flutter uses Dart? / Why Flutter loves Dart?
&lt;/h3&gt;

&lt;p&gt;In today's world, you need to build from many platforms to reach all your users, while maintaining quality to keep them happy.&lt;br&gt;
Flutter enables you to ship an application for Android, iOS,&lt;br&gt;
and the web from a single codebase. To do this, Flutter needs a programming language that works on all these platforms and gives you a fast development experience.&lt;/p&gt;

&lt;p&gt;That's why Flutter chose Dart.&lt;/p&gt;
&lt;h2&gt;
  
  
  How Dart enables developers to develop a Flutter app quickly and deploy it to multiple platforms?
&lt;/h2&gt;

&lt;p&gt;If you're developing for mobile, you might be used to slow compile and debug cycles.&lt;/p&gt;

&lt;p&gt;Dart changes this by enabling one of Flutter's most loved features, &lt;code&gt;hot reload&lt;/code&gt;, which injects updated Dart source code into your running app and rebuilds your UI in less than a second, so you can see your changes instantly.&lt;/p&gt;

&lt;p&gt;To have high-quality experiences of apps on both platforms, traditionally, you might have worked in separate teams to build performant apps for each platform. Dart enables you to build high fidelity Flutter apps for all platforms with one team.&lt;/p&gt;

&lt;p&gt;Dart's production quality compilers compile to ARM and x64 machine code for mobile or optimized JavaScript for the web, enabling quick app startup times and smooth animations.&lt;/p&gt;

&lt;p&gt;Finally, Dart is easy to learn.&lt;/p&gt;

&lt;p&gt;You'll pick up Dart quickly if you're familiar with languages such as Java, Swift, and JavaScript.&lt;/p&gt;

&lt;p&gt;Together, Dart and Flutter help you create amazing experiences across Android, iOS, and the web.&lt;/p&gt;

&lt;p&gt;Try Dart in your browser today at &lt;a href="https://dart.dev/#try-dart"&gt;dart.dev&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Dart is not just a programming language
&lt;/h2&gt;

&lt;p&gt;Dart holds much more than that, It includes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Libraries&lt;/li&gt;
&lt;li&gt;Tools&lt;/li&gt;
&lt;li&gt;A standalone Dart VM&lt;/li&gt;
&lt;li&gt;Compilers to JS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One does not need anything extra to support it, it includes all in one in its SDK.&lt;/p&gt;

&lt;p&gt;Dart VM allows code to run in CLI env as language tools included in the Dart SDK are written mostly in Dart itself.&lt;/p&gt;

&lt;p&gt;The standalone Dart VM is the critical part of Dart SDK.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you feel lazy to read more text, you can watch a video on the topic below&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;YouTube: &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FODGHk6ZIhU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Libraries
&lt;/h4&gt;

&lt;p&gt;Dart Ships with the complete standard libraries, allowing developers to write fully functional system apps such as &lt;code&gt;custom web servers, custom mobile apps&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some of the default libraries provided by Dart are, but other third-party libraries are available too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dart:core&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides a small but critical set of built-in complete functionality to dart&lt;/li&gt;
&lt;li&gt;Built-in types, collections, and other core functionality.&lt;/li&gt;
&lt;li&gt;This library is automatically imported into every Dart program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:async&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Support for asynchronous programming with callbacks&lt;/li&gt;
&lt;li&gt;Dart also provides other options for asynchronous programming by the support of classes such as Future and Stream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:math&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides common mathematical and trigonometry functionality within darts such as sine and cosine&lt;/li&gt;
&lt;li&gt;Mathematical constants and functions, plus a random number generator.&lt;/li&gt;
&lt;li&gt;Most of the functionality in the math library is implemented as a top-level function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:convert&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encoders and decoders for converting between different data representations, including JSON and UTF-8.&lt;/li&gt;
&lt;li&gt;As well as support for additional customized converters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:html&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOM and other APIs for browser-based apps.&lt;/li&gt;
&lt;li&gt;Allows manipulation of OBJECT and DOM&lt;/li&gt;
&lt;li&gt;Give access to HTML5 APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:io&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I/O for programs that can use the Dart VM, including Flutter apps, servers, and command-line scripts.&lt;/li&gt;
&lt;li&gt;Provides the support to deal with files, directories, processes, sockets and WebSockets and HTTP Clients and Servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;dart:ui&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exposes the lowest-level services that Flutter use to bootstrap the application&lt;/li&gt;
&lt;li&gt;Such as classes for driving the input, graphic text, layouts, and rendering subsystems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Tools
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Dart SDK&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dart SDK is a necessity for web developers, Script developers as well as Server-Side Developers.&lt;/li&gt;
&lt;li&gt;For Mobile Developers dart comes as a package within Flutter SDK.&lt;/li&gt;
&lt;li&gt;It means setting up Flutter SDK is good enough to start with Dart for Mobile Development.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IDEs and Code Editor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android Studio, VS Code, and IntelliJ idea - officially supported&lt;/li&gt;
&lt;li&gt;Atom, Vim, and Emacs are not supported officially by the Dart team but open-source plugins are available &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dart Pad&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Online dart compiler which allows us to play around with dart without installing any dependency,&lt;/li&gt;
&lt;li&gt;The link is in the description below, so please go ahead and check it out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;CLI Tools&lt;/strong&gt; - There are also certain command-line tools in DART&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. Pub Package Manager&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A package manager that makes it easy for you to install, use, and share Dart libraries, command-line tools, and other assets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;2. Dartanalyzer&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A static analyzer that evaluates and reports any errors or warnings in your code.&lt;/li&gt;
&lt;li&gt;The Dart plugin for your IDE should make use of Dart’s analysis engine, but you can also run the analyzer from the command line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;3. Dartdoc&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A documentation generator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;4. Dartfmt&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An opinionated code formater that follows the recommendations of the Dart style guide&lt;/li&gt;
&lt;li&gt;IDEs that support Dart generally allow you to format the code within the IDE.&lt;/li&gt;
&lt;li&gt;Or you can run the formater from the command line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;5. Build Runner&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A building package that’s used behind-the-scenes by the web dev command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;6. Dartfix&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A tool for migrating Dart source code and fixing common issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Debugging Tools&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. Dart DevTools&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A suite of debugging and performance tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Dart VM
&lt;/h4&gt;

&lt;p&gt;To run command-line apps, such as server-side scripts, programs, and servers, Dart VM borrows many Ideas from JavaScript VM used by Chrome called V8. But browsers actively rejected it, the reasons being size and concern similar to Javascript VM.&lt;/p&gt;

&lt;p&gt;It is important to know that DART VM works in the background during the process of application building.&lt;/p&gt;

&lt;p&gt;It runs in 2 basics forms&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JIT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which is an acronym for Just In Time.&lt;/li&gt;
&lt;li&gt;It is a mode that is used for dynamically loading dart source, parsing it, and compiling it to native machine code on the fly to execute this.&lt;/li&gt;
&lt;li&gt;This mode is used when you develop your app&lt;/li&gt;
&lt;li&gt;It provides features such as debugging, hot reload, etc&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;AOT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which is an acronym for Ahead Of Time&lt;/li&gt;
&lt;li&gt;It is the mode used to support loading and executing pre-compiled machine code&lt;/li&gt;
&lt;li&gt;It does not support dynamic loading, parsing, or compilation&lt;/li&gt;
&lt;li&gt;It is mainly used in deployed applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dart VM is included in Dart SDK itself&lt;/p&gt;

&lt;p&gt;It also includes observatory options like enable assert which is an assert statement that checks a boolean condition and raises an exception if the condition is false.&lt;/p&gt;

&lt;p&gt;An important point to note about dart VM is that it can not be used for mobile applications or web applications &lt;/p&gt;

&lt;h4&gt;
  
  
  Compiler to JavaScript
&lt;/h4&gt;

&lt;p&gt;Dart code is compiled into javascript using DART2JS or DARTDEVC compiler which are already included in DART&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dart2js&lt;/strong&gt; - User can compiled dart file by converting into javascript file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dartdevc&lt;/strong&gt; - let you run and debug your web app in any modern browser&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And it is for in development by dart&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note that the DartDevC compiler is only for the development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And dart2js is used only for deployment &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Originally posted on &lt;a href="https://ankitkumar.dev/why-flutter-loves-dart"&gt;AnkitKumar.Dev&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/why-flutter/"&gt;Top Flutter Advantages and Why You Should Try Flutter on Your Next Project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/react-native-deeplink-with-react-navigation/"&gt;How to implement deep linking in React Native app with React Navigation v5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TechTalksByAnkitKumar"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/KumarrAnkitt"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there&lt;/p&gt;

&lt;p&gt;Cheers!!! Happy coding!!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>mobile</category>
      <category>programming</category>
    </item>
    <item>
      <title>Top Flutter Advantages and Why You Should Try Flutter on Your Next Project</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 06 Jan 2021 06:53:14 +0000</pubDate>
      <link>https://dev.to/letstechtalks/top-flutter-advantages-and-why-you-should-try-flutter-on-your-next-project-2n3k</link>
      <guid>https://dev.to/letstechtalks/top-flutter-advantages-and-why-you-should-try-flutter-on-your-next-project-2n3k</guid>
      <description>&lt;p&gt;Flutter is Google’s UI toolkit for building beautiful, native applications from a single codebase for&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mobile&lt;/strong&gt; - Android and iOS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Desktop&lt;/strong&gt; - macOS, Chromebook, Windows, and Linux&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Web&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What Is Flutter?&lt;/li&gt;
&lt;li&gt;More than 15 points of Why to use Flutter&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What is Flutter?
&lt;/h3&gt;

&lt;p&gt;It belongs to the category of cross-platform development frameworks and tools that allows developers to build and compile native apps for&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android and iOS mobiles,&lt;/li&gt;
&lt;li&gt;Desktops including macOS, Chromebook, Windows, and Linux machines&lt;/li&gt;
&lt;li&gt;Web&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of this happens from a single code base.&lt;/p&gt;

&lt;p&gt;So we can say that Flutter is a Write once and run anywhere framework for developers.&lt;/p&gt;

&lt;p&gt;If you feel lazy to read more text, you can watch a video on the topic below&lt;/p&gt;

&lt;p&gt;YouTube: &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/a-EcD1AKRag"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Flutter? Let's understand it with more than 15 points
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Integration of Flutter with existing Android and iOS apps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s sometimes not practical to rewrite your entire application in Flutter all at once. For those situations, Flutter can be integrated into your existing application piecemeal, as a library or module. That module can then be imported into your Android or iOS (currently supported platforms) app to render a part of your app’s UI in Flutter. Or, just to run shared Dart logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Flutter can be developed on multiple IDEs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Including the Android Studio which is backed by JetBrains which build the worlds’ best IDE such as IntelliJ, WebStorm, PyCharm, and many more.&lt;/li&gt;
&lt;li&gt;It works perfectly on the VS Code, and those who are not coming from Android Native development, can use the VS Code as the IDE.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Flutter has whole suites of web-based tooling of debugging and inspecting Flutter applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are some of the things you can do with DevTools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inspect the UI layout and state of a Flutter app.&lt;/li&gt;
&lt;li&gt;Diagnose UI jank performance issues in a Flutter app.&lt;/li&gt;
&lt;li&gt;CPU profiling for a Flutter or Dart app.&lt;/li&gt;
&lt;li&gt;Network profiling for a Flutter app.&lt;/li&gt;
&lt;li&gt;Source-level debugging of a Flutter or Dart app.&lt;/li&gt;
&lt;li&gt;Debug memory issues in a Flutter or Dart command-line app.&lt;/li&gt;
&lt;li&gt;View general log and diagnostics information about a running Flutter or Dart command-line app.&lt;/li&gt;
&lt;li&gt;Analyze code and app size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Dart is the programming language for Flutter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because it is optimized for Client development with HOT RELOAD, powered by the DART VM so that developers can iteratively make changes and instantly see changes or results in the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Dart compiles to native machine code for mobile and desktop, as well as to JavaScript for the web&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whether you’re creating a &lt;code&gt;mobile app&lt;/code&gt;, &lt;code&gt;web app&lt;/code&gt;, &lt;code&gt;command-line script&lt;/code&gt;, or &lt;code&gt;server-side app&lt;/code&gt;, there’s a Dart solution for that.&lt;/p&gt;

&lt;p&gt;Flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dart Native:&lt;/strong&gt; For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with &lt;code&gt;JIT (just-in-time)&lt;/code&gt; compilation and an &lt;code&gt;AOT (ahead-of-time)&lt;/code&gt; compiler for producing machine code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dart Web:&lt;/strong&gt; For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Dart and Flutter has conditional UI features that help developers to render UI based on conditions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A flutter package that enhances conditional rendering supports &lt;code&gt;if-else&lt;/code&gt; and &lt;code&gt;switch&lt;/code&gt; conditions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;if-else&lt;/code&gt; example
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: &amp;lt;Widget&amp;gt;[
        Conditional.single(
          context: context,
          conditionBuilder: (BuildContext context) =&amp;gt; someCondition == true,
          widgetBuilder: (BuildContext context) =&amp;gt; Text('The condition is true!'),
          fallbackBuilder: (BuildContext context) =&amp;gt; Text('The condition is false!'),
        ),
      ],
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;switch&lt;/code&gt; example
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: &amp;lt;Widget&amp;gt;[
        ConditionalSwitch.single&amp;lt;String&amp;gt;(
          context: context,
          valueBuilder: (BuildContext context) =&amp;gt; 'A',
          caseBuilders: {
            'A': (BuildContext context) =&amp;gt; Text('The value is A!'),
            'B': (BuildContext context) =&amp;gt; Text('The value is B!'),
          },
          fallbackBuilder: (BuildContext context) =&amp;gt; Text('None of the cases matched!'),
        ),
      ],
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Compiled code of Flutter is faster than others and it increases performance by 15% for many cases&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flutter is fast. It's powered by the same hardware-accelerated 2D graphics library that underpins Chrome and Android: Skia.&lt;/p&gt;

&lt;p&gt;Flutter is architectured to support glitch-free, jank-free graphics at the native speed of your device.&lt;/p&gt;

&lt;p&gt;Flutter code is powered by the world-class Dart platform, which enables compilation to 32-bit and 64-bit ARM machine code for iOS and Android, as well as JavaScript for the web and Intel x64 for desktop devices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Flutter is an open-source product&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open Source Community is the major source of feedback, documentation, and code contributions.&lt;/p&gt;

&lt;p&gt;Flutter on &lt;a href="https://github.com/flutter/flutter" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Fastest growing skill among software engineers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And Linked data says that Flutter is the fastest-growing skill among software engineers.&lt;/p&gt;

&lt;p&gt;Read more about it &lt;a href="https://www.linkedin.com/business/learning/blog/productivity-tips/the-fastest-growing-skills-among-software-engineers-and-how-to" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Shared UI and Business logic for all platforms&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To illustrate, here’s an example of how UI rendering looks like in most cross-platform frameworks:&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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fui-elements.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fui-elements.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This kind of rendering process makes building an app that looks native on every platform simple. But the devil’s in the details.&lt;br&gt;
Relying on platform-specific components for rendering provokes a need for a property mapping layer for the platform widget and a framework widget data synchronization. That’s what requires mapping every animation into a platform-specific widget call. So much more complicated than it needs to be, right?&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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fflutter-canvas.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fflutter-canvas.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In contrast, Flutter doesn’t need any platform-specific UI components to render it’s UI. The only thing Flutter needs to show the application UI is a canvas to draw onto. And here’s how it looks like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Reduced Code Development Time&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flutter offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting your app or losing its state.&lt;/li&gt;
&lt;li&gt;Wide variety of ready-to-use widgets&lt;/li&gt;
&lt;li&gt;In addition to numerous core layout widgets, Flutter provides a large set of Material and Cupertino widgets that perfectly mimic the behavior of each design language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;12. Native App Performance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Application performance is crucial for good UX. While it’s hard to tell the exact figures, it’s safe to say that Flutter application performance in most cases will be indistinguishable from the native app and even better in complex UI animation scenarios.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Contrary to the approach of most cross-platform frameworks, Flutter doesn’t rely on any intermediate code representations or interpretation.&lt;/p&gt;

&lt;p&gt;Flutter application is built directly into the machine code, which eliminates any performance bugs of the interpretation process.&lt;/p&gt;

&lt;p&gt;Eventually, you get your release application fully compiled ahead of time with Flutter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Custom, Animated UI of Any Complexity Available&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the biggest advantages of Flutter is the ability to customize anything you see on the screen, regardless of how complex it may be.&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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fcomplex-ui.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fcomplex-ui.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flutter makes the process more flexible and versatile without adding to the workload. Shared element transitions, shape/color/shadow manipulations, clipping, transformations – Flutter allows you to perform all of these effortlessly&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Own Rendering Engine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flutter uses Skia for rendering itself onto a platform-provided canvas. Because of the engine, UI built-in Flutter can be launched on virtually any platform.&lt;/p&gt;

&lt;p&gt;Putting it differently, you no longer have to adjust UI to transfer it to a platform, which simplifies the development process hugely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. Simple Platform-Specific Logic Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Besides the UI, many real-life mobile applications rely on advanced OS-level features, such as fetching GPS coordinates, Bluetooth communication, gathering sensor data, permission handling, working with credentials, etc.&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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fplatform-specific.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fplatform-specific.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Many of these are available when developing a Flutter application through a ready-to-use plugin supported by Google.&lt;br&gt;
Flutter provides an easy to use way of establishing the communication between platform-native code and Dart through platform channels. This way, you can implement anything that a native app can do on a Flutter app, with just a little extra effort on the native side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;16 The Potential Ability to Go Beyond Mobile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Flutter, you can go far beyond Flutter app development on mobile.&lt;br&gt;
There’s also Flutter for Web and Flutter Desktop Embeddings now.&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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fall-platforms.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%2Fankitkumar.dev%2Fassets%2Fimages%2Fpost%2Fflutter%2Fall-platforms.png"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Originally posted on &lt;a href="https://ankitkumar.dev/why-flutter/" rel="noopener noreferrer"&gt;https://ankitkumar.dev&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ankitkumar.dev/react-native-deeplink-with-react-navigation/" rel="noopener noreferrer"&gt;How to implement deep linking in React Native app with React Navigation v5&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Also, to be notified about my new articles and stories:&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/TECHTALKSWITHAK" rel="noopener noreferrer"&gt;YouTube Channel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://ankitdeveloper.medium.com/" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;, &lt;a href="https://github.com/AnkitDroidGit" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, and &lt;a href="https://twitter.com/KumarrAnkitt" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/kumarankitkumar/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;I am quite active on &lt;a href="https://dev.to/ankitkumar"&gt;Dev Community&lt;/a&gt; as well and write small topics over there.&lt;/p&gt;

&lt;p&gt;Cheers!!! Happy coding!!&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>mobile</category>
      <category>programming</category>
    </item>
    <item>
      <title>Getting error during saving or publishing new article on Dev.to</title>
      <dc:creator>Ankit Kumar</dc:creator>
      <pubDate>Wed, 06 Jan 2021 02:31:07 +0000</pubDate>
      <link>https://dev.to/architectak/getting-error-during-saving-or-publishing-new-article-on-dev-to-8ko</link>
      <guid>https://dev.to/architectak/getting-error-during-saving-or-publishing-new-article-on-dev-to-8ko</guid>
      <description>&lt;p&gt;Looking for help in publishing my bew article on dev.to.&lt;/p&gt;

&lt;p&gt;Cover image is contains the error message what I am getting when trying to publish or save draft.&lt;/p&gt;

&lt;p&gt;Error text is&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whoops, something went wrong:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;base: undefined method 'any?' for #&lt;a&gt;String:Ox00007f4bfbabc6f8&lt;/a&gt;&lt;/p&gt;

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