<?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: Prasad Sawant</title>
    <description>The latest articles on DEV Community by Prasad Sawant (@prasadsawant7).</description>
    <link>https://dev.to/prasadsawant7</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%2F527460%2F4e805360-2781-4339-8574-88b59e516fc3.jpeg</url>
      <title>DEV Community: Prasad Sawant</title>
      <link>https://dev.to/prasadsawant7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prasadsawant7"/>
    <language>en</language>
    <item>
      <title>JavaScript Functions</title>
      <dc:creator>Prasad Sawant</dc:creator>
      <pubDate>Mon, 20 Feb 2023 15:13:40 +0000</pubDate>
      <link>https://dev.to/prasadsawant7/javascript-functions-12i1</link>
      <guid>https://dev.to/prasadsawant7/javascript-functions-12i1</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Function Statement aka Function Declaration:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;u&gt;syntax of writing function&lt;/u&gt; is called as &lt;strong&gt;Function Statement or Function Declaration.&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 fooBar() {
    console.log("Hello World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Difference between Function Parameters and Arguments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we add &lt;u&gt;variables inside round brackets&lt;/u&gt; in &lt;u&gt;Function Declaration&lt;/u&gt; then those variables are called as &lt;strong&gt;Parameters&lt;/strong&gt;, and they are &lt;u&gt;copy&lt;/u&gt; of the sent variable through function call.&lt;br&gt;
If we call the function and along with it we pass a variable inside round brackets of function call then those variables are called as &lt;strong&gt;Arguments.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📌&lt;u&gt;&lt;strong&gt;Note:-&lt;/strong&gt;&lt;/u&gt; We can keep the names of parameter and argument same, but to avoid confusion we usually name it differently.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Parameter
function fooBar(parameter) {
    console.log("Hey Foo Bar, it's me ", parameter)
}

// Argument
let argument = "John Doe"
fooBar(argument)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Anonymous Function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When we create a &lt;u&gt;function but without name&lt;/u&gt; is called as &lt;strong&gt;Anonymous Function.&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;setTimeout(function() {
    console.log("Hello World!")
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Function Expression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is almost same as creating &lt;u&gt;Anonymous Function&lt;/u&gt; but not only creating it, also &lt;u&gt;assigning it to a Variable&lt;/u&gt; means &lt;strong&gt;Function Expression.&lt;/strong&gt; After assigning the function to the variable, the function act as a &lt;u&gt;&lt;strong&gt;value&lt;/strong&gt;&lt;/u&gt; and it is &lt;u&gt;not added&lt;/u&gt; into the &lt;u&gt;Global Scope&lt;/u&gt;. We can also create a &lt;u&gt;Named Function&lt;/u&gt; and &lt;u&gt;assign it to a variable&lt;/u&gt; then it is called as &lt;strong&gt;Named Function Expression.&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 Expression
let foo = function() {
    console.log("Hello World!")
}

// Named Function Expression
let bar = function foo() {
    console.log("Hello World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First Class Functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Functions&lt;/u&gt; has ability to be used like &lt;u&gt;Values&lt;/u&gt; is called as &lt;strong&gt;First Class Functions&lt;/strong&gt;. Functions can be &lt;u&gt;returned as  values&lt;/u&gt; from a function or can be send as &lt;u&gt;arguments&lt;/u&gt; to a function. &lt;strong&gt;First Class Functions&lt;/strong&gt; are also known as &lt;strong&gt;First Class Citizens.&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 returned as Value
function foo() {
    return function() {
        console.log("Hello World!")
    }
}
let helloWorld = foo()

// Functions sent as Argument
function foo(funcParam) {
    bar()
    console.log("Here we are in Foo!")
}

function bar() {
    console.log("Hello World!")
}

foo(bar)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Thanks for reading, will cover Arrow Functions in next blog 😉&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>discuss</category>
      <category>news</category>
    </item>
  </channel>
</rss>
