<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
>

<channel>
	<title>function - Bipon's Diary</title>
	<atom:link href="https://biponnotes.iglyphic.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>https://biponnotes.iglyphic.com</link>
	<description>Do good for others. It will come back in unexpected ways.</description>
	<lastBuildDate>Sun, 26 Jan 2020 05:13:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.9.10</generator>
<site xmlns="com-wordpress:feed-additions:1">168324471</site>	<item>
		<title>Callback Function in JavaScript</title>
		<link>https://biponnotes.iglyphic.com/callback-function/</link>
					<comments>https://biponnotes.iglyphic.com/callback-function/#comments</comments>
		
		<dc:creator><![CDATA[bipon68]]></dc:creator>
		<pubDate>Fri, 24 Jan 2020 17:01:07 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[synchronous]]></category>
		<guid isPermaLink="false">https://bipon.me/?p=419</guid>

					<description><![CDATA[<p>Callback function means that it is a function that executes after another function is executed. And that&#8217;s why it&#8217;s called callback function. #synchronous&#160;function #Asynchronous&#160;function #Infinity Loop Now what&#8217;s the callback job? We know about the asynchronous behavior of JavaScript. If JavaScript takes time to do a task, do not wait and move on to the&#8230;<a href="https://biponnotes.iglyphic.com/callback-function/" class="more-link">Continue reading <span class="screen-reader-text">Callback Function in JavaScript</span></a></p>
<p>The post <a href="https://biponnotes.iglyphic.com/callback-function/">Callback Function in JavaScript</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Callback function means that it is a function that executes after another function is executed. And that&#8217;s why it&#8217;s called callback function.</p>



<p> #synchronous&nbsp;function </p>



<pre class="wp-block-code"><code>    function synch(func){
      func("synchronous")
    }
    synch(alert)
    alert('Test')</code></pre>



<figure class="wp-block-image"><img width="472" height="331" src="https://i2.wp.com/bipon.me/wp-content/uploads/2020/01/1-4.png?resize=472%2C331&#038;ssl=1" alt="" class="wp-image-420" srcset="https://i1.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/1-4.png?w=472&amp;ssl=1 472w, https://i1.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/1-4.png?resize=300%2C210&amp;ssl=1 300w" sizes="(max-width: 472px) 100vw, 472px" data-recalc-dims="1" /></figure>



<p> #Asynchronous&nbsp;function </p>



<pre class="wp-block-code"><code>setTimeout(alert,1000, "Asynchronous");
    alert('Test')</code></pre>



<p>#<strong>Infinity Loop</strong></p>



<pre class="wp-block-code"><code>function _1(){
      console.log('First function')
      _2();
    }
    function _2(){
      console.log('Second function');
      _1();
    }
    _1();</code></pre>



<p>Now what&#8217;s the <code>callback </code>job? We know about the <code>asynchronous </code>behavior of JavaScript. If JavaScript takes time to do a task, do not wait and move on to the next code:</p>



<pre class="wp-block-code"><code>    const getCustomFunction = () => {
      setTimeout(function(){
        console.log('A function that takes some time');
      }, 3000)
    }
    const printAnotherFunction = () => {
      console.log('Another Function');
    }
    getCustomFunction();
    printAnotherFunction();</code></pre>



<p>Running this code will show the next as before, and the next one for <code>JavaScript asynchronous behavior</code>:</p>



<figure class="wp-block-image"><img loading="lazy" width="543" height="241" src="https://i2.wp.com/bipon.me/wp-content/uploads/2020/01/3-2.png?resize=543%2C241&#038;ssl=1" alt="" class="wp-image-427" srcset="https://i1.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/3-2.png?w=543&amp;ssl=1 543w, https://i1.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/3-2.png?resize=300%2C133&amp;ssl=1 300w" sizes="(max-width: 543px) 100vw, 543px" data-recalc-dims="1" /></figure>



<p>From the definition of a <code>callback </code>function, we know that it is executed after another function is executed. And so we can use this technique here by writing two functions individually, but we can do it by the <code>callback </code>at the exact time the function is called:</p>



<pre class="wp-block-code"><code>    const getCustomFunction = (callback) => {
      setTimeout(function(){
        console.log('A function that takes some time');
        callback();
      }, 3000)
    }
    const printAnotherFunction = () => {
      console.log('Another Function');
    }
    getCustomFunction(printAnotherFunction);</code></pre>



<p>We passed our function here as <code>an argument inside</code> our Main function call. And then I called it exactly where I needed it. This  <code>printAnotherFunction()</code> function here is the callback function. It will give us results like mind. Means one after another. It will wait exactly 3 seconds then give the result. But serial maintenance does. Promise first, the data will come from it, then run the callback function:</p>



<figure class="wp-block-image"><img loading="lazy" width="670" height="211" src="https://i0.wp.com/bipon.me/wp-content/uploads/2020/01/4-2.png?resize=670%2C211&#038;ssl=1" alt="" class="wp-image-428" srcset="https://i2.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/4-2.png?w=670&amp;ssl=1 670w, https://i2.wp.com/biponnotes.iglyphic.com/wp-content/uploads/2020/01/4-2.png?resize=300%2C94&amp;ssl=1 300w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></figure><p>The post <a href="https://biponnotes.iglyphic.com/callback-function/">Callback Function in JavaScript</a> first appeared on <a href="https://biponnotes.iglyphic.com">Bipon's Diary</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://biponnotes.iglyphic.com/callback-function/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">419</post-id>	</item>
	</channel>
</rss>
