<?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: Trishank Sharma</title>
    <description>The latest articles on DEV Community by Trishank Sharma (@trishank_sharma_ac493a8f0).</description>
    <link>https://dev.to/trishank_sharma_ac493a8f0</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%2F2620198%2F09f178ec-42bd-49f2-8a7b-dcd0f6768b4a.jpg</url>
      <title>DEV Community: Trishank Sharma</title>
      <link>https://dev.to/trishank_sharma_ac493a8f0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/trishank_sharma_ac493a8f0"/>
    <language>en</language>
    <item>
      <title>setTimeout() takes more time than given time in param</title>
      <dc:creator>Trishank Sharma</dc:creator>
      <pubDate>Thu, 02 Jan 2025 06:22:08 +0000</pubDate>
      <link>https://dev.to/trishank_sharma_ac493a8f0/settimeout-takes-more-time-than-given-time-in-param-1aii</link>
      <guid>https://dev.to/trishank_sharma_ac493a8f0/settimeout-takes-more-time-than-given-time-in-param-1aii</guid>
      <description>&lt;p&gt;setTimeout is not part of core JavaScript. Yes, you heard right. It is part of the web APIs provided by the browser (in a web environment) or the Node.js APIs in a server-side environment.&lt;br&gt;
As we all know, the setTimeout method takes the CB function as a parameter. The other parameter is the time in ms after which the CB must be executed.&lt;br&gt;
But wait, It is not necessary that setTimeout execute always at given time params. If our call stack or say main thread is blocked by any piece of code then setTimeout is immediately executed in the call stack after the blocking code is complete. Until then, it remains stored in the Browser Callback queue or Task Queue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("HELLO");
setTimeout(() =&amp;gt; console.log("Timeout executed"), 5000); //should be execute after 5sec
let start = new Date().getTime();
let end= start;
while (end &amp;lt; start + 10000){
  end= new Date.getTime();
} //This loop will block the main thread for 10sec
 console.log("Time Expire");

//output---
//HELLO
//Time Expire
//Timeout executed  (Immediately just after Time expire)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is one case also, what if we provide 0ms time in setTimeout. Is it execute in sequence manner like normal code execution.&lt;br&gt;
The answer is no because setTimeout is first go the CB queue unlike other function which execute immediately first in call stack.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>node</category>
    </item>
    <item>
      <title>Currying in JavaScript</title>
      <dc:creator>Trishank Sharma</dc:creator>
      <pubDate>Fri, 27 Dec 2024 06:20:05 +0000</pubDate>
      <link>https://dev.to/trishank_sharma_ac493a8f0/currying-in-javascript-f0f</link>
      <guid>https://dev.to/trishank_sharma_ac493a8f0/currying-in-javascript-f0f</guid>
      <description>&lt;p&gt;Currying is the pattern of writing the functional code more modular. In simple words.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Currying is the pattern where a function with multiple arguments is transformed into a series of functions, each taking a single argument.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of taking all arguments at once, the curried function takes the first argument, returns a new function that takes the next argument, and so on until all arguments are provided. The final function then returns the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Normal Function
 `function nonCurrying(param1, param2, param3){
  return param1 + param2 + param3
}`

// Curried Function

`function curried(param1){
   return function(param2){
    return function(param3){
      return param1 * param2 * param3
}}}

curried(10)(20)(30);
`





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

&lt;/div&gt;



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