<?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 Gayathri on Medium]]></title>
        <description><![CDATA[Stories by Gayathri on Medium]]></description>
        <link>https://medium.com/@sarveshgayu3?source=rss-f31a32b3d6aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5GZWy0iLr2pvewTNJWAR4w.jpeg</url>
            <title>Stories by Gayathri on Medium</title>
            <link>https://medium.com/@sarveshgayu3?source=rss-f31a32b3d6aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 19:24:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sarveshgayu3/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[Event Loop in JS]]></title>
            <link>https://sarveshgayu3.medium.com/event-loop-in-js-d02da3854763?source=rss-f31a32b3d6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d02da3854763</guid>
            <dc:creator><![CDATA[Gayathri]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 18:52:59 GMT</pubDate>
            <atom:updated>2021-07-13T18:52:59.005Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi folks !! Today we are going to see about event loop. This is just a content sharing…..over content is injurious to health so i just gave a small amount of content . Just read the content and live well!!!<br>First of all what is event loop ?<br><strong>Event loop is nothing but a built-in mechanism which handles the execution of multiple chunks of your program.</strong></p><p>Let’s dive into event loop:</p><p>consider the following code:<br> console.log(“hello”);<br> setTimeout(function cb(){<br> console.log(“inside timeout”);<br> },3000);<br> Console.log(“final”);</p><p><strong>Execution of the code:</strong><br>Firstly, the console.log(“hello”) moved to call stack(Reference:<a href="https://developer.mozilla.org/en-US/docs/Glossary/Call_stack">call stack</a>), then print it in console<br>Then setTimeout pushed inside the call stack, (setTimeout is a function not provided by js but by the browser.) So it moved to the webAPI [<em>web api is a thread that we can’t access just make calls to them</em>]from call stack <br>Browser immediately start the timer for call back function<br>Controls moved to console.log(“final”) and print it in console.<br>Finally our setTimeout comes into picture, once the time expired, call back function moved to the queue called <strong>task/callback queue</strong></p><p><strong>call back queue:<br></strong>A queue where the asynchronous code is enqueued. i.e,. The code return by the web api’s.</p><p>Then how call back function placed inside the call stack ?<br>Here only the event loop comes!!!</p><p><strong>EVENT LOOP:</strong><br>The main job of event loop is keep monitoring the call stack and callback queue. If the call stack is empty then event loop check the callback queue whether it contains task or not. If the callback queue contains task/function then event loop take the task from queue and push into the call stack and call stack immediately execute it.</p><p>In our code the cb() moved to the callback queue once the time expired. Event loop checks the call stack , if it’s empty then push cb() to call stack, then console.log(“inside timeout”) logged into console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*DMTahnhmkDiardJWahOmmQ.png" /><figcaption>Execution of call back function</figcaption></figure><p>suppose if we are using <strong>fetch</strong> (refer here: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"><strong><em>fetch</em></strong></a>)in our code, then what will happen ? don’t overthink. Just recall the setTimeout function execution above. Instead of waiting for the time to expire , browser wait for the response from server. Because we used fetch to get some response from the server for the given URL. After receiving response ,the fetch API have some function or some lines of code to execute. So, that function can be placed inside <strong>microtask queue</strong>. Then event loop start it’s work. But wait !! what is microtask queue??? we placed setTimeout callback function inside callback queue but fetch function placed inside micro task queue? yes, <strong>high priority</strong> task will be placed inside the micro task queue, <strong>low priority</strong> task will be placed inside the call back queue. Event loop always executes the tasks inside micro task queue then only execute the call back queue task.</p><p>consider if we have multiple tasks inside microtask queue and only one task inside the call back queue. Event loop checks the call back queue only after finish executing all the task inside the microtask queue.<br>But, here is the problem. microtask queue have multiple say 100 tasks but in call back queue have only one task. so task inside the call back queue wait for event loop to finish all the 100 task inside microtask queue. so task inside callback queue become starved.<br>Then next question !!! what is starvation?</p><p><strong>STARVATION:<br></strong>The process/task waits for long time to execute because of high priority task execution is called starvation. Sometime the low priority task [i.e,. in our case task inside call back queue] wait indefinitely.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d02da3854763" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chatbot using Javascript]]></title>
            <link>https://sarveshgayu3.medium.com/chatbot-using-javascript-7b188b207ae?source=rss-f31a32b3d6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b188b207ae</guid>
            <dc:creator><![CDATA[Gayathri]]></dc:creator>
            <pubDate>Sun, 02 May 2021 16:54:23 GMT</pubDate>
            <atom:updated>2021-05-02T16:54:23.575Z</atom:updated>
            <content:encoded><![CDATA[<p>Chatbot using Javascript</p><p>simple chatbot code using javascript:<br><strong>Here is my chatbot.html:</strong></p><p>&lt;html&gt;<br>&lt;head&gt;<br>&lt;script type=”text/javascript” src=”chatbot.js”&gt;&lt;/script&gt;<br>&lt;link rel=”stylesheet” href=”style.css”&gt;&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div class=”scroll centered”&gt;<br>&lt;p id=”textarea”&gt;&lt;/p&gt;<br>&lt;/div&gt;<br>&lt;div class=”userFields”&gt;&lt;input id=”msg” type=”text” placeholder=”type something…”&gt;&lt;button onclick=”replyToChat()”&gt;send&lt;/button&gt;&lt;/div&gt;&lt;/body&gt;<br>&lt;/html&gt;<br>In this I just use “input” field and “button”. After clicking the button the replyToChat function will be called to get a response.</p><p><strong>Here is my Js file:</strong></p><p>var words={<br> “hi”:”Hello”,<br> “how are you”:”Fine! and you?”<br>};</p><p>function replyToChat()<br>{<br> var userMessage=document.getElementById(“msg”).value.toLowerCase();<br> document.getElementById(“textarea”).innerHTML += “You:”+userMessage +”&lt;br&gt;”;<br> if(userMessage in words){<br> document.getElementById(“textarea”).innerHTML += “Bot:”+words[userMessage] +”&lt;br&gt;”;<br> }<br> else{<br> document.getElementById(“textarea”).innerHTML += “Bot:”+”I don’t understand &lt;br&gt;”;<br> }<br> document.getElementById(“msg”).value=””;<br>}<br>In replyToChat function I just use the “getElementById” to get the user typed value and used the object for reply. You can add your own data in words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*OD9GjlSlpFJtXcu221GpyQ.png" /><figcaption>Sample chatbot</figcaption></figure><p>Hope you understand! I’ll post next version of chatbot soon..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b188b207ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript execution]]></title>
            <link>https://sarveshgayu3.medium.com/javascript-execution-10aebd92c88d?source=rss-f31a32b3d6aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/10aebd92c88d</guid>
            <dc:creator><![CDATA[Gayathri]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 07:08:22 GMT</pubDate>
            <atom:updated>2021-02-09T07:08:22.643Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*6iC7bzQwWJYyuG0wDKyZfw.png" /></figure><p>Javascript is asynchronous and single thread language. I. e,. Every request handled one by one.<br>Every operation happened within execution context. It has 2 components.one is memory and another one is code.</p><p>In memory all the variable and functions are stored. In code component, every single line of code is executed one by one.<br>For example our java script code is like below,</p><p>var a=5; function sum(){ let b=5; let c=2; }</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*aXfboQbsYhagubXhXaqwaA.png" /></figure><p>once our javascript program ready to execute, our variable and function are stored in memory with undefined values. Then our first line code is executed the code section take the variable from memory part and assign the value to it. Next in our memory part value of ‘a’ changed from undefined to 5.The same will be happen for function. once all the execution is completed the code part will be cleared.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10aebd92c88d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>