<?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: Dev-Coder</title>
    <description>The latest articles on DEV Community by Dev-Coder (@dev_coder).</description>
    <link>https://dev.to/dev_coder</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%2F538627%2Fc863a222-108b-4980-94cb-aa5bbb899521.png</url>
      <title>DEV Community: Dev-Coder</title>
      <link>https://dev.to/dev_coder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dev_coder"/>
    <language>en</language>
    <item>
      <title>Angular : Lifecycle Hooks</title>
      <dc:creator>Dev-Coder</dc:creator>
      <pubDate>Tue, 15 Dec 2020 11:50:35 +0000</pubDate>
      <link>https://dev.to/dev_coder/angular-8-lifecycle-hooks-14i0</link>
      <guid>https://dev.to/dev_coder/angular-8-lifecycle-hooks-14i0</guid>
      <description>&lt;p&gt;&lt;em&gt;In Angular, a component is the main building block the application, it is very important for us to understand the lifecycle processing steps of the components so that we can implement that in our applications.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LifeCycle Process&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Angular, every component has a life-cycle, a number of different stages it goes through. &lt;/li&gt;
&lt;li&gt;There are 8 different stages in the component lifecycle. &lt;/li&gt;
&lt;li&gt;Every stage is called as lifecycle hook event.&lt;/li&gt;
&lt;li&gt;So, we can use these hook events in different phases of our application to obtain control of the components.&lt;/li&gt;
&lt;li&gt;Since a component is a TypeScript class, every component must have a constructor method.&lt;/li&gt;
&lt;li&gt;The constructor of the component class executes, first, before the execution of any other lifecycle hook events.&lt;/li&gt;
&lt;li&gt;If we need to inject any dependencies into the component, then the constructor is the best place to inject those dependencies.&lt;/li&gt;
&lt;li&gt;After executing the constructor, Angular executes its lifecycle hook methods in a specific order.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1cp99r7ozvgvpna08m5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1cp99r7ozvgvpna08m5a.png" alt="Lifecycle Hooks Sequencial Order" width="219" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These stages are mainly divided into two phases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One is linked to the component itself and &lt;/li&gt;
&lt;li&gt;Another is linked to the children of that component.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ngOnChanges&lt;/strong&gt; – This event executes every time when a value of an input control within the component has been changed. Actually, this event is fired first when a value of a bound property has been changed. It always receives a change data map, containing the current and previous value of the bound property wrapped in a SimpleChange.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngOnInit&lt;/strong&gt; – This event initializes after Angular first displays the data-bound properties or when the component has been initialized. This event is basically called only after the ngOnChanges()events. This event is mainly used for the initialize data in a component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngDoCheck&lt;/strong&gt; – This event is triggered every time the input properties of a component are checked. We can use this hook method to implement the check with our own logic check. Basically, this method allows us to implement our own custom change detection logic or algorithm for any component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngAfterContentInit&lt;/strong&gt; –  This lifecycle method is executed when Angular performs any content projection within the component views. This method executes when all the bindings of the component need to be checked for the first time. This event executes just after the ngDoCheck() method. This method is basically linked with the child component initializations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngAfterContentChecked&lt;/strong&gt; – This lifecycle hook method executes every time the content of the component has been checked by the change detection mechanism of Angular. This method is called after the ngAfterContentInit() method. This method is also called on every subsequent execution of ngDoCheck(). This method is also mainly linked with the child component initializations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngAfterViewInit&lt;/strong&gt; – This lifecycle hook method executes when the component’s view has been fully initialized. This method is initialized after Angular initializes the component’s view and child views. It is called after ngAfterContentChecked(). This lifecycle hook method only applies to components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngAfterViewChecked&lt;/strong&gt; – This method is called after the ngAterViewInit() method. It is executed every time the view of the given component has been checked by the change detection algorithm of Angular. This method executes after every subsequent execution of the ngAfterContentChecked(). This method also executes when any binding of the children directives has been changed. So this method is very useful when the component waits for some value which is coming from its child components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ngOnDestroy&lt;/strong&gt; – This method will be executed just before Angular destroys the components. This method is very useful for unsubscribing from the observables and detaching the event handlers to avoid memory leaks. Actually, it is called just before the instance of the component is finally destroyed. This method is called just before the component is removed from the DOM.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>angular</category>
      <category>codenewbie</category>
      <category>devjournal</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Arrow Functions</title>
      <dc:creator>Dev-Coder</dc:creator>
      <pubDate>Sun, 13 Dec 2020 14:51:42 +0000</pubDate>
      <link>https://dev.to/dev_coder/javascript-arrow-functions-4n44</link>
      <guid>https://dev.to/dev_coder/javascript-arrow-functions-4n44</guid>
      <description>&lt;p&gt;_Today, We will learn how to use the JavaScript arrow function to write more concise code for function expressions.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ES6 arrow functions provide you with an alternative way to write a shorter syntax compared to the function expression.&lt;/p&gt;

&lt;p&gt;The following example defines a function expression that adds two numbers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg6na0hlswzo258rbzqo7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg6na0hlswzo258rbzqo7.PNG" alt="Alt Text" width="482" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Arrow Function Example&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe5kdprevn52vox3wtbl3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe5kdprevn52vox3wtbl3.PNG" alt="Alt Text" width="423" height="111"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In above example, The arrow function has one expression x + y so it returns the result of the expression.&lt;/p&gt;

&lt;p&gt;However, if you use the block syntax, you need to specify the &lt;strong&gt;return&lt;/strong&gt; keyword:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gt8bb50alh8y919vkth.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gt8bb50alh8y919vkth.PNG" alt="Alt Text" width="411" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;typeof&lt;/strong&gt; operator returns function indicating the type of arrow function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F75dsd0xm50ivmddt7be6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F75dsd0xm50ivmddt7be6.PNG" alt="Alt Text" width="384" height="93"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Arrow Functions With Multiple Parameters&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If an arrow function has two or more parameters, we need to use the following syntax:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb4lli8qse6sro3lndj16.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb4lli8qse6sro3lndj16.PNG" alt="Alt Text" width="415" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example, To sort an array of numbers in the descending order, we use the sort() method of the array object as follows:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8sw5ty8z1dkuoxshri5l.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8sw5ty8z1dkuoxshri5l.PNG" alt="Alt Text" width="446" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code is more concise with the arrow function syntax:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm57rizjmaf8yhkju5r1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm57rizjmaf8yhkju5r1.PNG" alt="Alt Text" width="425" height="124"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Arrow Functions With Single Parameter&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If an arrow function takes a single parameter, we can use the following syntax:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;(parameter1) =&amp;gt; { statements }&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Note that, We can omit the parentheses as follows:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;parameter =&amp;gt; { statements }&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The following example uses an arrow function as an argument of the &lt;em&gt;map()&lt;/em&gt; method that transforms an array of strings into an array of the string’s lengths.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxfwh773ol5k3cxv1epwt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxfwh773ol5k3cxv1epwt.PNG" alt="Alt Text" width="539" height="133"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Arrow Functions With No Parameter&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the arrow function has no parameter, we must use the parentheses, like this:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;( ) =&amp;gt; { statements }&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Line Break Between Parameter Definition and Arrow&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript doesn’t allow us to use a line break between the parameter definition and the arrow &lt;strong&gt;( =&amp;gt; )&lt;/strong&gt; in an arrow function. The following code produces a &lt;strong&gt;SyntaxError&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwwnhhdf29xaw5i8w1yzr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwwnhhdf29xaw5i8w1yzr.PNG" alt="Alt Text" width="379" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, the following code works perfectly fine:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn40tgoqcfvs6lr5ib017.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn40tgoqcfvs6lr5ib017.PNG" alt="Alt Text" width="408" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;JavaScript allows us to use the line break between parameters as shown in the following example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F53o7an3fmxbv5ppzy403.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F53o7an3fmxbv5ppzy403.PNG" alt="Alt Text" width="437" height="149"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Summary:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Arrow functions are handy for one-liners. They come in two flavors:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Without curly braces: (...args) =&amp;gt; expression – the right side is an expression: the function evaluates it and returns the result.&lt;/li&gt;
&lt;li&gt;With curly braces: (...args) =&amp;gt; { body } – brackets allow us to write multiple statements inside the function, but we need an explicit return to return something.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>JavaScript - Destructuring Assignment</title>
      <dc:creator>Dev-Coder</dc:creator>
      <pubDate>Sat, 12 Dec 2020 18:57:52 +0000</pubDate>
      <link>https://dev.to/dev_coder/javascript-destructuring-assignment-124f</link>
      <guid>https://dev.to/dev_coder/javascript-destructuring-assignment-124f</guid>
      <description>&lt;p&gt;&lt;em&gt;Today, We will learn how to use the ES6 destructuring assignment that allows us to destructure an array into individual variables&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;ES6 provides a new feature called destructing assignment that allows you to destructure properties of an object or elements of an array into individual variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Array destructuring&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's take an example of a function that returns an array of subject list as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fusvl6fzm1inz70h8oh5p.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fusvl6fzm1inz70h8oh5p.PNG" alt="Alt Text" width="424" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following invokes the getSubjectList() function and assigns the returned value to a variable:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc216qmbwhtvz563r4tzi.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc216qmbwhtvz563r4tzi.PNG" alt="Alt Text" width="404" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prior to ES6, there was no direct way to assign the elements of the returned array to multiple variables such as x, y and z.&lt;/li&gt;
&lt;li&gt;To get the individual subject to a variable, We need to do like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fba8e635vobjljd1u062m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fba8e635vobjljd1u062m.PNG" alt="Alt Text" width="360" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, From ES6, We can use the destructing assignment as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynwqsu8wyiyvsfixcnh1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynwqsu8wyiyvsfixcnh1.PNG" alt="Alt Text" width="447" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The variables x, y and z will take the values of the first, second, and third elements of the returned array.&lt;/p&gt;

&lt;p&gt;Note that the square brackets [] look like the array syntax but they are not.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If the getSubjectList() function returns an array of two elements, the third variable will be undefined, like this:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgw3px6x6wqjqht543e47.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgw3px6x6wqjqht543e47.PNG" alt="Alt Text" width="550" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In case the getSubjectList() function returns an array that has more than three elements, &lt;strong&gt;the remaining elements are discarded.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwpsso8uurlo2rnivfqpj.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwpsso8uurlo2rnivfqpj.PNG" alt="Alt Text" width="624" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Array "Destructuring Assignment" with "Rest" Parameter&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It’s possible to take all remaining elements of an array and put them in a new array by using the rest syntax (...):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foyyss6yyjvy3m2jqp34z.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foyyss6yyjvy3m2jqp34z.PNG" alt="Alt Text" width="599" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The variables x and y receive values of the first two elements of the returned array. &lt;/li&gt;
&lt;li&gt;The args variable receives all the remaining arguments, which are the last two elements of the returned array.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Setting default values&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For Example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjvz8lvnzjpiqon7i0v5o.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjvz8lvnzjpiqon7i0v5o.PNG" alt="Alt Text" width="600" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, declare the getValues() function that returns an array of two numbers.&lt;/li&gt;
&lt;li&gt;Then, assign the dataValue variable to the returned array of the getValues() function.&lt;/li&gt;
&lt;li&gt;Finally, check if the third element exists in the array. If not, assign the value 0 to the thirdItem variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;It’ll be simpler with the destructuring assignment with a default value:&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft3gyiimzwcms1pes4qzi.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft3gyiimzwcms1pes4qzi.PNG" alt="Alt Text" width="609" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;If the getData() function doesn’t return an array and you expect an array, the destructing assignment will result in an error.&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc6n7kzpduhyhd3h4mpja.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc6n7kzpduhyhd3h4mpja.PNG" alt="Alt Text" width="706" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uncaught TypeError: getData is not a function or its return value is not iterable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A typical way to solve this is to fallback the returned value of the getData() function to an empty array like this:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy84whfe4sai969ncb4zo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy84whfe4sai969ncb4zo.PNG" alt="Alt Text" width="509" height="218"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Summary&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.&lt;/li&gt;
&lt;li&gt;We can set user-defined default values if array has returned null or variable has a undefined.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>todayilearned</category>
      <category>dailypost</category>
    </item>
    <item>
      <title>JavaScript ES6 - Spread Operator</title>
      <dc:creator>Dev-Coder</dc:creator>
      <pubDate>Fri, 11 Dec 2020 19:17:56 +0000</pubDate>
      <link>https://dev.to/dev_coder/javascript-es6-spread-operator-2me5</link>
      <guid>https://dev.to/dev_coder/javascript-es6-spread-operator-2me5</guid>
      <description>&lt;ul&gt;
&lt;li&gt;ES6 provides a new operator called spread operator that consists of three dots (...). &lt;/li&gt;
&lt;li&gt;The spread operator allows you to spread out elements of an iterable object such as an array,a  map, or a set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Example&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10jgopm5dhwz88uvtf91.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10jgopm5dhwz88uvtf91.PNG" alt="Alt Text" width="401" height="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Result&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffbrw9ox1aqv2m2xnzuat.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffbrw9ox1aqv2m2xnzuat.PNG" alt="Alt Text" width="127" height="54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Above example, the three dots (...) located in front of the &lt;strong&gt;&lt;em&gt;oddValue&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;evenValue&lt;/em&gt;&lt;/strong&gt; array is the spread operator.&lt;/li&gt;
&lt;li&gt;  The spread operator unpacks the elements of the &lt;strong&gt;&lt;em&gt;oddValue&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;evenValue&lt;/em&gt;&lt;/strong&gt; array.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;Summary&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The spread operator is denoted by three dots (…).&lt;/li&gt;
&lt;li&gt;  The spread operator unpacks elements of iterable objects such as arrays, sets, and maps into a list.&lt;/li&gt;
&lt;li&gt;  The spread operator can be used to clone an iterable object or merge iterable objects into one.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>javascript</category>
      <category>es6</category>
      <category>spreadoperator</category>
    </item>
  </channel>
</rss>
