<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abhishek Rath</title>
    <description>The latest articles on Forem by Abhishek Rath (@abhishek_rath).</description>
    <link>https://forem.com/abhishek_rath</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%2F689323%2F55d86198-ce0c-473d-aaff-9495dbbcaeae.png</url>
      <title>Forem: Abhishek Rath</title>
      <link>https://forem.com/abhishek_rath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abhishek_rath"/>
    <language>en</language>
    <item>
      <title>Arrays in JavaScript</title>
      <dc:creator>Abhishek Rath</dc:creator>
      <pubDate>Tue, 01 Feb 2022 19:07:21 +0000</pubDate>
      <link>https://forem.com/abhishek_rath/arrays-in-javascript-3340</link>
      <guid>https://forem.com/abhishek_rath/arrays-in-javascript-3340</guid>
      <description>&lt;h2&gt;
  
  
  What is an array?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An array is a finite collection of elements stored under one name.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zQ-nPHAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4w96qsx3544peb7gpl2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zQ-nPHAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4w96qsx3544peb7gpl2e.png" alt="Array Syntax" width="880" height="296"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N9rhHTlz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fnyjcogvjabfh4q3juh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N9rhHTlz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fnyjcogvjabfh4q3juh.png" alt="Array Example" width="880" height="559"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From above example, we can note that -  &lt;strong&gt;Array index in JavaScript starts from 0.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Accessing Array Elements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Array elements can be accessed using their index number.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tlG9s1dI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnux78fonze4sg57yvbt.png" alt="accessing" width="880" height="411"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Modifying Array Elements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Array elements can be modified by assigning value at some particular index to some other value&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XCeDACFq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oxsi444vo1tim9wqm40c.png" alt="Modify" width="880" height="469"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Methods in Arrays
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Methods allow us to manipulate arrays. &lt;/li&gt;
&lt;li&gt; In this article we'll be looking some of them, let's go :)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. length
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As the name suggests, &lt;code&gt;length&lt;/code&gt; returns the length of the array i.e. number of elements present in the array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fKNPSZAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3s2zar57dexr7fcdet9.png" alt="Length" width="880" height="411"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. concat()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This method combines two arrays and returns a new array with combined elements.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lgG55xry--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgmz5ad3s6ggdpymk2zh.png" alt="concat" width="880" height="645"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. push()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This method adds item to the end of the array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PLUUU2Jw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzjv42392mmjzy4l9bah.png" alt="push" width="880" height="439"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. pop()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Removes last item of an array, and returns the modified array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kbJAjGf4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tesg657f0wz4hokfaxuq.png" alt="pop" width="880" height="469"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. slice(start, end)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This method returns selected elements in an array.&lt;/li&gt;
&lt;li&gt;Selects elements from a given &lt;code&gt;start&lt;/code&gt;, up to a given &lt;code&gt;end&lt;/code&gt;
(exclusive).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;slice()&lt;/code&gt; method does not mutate the original array, but returns a new array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DKuU7RAL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7j7jcp12onp1iqc93hqy.png" alt="Slice" width="880" height="732"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. splice()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;splice()&lt;/code&gt; method modifies an array, by adding, removing and inserting elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Syntax&lt;/strong&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bDE4oMES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5xeydbswe61soy6odbt1.png" alt="Splice" width="880" height="323"&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index&lt;/code&gt; here is the starting point for removing elements from the array. 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2GNsaFgX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49xm23z7o09f2m3rm2i5.png" alt="splice index" width="880" height="497"&gt; &lt;/li&gt;
&lt;li&gt; &lt;code&gt;count&lt;/code&gt; specifies the number of elements to be deleted from the given index. This is optional parameter.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LP2TZZh0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3a0vr43xhbktniedkm3h.png" alt="splice count" width="880" height="497"&gt;
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;value&lt;/code&gt; specifies the value to be added to the original array
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7ZeNIgSP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8mxaqo0rducosmdd7bp.png" alt="splice value" width="880" height="497"&gt; &lt;/li&gt;
&lt;li&gt;In above example, &lt;code&gt;count&lt;/code&gt; parameter is set to &lt;code&gt;0&lt;/code&gt;, therefore it doesn't remove any elements from the array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;value&lt;/code&gt; parameter Cedric is added to array at position 1.
&lt;/li&gt;
&lt;/ul&gt;


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



&lt;h2&gt;
  
  
  7. reverse()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As the name says, &lt;code&gt;reverse()&lt;/code&gt; method reverses the order of elements in the array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reverse()&lt;/code&gt; method modifies the original array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9TPYAzv0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sizsnl9whk15o32idfuw.png" alt="array reverse" width="880" height="351"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. join()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Returns array as string.&lt;/li&gt;
&lt;li&gt;Doesn't modify the original array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;join()&lt;/code&gt; method accepts an optional parameter - a &lt;strong&gt;separator&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Any separator can be specified. The default is comma (,).
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lTKcFZ-o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2y5zpn0yi9nefq8s2ym.png" alt="join" width="880" height="469"&gt;
&lt;/li&gt;
&lt;li&gt;Example with separator
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MUbbb3_B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9fiu0zz1n517z685io98.png" alt="join separator" width="880" height="469"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. map(fn)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One of the most used array methods in JavaScript.&lt;/li&gt;
&lt;li&gt;Takes in function as a parameter, and creates a new array by calling a function for every array element.&lt;/li&gt;
&lt;li&gt;Doesn't modify the original array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FBrptcfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jgh5huf887f8h9ifno8.png" alt="map" width="880" height="557"&gt;
&lt;/li&gt;
&lt;li&gt;In above example, &lt;code&gt;map()&lt;/code&gt; takes every element from the &lt;code&gt;arr&lt;/code&gt; and applies &lt;code&gt;square&lt;/code&gt; function to it. &lt;/li&gt;
&lt;li&gt;Inshort, &lt;code&gt;map()&lt;/code&gt; method, maps every elements of the array to the specified function and returns a new array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  10. filter()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Another most used array method in JS.&lt;/li&gt;
&lt;li&gt;This method creates a new array if the elements of an array pass a certain condition.&lt;/li&gt;
&lt;li&gt;Doesn't modify the original array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fyIzvDiR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0bccqzum2ozzzgkgyzs.png" alt="filter" width="880" height="557"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filter&lt;/code&gt; method in above example filters the elements based on the function provided in as its parameter. The function returns only the even numbers from the array.&lt;/li&gt;
&lt;li&gt;Hence, &lt;code&gt;filter&lt;/code&gt; method creates a new array with even numbers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  11. indexOf()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;indexOf()&lt;/code&gt; method returns the first occurence of a specified value.&lt;/li&gt;
&lt;li&gt;Returns -1 if the value is not found.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RMzEjykQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4u8szm1g90iolfpazjh.png" alt="indexOf" width="880" height="411"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  12. lastIndexOf()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;lastIndexOf()&lt;/code&gt; method returns the last occurence of the element in the array.&lt;/li&gt;
&lt;li&gt;Returns -1 if the value is not found.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7PKkyxW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pjbf9oinnbiykpwxsxhy.png" alt="lastIndexOf" width="880" height="497"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  13. forEach()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;forEach()&lt;/code&gt; method calls a function for every element in an array.&lt;/li&gt;
&lt;li&gt;Very useful for iterating through an array.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OEPb-jSS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9keu99ut9g4e45f9ied.png" alt="forEach" width="880" height="645"&gt;
&lt;/li&gt;
&lt;li&gt;In above example, &lt;code&gt;forEach()&lt;/code&gt; takes in an arrow function as its parameter, and logs every number multplied by 100 to the console.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;concat()&lt;/code&gt; combines two arrays together.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;push()&lt;/code&gt; adds item(s) to the end of an array .&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pop()&lt;/code&gt; removes the last item of an array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;splice()&lt;/code&gt; changes an array, by adding, removing and inserting elements.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;indexOf()&lt;/code&gt; searches for an element in the array and returns the index of its first occurence, else it returns -1.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lastIndexOf()&lt;/code&gt; searches for an element and returns the last index where the item was found.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filter()&lt;/code&gt; creates a new array if the elements of an array pass a certain condition.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;map()&lt;/code&gt; creates a new array by calling a function for every array element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;forEach()&lt;/code&gt; iterates through an array, and applies a function on every element in an array.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reverse()&lt;/code&gt; reverses the order of elements in the array.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;I hope this article provides you the basics of JavaScript arrays and its methods.&lt;/li&gt;
&lt;li&gt;This article discusses some of the basic array methods, and there are many &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;other methods&lt;/a&gt; out there.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Happy Learning!!
&lt;/h4&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Truthy and Falsy Values in JavaScript</title>
      <dc:creator>Abhishek Rath</dc:creator>
      <pubDate>Thu, 16 Dec 2021 07:31:17 +0000</pubDate>
      <link>https://forem.com/abhishek_rath/truthy-and-falsy-values-in-javascript-g4a</link>
      <guid>https://forem.com/abhishek_rath/truthy-and-falsy-values-in-javascript-g4a</guid>
      <description>&lt;p&gt;Before diving into truthy and falsy values, let us understand what  &lt;strong&gt;boolean&lt;/strong&gt; data type is in JavaScript?&lt;/p&gt;

&lt;p&gt;A JavaScript Boolean denotes one of two values: true or false.&lt;br&gt;
For example,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cFw8MhKk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atw8fymqrlpmy29wqqr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cFw8MhKk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atw8fymqrlpmy29wqqr5.png" alt="Boolean Example" width="880" height="474"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Boolean() function can be used to find out if an expression (or a variable) is true or false.&lt;/p&gt;

&lt;p&gt;Now let us know about truthy and falsy values.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Falsy values are the values that are not actually false but will produce the result as false when converted into boolean.&lt;/li&gt;
&lt;li&gt;There are total 5 falsy values in JS - 0, undefined, NaN, null, '' .
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pdyHh6sX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uns116g6opvin7qe9a71.png" alt="Falsy" width="880" height="549"&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Truthy values are the values that are considered true when converted into Boolean.&lt;/li&gt;
&lt;li&gt;All values except &lt;code&gt;false, 0, undefined, NaN, null, ''&lt;/code&gt; are truthy values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5CNe0A53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639635977300/Rn6O6etY6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5CNe0A53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639635977300/Rn6O6etY6.png" alt="Truthy" width="880" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you find this article simple and easy to understand JavaScript truthy and falsy values. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Some popular string Methods in JavaScript</title>
      <dc:creator>Abhishek Rath</dc:creator>
      <pubDate>Mon, 08 Nov 2021 16:14:13 +0000</pubDate>
      <link>https://forem.com/abhishek_rath/string-methods-in-javascript-4d32</link>
      <guid>https://forem.com/abhishek_rath/string-methods-in-javascript-4d32</guid>
      <description>&lt;h2&gt;
  
  
  What is a String?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The sequence of one or more characters enclosed within quotation marks is called a string.&lt;/li&gt;
&lt;li&gt;The quotation can be single quotes &lt;code&gt;''&lt;/code&gt; or double quotes &lt;code&gt;" "&lt;/code&gt; or backtick ``.&lt;/li&gt;
&lt;li&gt;And, the sequence of characters can be alphabets, numbers, symbols, etc.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Some commonly used JavaScript methods:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Length&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As the name suggests, &lt;code&gt;length&lt;/code&gt; returns the length of the string.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghmt0kg9k6wexemge3ga.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghmt0kg9k6wexemge3ga.png" alt="Length"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note, in the above example the whitespace, comma, and exclamation mark are also part of the string.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.&lt;strong&gt;charAt(index)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;charAt()&lt;/code&gt; returns the character at a specified index in a string.&lt;/li&gt;
&lt;li&gt;The very first character of the string has an index of 0, the second character has index 1, and so on...&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;3.&lt;strong&gt;substring(start, end)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This method extracts the part of the string between &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; and returns the substring.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;4.&lt;strong&gt;substr(start, length)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;substr()&lt;/code&gt; method returns the specified number of characters from the specified index (&lt;code&gt;start&lt;/code&gt; parameter) from a given string.&lt;/li&gt;
&lt;li&gt;Here, &lt;code&gt;start&lt;/code&gt; defines the starting index from where the substring is to be extracted from the original string.&lt;/li&gt;
&lt;li&gt;And, &lt;code&gt;length&lt;/code&gt; defines the number of characters to be extracted from the specified start index.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Note:&lt;/strong&gt; If the &lt;code&gt;length&lt;/code&gt; parameter isn't given, then all the characters from start till the end of the string are extracted.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;5.&lt;strong&gt;concat()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;concat()&lt;/code&gt; method joins two or more strings.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;concat()&lt;/code&gt; method doesn't modify the  original strings, but it returns a new string.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkam7ly6liq3z4g9wzkn4.png" alt="concat"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6.&lt;strong&gt;toUpperCase()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;toUpperCase()&lt;/code&gt; method converts the strings to upper case letters.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fopks9yhun2u40ne4y6v4.png" alt="toUpperCase()"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;7.&lt;strong&gt;toLowerCase()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;toLowerCase()&lt;/code&gt; method converts the strings to lower case letters. 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ih7jxub77z1lwzw63dv.png" alt="lower case"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;8.&lt;strong&gt;slice(start, end)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;slice()&lt;/code&gt; method extracts and returns a part of the string from start to (excluding) the end character.&lt;/li&gt;
&lt;li&gt;If there's no second argument specified, then the slice method extracts till the end of the string.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;slice()&lt;/code&gt; also works on negative indices. If a negative index is specified, the string is extracted from the right end.&lt;/li&gt;
&lt;li&gt;The negative index starts from -1 and it indicates the last character of the string, -2 is the second last character, and so on...
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwnkwsphk79umaa8t7ez.png" alt="slice"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;9.&lt;strong&gt;replace(substring)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;replace()&lt;/code&gt; method is used to replace a part of a given string with a new substring.&lt;/li&gt;
&lt;li&gt;One important thing to note here is that the &lt;code&gt;replace()&lt;/code&gt; method does not change the original string on which it is called upon. It simply returns a new string.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;10.&lt;strong&gt;includes(substring)&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;includes()&lt;/code&gt; method does a case-sensitive search on the original string to see if the specified substring is present in the string or not.&lt;/li&gt;
&lt;li&gt;If the specified string is present, the method returns &lt;code&gt;true&lt;/code&gt; otherwise &lt;code&gt;false&lt;/code&gt;.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdn7mzevxtdk4nipdy7k.png" alt="includes"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;11.&lt;strong&gt;trim()&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;trim()&lt;/code&gt; method removes leading and trailing whitespaces from the given string.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphzu5o545e5200jq06hb.png" alt="trim"&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;That is all from my side. I hope this article provides you with the basics of some popular string methods used in JavaScript.&lt;/li&gt;
&lt;li&gt;Working through the examples is the best idea to understand these methods. Play with the examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Keep Learning!!
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Functions in JavaScript</title>
      <dc:creator>Abhishek Rath</dc:creator>
      <pubDate>Sat, 16 Oct 2021 17:10:38 +0000</pubDate>
      <link>https://forem.com/abhishek_rath/functions-in-javascript-56if</link>
      <guid>https://forem.com/abhishek_rath/functions-in-javascript-56if</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;One day a student was plotting some mischief in a class. The professor noticed this and as a way to punish him, he asked the student to write a program to calculate square of number. After a minute, the student came to professor to show his code, it was something like this &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdpt2q8vt01kpto8es7xv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdpt2q8vt01kpto8es7xv.png" alt="Code"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The professor looked at the code, and asked him, "how will you solve this particular question, if ask you calculate square of 10 distinct number"?. The student replied, sir I'll write &lt;code&gt;console.log(x * x)&lt;/code&gt; 10 times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To this the professor said it is one way to solve a problem, but now, if ask you to solve the same problem for 20 different numbers, what will you do? The student said, I'll print square of a number 20 times, but it is very boring and tedious task.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Exactly", said the professor. Repeating yourself in a code violates the DRY (Don't Repeat Yourself) principle and it also makes your code look ugly. Therefore, the professor said to his students, "Let us learn about a important topic called &lt;em&gt;"Functions"&lt;/em&gt;.&lt;br&gt;
Let us also learn with them...&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Function is a group of statements that are bundled together to perform a specific task.&lt;/li&gt;
&lt;li&gt;The syntax to create a function is - 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wh2pbiztq891udhmczh.png" alt="Syntax"&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function Declaration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The function declaration also called as function definition consists of &lt;strong&gt;function&lt;/strong&gt; keyword followed by:

&lt;ul&gt;
&lt;li&gt;Name of the function.&lt;/li&gt;
&lt;li&gt;A list of parameters (optional) enclosed within the 
parentheses and separated by commas.&lt;/li&gt;
&lt;li&gt;Statements that define what the function does.&lt;/li&gt;
&lt;li&gt;An optional return statement.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;In above code snippet, &lt;code&gt;square&lt;/code&gt; is the function name, followed by a parameter named &lt;code&gt;num&lt;/code&gt; enclosed in parentheses and the function body prints the square of the number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Calling a function
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In above example we have defined a function, but it doesn't execute on its own. It only specifies what the function performs.&lt;/li&gt;
&lt;li&gt;To execute the statements specified in the body of function, you need to call it or invoke it.&lt;/li&gt;
&lt;li&gt;To invoke a function you need to write function name and pass the parameters enclosed within the parentheses, if any.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: The above function can be invoked as: 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3psjnurjs86s5x7d0xd.png" alt="invoke a function"&gt;
&lt;/li&gt;
&lt;li&gt;This function call passes the value &lt;code&gt;5&lt;/code&gt; to the &lt;code&gt;num&lt;/code&gt; in the function declaration above.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Return Statement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A function may or may not return a value.&lt;/li&gt;
&lt;li&gt;If function has return statement, it returns the value to the caller function.&lt;/li&gt;
&lt;li&gt;A function can have only one return statement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hwhm06iop0fr8nd6o7z.png" alt="Return Statement"&gt;
&lt;/li&gt;
&lt;li&gt;In above example, the &lt;code&gt;return&lt;/code&gt; statement returns the value of the calculated expression to the calling function.&lt;/li&gt;
&lt;li&gt;This returned value is stored in the variable &lt;code&gt;age&lt;/code&gt;, and the next statement prints the value of &lt;code&gt;age&lt;/code&gt; in the console.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are parameters?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We saw in above syntax that parameters are something that are enclosed within parentheses. But what exactly does it do ?&lt;/li&gt;
&lt;li&gt;The parameters act as a placeholder which accepts the value passed during calling the function.&lt;/li&gt;
&lt;li&gt;The parameters are optional, a function may or may not have them.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1s922rle1wwvcxjqsynn.png" alt="Parameters example"&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits of using functions -
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To improve readability of the code.&lt;/li&gt;
&lt;li&gt;To follow DRY (Don't repeat yourself) principle.&lt;/li&gt;
&lt;li&gt;Improves reusability of code, i.e. same function can be called to perform a specific task as many times it is required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Different ways to use functions in JavaScript
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Declaring a function (most commonly used and discussed above).&lt;/li&gt;
&lt;li&gt;Function Expressions&lt;/li&gt;
&lt;li&gt;Arrow Functions&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Function Expressions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Besides function declaration, the functions can also be created using function expressions.&lt;/li&gt;
&lt;li&gt;Such a function can be anonymous; it does not need to have a name. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4mka8c2zwyocs6d4u0b.png" alt="Function expression example"&gt;
&lt;/li&gt;
&lt;li&gt;The function in above example doesn't have name hence it is called anonymous function.&lt;/li&gt;
&lt;li&gt;However, the function expression can also have a name.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fubqgiiufi8blchhdsvlp.png" alt="Named function expression"&gt; &lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Also called as one liner functions.&lt;/li&gt;
&lt;li&gt;Has a shorter syntax compared to function expressions.&lt;/li&gt;
&lt;li&gt;The arrow functions doesn't make use of function keyword to define a function. Instead, it uses a fat arrow =&amp;gt; to define what a function does.&lt;/li&gt;
&lt;li&gt;Arrow functions are anonymous.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjaiauavbkxmctc3qftzc.png" alt="Arrow function"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The functions are very useful to write reusable code.&lt;/li&gt;
&lt;li&gt;A function can be written in one or more ways.&lt;/li&gt;
&lt;li&gt;Arrow functions must be avoided since they don't have a name, which causes problems while debugging.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;That will be all from my side. I hope, this article gave you a basic idea about the functions.&lt;/li&gt;
&lt;li&gt;Although basics of function are covered in this article, please look into &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions" rel="noopener noreferrer"&gt;MDN documentation&lt;/a&gt; for more details and examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Keep Learning!!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Strict mode in JavaScript</title>
      <dc:creator>Abhishek Rath</dc:creator>
      <pubDate>Thu, 14 Oct 2021 19:25:49 +0000</pubDate>
      <link>https://forem.com/abhishek_rath/strict-mode-in-javascript-cl7</link>
      <guid>https://forem.com/abhishek_rath/strict-mode-in-javascript-cl7</guid>
      <description>&lt;h2&gt;
  
  
  What is strict mode?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Strict mode was introduced in ECMAScript5 also known as ES5 in 2009.&lt;/li&gt;
&lt;li&gt;Adding strict mode to JavaScript code allows your code to be checked more strictly.&lt;/li&gt;
&lt;li&gt;Allows programmer to write more secure JavaScript code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits of Strict Mode
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Using strict mode in JavaScript code throws visible errors in developer console which would otherwise fail silently (shown in the examples below).&lt;/li&gt;
&lt;li&gt;Forbids programmers to use certain syntax.&lt;/li&gt;
&lt;li&gt;In some cases using strict mode in code can make the code to run faster.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to enable strict mode in JavaScript?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To enable strict mode write &lt;code&gt;"use strict"&lt;/code&gt; or &lt;code&gt;'use strict'&lt;/code&gt; at the beginning of JavaScript code.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzr31z7z292mrv2elkbo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzr31z7z292mrv2elkbo.png" alt="Strict mode for entire code"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The strict mode can also be used for a function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To enable strict mode in function, &lt;code&gt;"use strict"&lt;/code&gt; or &lt;code&gt;'use strict'&lt;/code&gt; must be the very first line in function body.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feizx9nbglojjtsa25jlc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feizx9nbglojjtsa25jlc.png" alt="Strict mode in function"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes that occur in non-strict mode
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Using reserved words as variable names
&lt;/h3&gt;

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

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

&lt;ul&gt;
&lt;li&gt;Wait!! Isn't &lt;strong&gt;&lt;em&gt;"let"&lt;/em&gt;&lt;/strong&gt; a reserved word in the JavaScript? Therefore it mustn't be used as a variable name according to naming an identifier rules.
Here in the above code snippet JavaScript fails silently instead of throwing an error.&lt;/li&gt;
&lt;li&gt;But, if we use strict mode, JavaScript engine will throw an error-
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9md3nht65fa8vvsnlvwu.png" alt="Strict mode in code snippet"&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiqdqx5mdg5qulqocoic5.png" alt="Produces error"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Using variables before declaring them
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using strict mode gives &lt;em&gt;Reference Error&lt;/em&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F640wr270x9qp3lhl30iz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F640wr270x9qp3lhl30iz.png" alt="Variable used before declaration in strict mode"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmu9qm3h3b4rqg1e0ujz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmu9qm3h3b4rqg1e0ujz.png" alt="Output"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To know more about the strict mode, checkout the documentation by &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;That will be all from my side. I hope, this article gave you a basic idea about the strict mode.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep Learning!!&lt;/p&gt;

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