<?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: arsham-azami</title>
    <description>The latest articles on DEV Community by arsham-azami (@arshamaazami).</description>
    <link>https://dev.to/arshamaazami</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%2F515011%2F6532d1ae-7a2f-4b29-86ac-69d1bb13cd86.jpeg</url>
      <title>DEV Community: arsham-azami</title>
      <link>https://dev.to/arshamaazami</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arshamaazami"/>
    <language>en</language>
    <item>
      <title>Expression and statement</title>
      <dc:creator>arsham-azami</dc:creator>
      <pubDate>Tue, 17 Nov 2020 15:17:01 +0000</pubDate>
      <link>https://dev.to/arshamaazami/expression-and-statement-3825</link>
      <guid>https://dev.to/arshamaazami/expression-and-statement-3825</guid>
      <description>&lt;p&gt;&lt;strong&gt;statement and expression&lt;/strong&gt; these are two things that we Programmers deal with it every moment in the day.&lt;br&gt;
It's impossible when you're writing code and don't use expressions or statements. But some of the developers aren't familiar with their differences. in this article, I am going to explain what expressions and statements are and why we use them a lot in our daily life as a programmer?🤔&lt;/p&gt;
&lt;h1&gt;
  
  
  Expression
&lt;/h1&gt;

&lt;p&gt;In a simple word, expressions are a combination of Numbers, Symbols, and operators and the purpose of an expression is to produce a value. Let me give you an example in mathematics for example (32+67) is an expression because it produces a number (99) and containers (+) as an operator&lt;/p&gt;

&lt;p&gt;expressions in computer programming mean the same expression in programming&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x =12
Console.log(x += 4)
&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;output: 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we define a variable and incremented by 4 and logged it on the console, in your opinion which part of the code above is an expression?🤔&lt;/p&gt;

&lt;p&gt;😊Yes your answer is correct😊, (x += 4) is an expression because it produces the number 16 as a value &lt;/p&gt;

&lt;h1&gt;
  
  
  Statement
&lt;/h1&gt;

&lt;p&gt;think of a computer program, a computer program contains a list of instructions in which to be executed by the computer.&lt;br&gt;&lt;br&gt;
in the programming languages, these instruction are called &lt;strong&gt;statement&lt;/strong&gt;&lt;br&gt;
actually, the statements can perform several operations like looping and &lt;/p&gt;

&lt;p&gt;in a programming language like javascript, statements are composed of the following options:&lt;/p&gt;

&lt;p&gt;1 - Values&lt;br&gt;
   2 - Operators&lt;br&gt;
   3 - Expressions (Expressions are also called statement)&lt;br&gt;
   4 - Keywords&lt;br&gt;
   5 - Comments &lt;/p&gt;

&lt;p&gt;To understand better look at the following example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; let a = 'hello'
 let b = 'guys'
 var demo = document.getElementbyId('demo')
 demo.innerHTML = a +''+ b

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

&lt;/div&gt;



&lt;p&gt;in the code above 'dom' gets the HTML element(tag) by its ID&lt;br&gt;
which is 'demo' and then set the HTML content to 'hello'&lt;br&gt;
so why is it is a statement?🤔🤨&lt;/p&gt;

&lt;p&gt;because the code contains an operator &lt;strong&gt;(=)&lt;/strong&gt; and &lt;strong&gt;(a +''+ b )&lt;/strong&gt; is an expression because it produces a string ('hello guys') as a value&lt;/p&gt;

&lt;p&gt;Another example of a statement is if...else in which is a conditional statement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var manner = 'happy' 
if(manner == 'happy'){
  return 'perfect😊'
}else{
  return 'You are sad😢'
}
&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;output: 'perfect😊
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the (manner == 'happy') is an expression because it returns a boolean as a value if the condition is true it returns 'perfect😊'&lt;br&gt;
otherwise returns 'You are sad😢'&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note :&lt;br&gt;
1-expressions are the statements that produce a value&lt;br&gt;
2-when a variable name is used in an expression the current value&lt;br&gt;
3-statements are executed one by one or in the same order they are&lt;br&gt;
written&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I tried to explain the concepts well and understandable&lt;br&gt;
I hope you enjoy reading this article&lt;/p&gt;

&lt;p&gt;❤see you until the next article❤&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The differences between map() and forEach() </title>
      <dc:creator>arsham-azami</dc:creator>
      <pubDate>Mon, 16 Nov 2020 13:38:28 +0000</pubDate>
      <link>https://dev.to/arshamaazami/the-differences-between-map-and-foreach-20fk</link>
      <guid>https://dev.to/arshamaazami/the-differences-between-map-and-foreach-20fk</guid>
      <description>&lt;p&gt;In javascript, there are many methods to work with arrays&lt;br&gt;
but some of them are a little bit confusing for most of the developers. the most common methods among javascript array methods are map() and forEach() methods but the majority of developers don't know when to use map() and forEach() and are not familiar with their differences. &lt;br&gt;
in this article, I am going to completely describe this for you&lt;/p&gt;
&lt;h1&gt;
  
  
  map()
&lt;/h1&gt;

&lt;p&gt;the map()method is a useful method and is used to repeat the same operation on every element of the array(&lt;em&gt;just like a loop&lt;/em&gt;) and then return a new array with the same number of elements. &lt;/p&gt;

&lt;p&gt;syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array.map(function(currentValue, index, arr), thisValue)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the first argument represents the current element(&lt;strong&gt;required&lt;/strong&gt;) &lt;/p&gt;

&lt;p&gt;the second argument represents the index of the current element(&lt;strong&gt;optional&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;and the third argument represents the array object that an element belongs to(&lt;strong&gt;optional&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;let arr = [21, 54, 32, 67, 90]
arr.map((element, index) =&amp;gt; {
   console.log(`element:${element} index:${index}`)
})

&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;//map() method
output :  
   element:21 index:0
   element:54 index:1
   element:32 index:2
   element:67 index:3
   element:90 index:4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;code explanation:&lt;/p&gt;

&lt;p&gt;In the example, above we define an array with five elements and took the element and index of the element by &lt;strong&gt;map()&lt;/strong&gt; method and placed them in a string, and repeated this process on all the elements. and if we decide to make this approach by for loop&lt;br&gt;
it would be something 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;let arr = [21, 54, 32, 67, 90]

for(let x=0; x&amp;lt;arr.length; x++){
   console.log(`elements:${arr[x]} index:${x}`)
}
&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;//for loop
output :  
   element:21 index:0
   element:54 index:1
   element:32 index:2
   element:67 index:3
   element:90 index:4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  forEach()
&lt;/h1&gt;

&lt;p&gt;This method is much similar to map() method it receives a function as the first argument and calls them for all the elements&lt;br&gt;
but the main difference is instead of returning a new array it returns &lt;em&gt;undefined&lt;/em&gt; and if it doesn't return anything it return a mutated array while map() method returns a new array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.forEach(function(currentValue, index, arr), thisValue)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the first argument represents the current element(&lt;strong&gt;required&lt;/strong&gt;) &lt;/p&gt;

&lt;p&gt;the second argument represents the index of the current element(&lt;strong&gt;optional&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;and the third argument represents the array object that an element belongs to(&lt;strong&gt;optional&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;let arr = [21, 54, 32, 67, 90]
arr.forEach(element =&amp;gt; element + 3)

//output: undefined 

let arr = [21, 54, 32, 67, 90]
arr.map(element =&amp;gt; element + 3)

output: [24, 57, 35, 70, 93]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;see! we performed the same operation( *defining a callback function to add 3 to each member * ) on the array with map and forEach but forEach returns undefined&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You might say javascript is a little bit strange&lt;/strong&gt;🤔&lt;/p&gt;

&lt;h1&gt;
  
  
  channing other methods
&lt;/h1&gt;

&lt;p&gt;Chaining methods means after executing a method we can bind it with some methods such as &lt;strong&gt;filter()&lt;/strong&gt;,&lt;strong&gt;splice()&lt;/strong&gt;,&lt;strong&gt;pop()&lt;/strong&gt;,etc.&lt;br&gt;
and another difference is you can bind other methods to map() method but you can't take this approach with forEach if you do this it returns undefined &lt;/p&gt;

&lt;p&gt;with map():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [21, 54, 32, 67, 90]
arr.map(element =&amp;gt; element + 3)//adding 3 to each element 
.filter(element =&amp;gt; element &amp;gt; 50) //filtering element bigger than50 
&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;output: [57, 70, 93]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with forEach():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [21, 54, 32, 67, 90]
arr.forEach(element =&amp;gt; element + 3)//adding 3 to each element 
.filter(element =&amp;gt; element &amp;gt; 50) //filtering element bigger than50 
&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;output: cannot read property 'filter' of undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  conclusion
&lt;/h1&gt;

&lt;p&gt;Both map and forEach perform the same process and receive callback function but the performance of these two methods is different, but is it important to know?🤔  &lt;/p&gt;

&lt;p&gt;It completely depends on you to choose map or forEach&lt;br&gt;
if you are going to mutate or alternate the element, you should use &lt;strong&gt;map()&lt;/strong&gt; because it returns a new array with mutated elements&lt;br&gt;
but whenever you don't need a returning array you should use forEach&lt;/p&gt;

&lt;p&gt;If you have any questions,suggestions or criticism please leave a comment&lt;/p&gt;

&lt;p&gt;😊 Thanks for reading this article 😊&lt;br&gt;
🙏🙏🙏🙏🙏🙏&lt;/p&gt;

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