<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by One Minute Coder on Medium]]></title>
        <description><![CDATA[Stories by One Minute Coder on Medium]]></description>
        <link>https://medium.com/@oneminutecoder?source=rss-802b2d52da0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uZ83EgrfN62L3Zdo</url>
            <title>Stories by One Minute Coder on Medium</title>
            <link>https://medium.com/@oneminutecoder?source=rss-802b2d52da0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 22:50:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oneminutecoder/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Callback Functions in JavaScript]]></title>
            <link>https://oneminutecoder.medium.com/understanding-callback-functions-in-javascript-087cf23d52f2?source=rss-802b2d52da0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/087cf23d52f2</guid>
            <category><![CDATA[javascript-callback]]></category>
            <category><![CDATA[callback-function]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[One Minute Coder]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 11:20:10 GMT</pubDate>
            <atom:updated>2025-04-17T11:21:54.924Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Understanding Callback Functions in JavaScript" src="https://cdn-images-1.medium.com/max/1024/1*iX9K3UIIQfuA-5WJg93AfA.png" /></figure><p>In JavaScript, you can use functions like regular values. You can store them in variables, pass them as arguments to other functions, or return them from functions. This feature makes callback functions possible.</p><pre>function sayHello() {<br>  console.log(&quot;Hello!&quot;);<br>}<br><br>function runFunction(fn) {<br>  fn(); <br>}<br>runFunction(sayHello);</pre><h3>What is a Callback Function?</h3><p>A callback function is a function that is passed as an argument to another function, and it is usually invoked inside that function to complete some kind of routine or action.</p><p>In simple terms:</p><blockquote><em>A callback is a function that gets called after another function finishes its task.</em></blockquote><h3>Basic Example</h3><pre>function greet(name, callback) {<br>  console.log(&quot;Hello, &quot; + name);<br>  callback();<br>}<br><br>function sayBye() {<br>  console.log(&quot;Goodbye!&quot;);<br>}<br>greet(&quot;Ali&quot;, sayBye);</pre><p><strong>Output:</strong></p><pre>Hello, Ali<br>Goodbye!</pre><p>Here, sayBye is passed as a callback and is called after greeting the user.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fr2tr7HCc-8E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dr2tr7HCc-8E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fr2tr7HCc-8E%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/703c56c361dfc5e49e68286ab9047419/href">https://medium.com/media/703c56c361dfc5e49e68286ab9047419/href</a></iframe><p><strong>Why Use Callbacks?</strong></p><p>Callbacks are mainly used to:</p><ul><li>Handle <strong>asynchronous operations</strong> (like data fetching)</li><li>Allow <strong>flexibility</strong> in how a function behaves</li><li>Avoid <strong>code repetition</strong></li></ul><h3>Callbacks in Asynchronous Code</h3><p>Callbacks are especially useful for <strong>asynchronous operations</strong> like reading files, making HTTP requests, or using timers.</p><pre>setTimeout(function () {<br>  console.log(&quot;This runs after 2 seconds&quot;);<br>}, 2000);</pre><p>The anonymous function here is a callback passed to setTimeout.</p><h3>Named vs Anonymous Callbacks</h3><p><strong>Named Callback:</strong></p><pre>function done() {<br>  console.log(&quot;Task finished.&quot;);<br>}<br>doSomething(done);</pre><p><strong>Anonymous Callback:</strong></p><pre>doSomething(function () {<br>  console.log(&quot;Task finished.&quot;);<br>});</pre><h3>Common Use Case: Array Methods</h3><pre>const numbers = [1, 2, 3, 4];</pre><pre>numbers.forEach(function (num) {<br>  console.log(num * 2);<br>});</pre><p>Here, the function passed to forEach is a callback executed for each element.</p><h3>Conclusion</h3><p>Callback functions are a powerful way to make JavaScript code more dynamic and responsive. They are essential for handling asynchronous behavior and for building flexible, reusable functions.</p><p>As you go deeper into JavaScript, you’ll also encounter <strong>Promises</strong> and <strong>async/await</strong>, which are modern ways of handling asynchronous code — often built on top of callbacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=087cf23d52f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>