<?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 Hemendra Khatik on Medium]]></title>
        <description><![CDATA[Stories by Hemendra Khatik on Medium]]></description>
        <link>https://medium.com/@aamchora?source=rss-50a1604e965f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w9PITqvCkokAZHCq_fyqzA.png</url>
            <title>Stories by Hemendra Khatik on Medium</title>
            <link>https://medium.com/@aamchora?source=rss-50a1604e965f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 12:34:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aamchora/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[You’re Not Late. You’re Just Getting Started at the Right Time]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">At some point, almost everyone feels it.</p><p class="medium-feed-link"><a href="https://medium.com/@aamchora/youre-not-late-you-re-just-getting-started-at-the-right-time-f8c948dd8af4?source=rss-50a1604e965f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@aamchora/youre-not-late-you-re-just-getting-started-at-the-right-time-f8c948dd8af4?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8c948dd8af4</guid>
            <category><![CDATA[building]]></category>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[self-awareness]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Tue, 28 Apr 2026 06:50:50 GMT</pubDate>
            <atom:updated>2026-04-28T06:50:50.453Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[I Stopped Writing Code… and Somehow Became a Better Engineer]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">There&#x2019;s a strange shift happening in tech right now.
Not loud. Not obvious. But if you&#x2019;re paying attention &#x2026;you can feel it.</p><p class="medium-feed-link"><a href="https://medium.com/@aamchora/i-stopped-writing-code-and-somehow-became-a-better-engineer-cc4145d02aa9?source=rss-50a1604e965f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@aamchora/i-stopped-writing-code-and-somehow-became-a-better-engineer-cc4145d02aa9?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4145d02aa9</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[agi]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Sun, 26 Apr 2026 14:26:12 GMT</pubDate>
            <atom:updated>2026-04-26T14:26:12.987Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Want to code anything?]]></title>
            <link>https://medium.com/@aamchora/want-to-code-anything-a830694b5ad0?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a830694b5ad0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Mon, 18 Sep 2023 07:23:50 GMT</pubDate>
            <atom:updated>2023-09-22T14:01:24.868Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever met or seen someone who knows so much about coding that he can literally build anything?</p><p>Did you ever wonder? How one can person know so much about coding?</p><p>Do they have superpowers?</p><p>Let’s figure out</p><p>But before we proceed can you answer the below question?</p><p>How one person who knows how to ride a bike can ride any bike in the world?</p><p>(if you can’t relate just think of another example)</p><p>Absolutely, it does take a little effort, but it’s hardly anything at all.</p><p>For example, whenever I hop on a new bike, I simply ask the other person, How many gears does it have? and that’s it.</p><p>Did you notice I didn’t ask anything else? I just asked about the gears.</p><p>But why?</p><p>I could ask how to balance a bike?</p><p>How to sit on a bike?</p><p>When to use the break and when to increase speed.</p><p>I didn’t ask because I already knew from my previous experience of riding a bike. How to do all of that. It’s very similar.</p><p>I just asked and learned about what is new.</p><p>Similarly, In Software development, We have a similar process of building any kind of software. And for every new software like android app, web app, ios, app, chrome extension, etc. You just need to learn what is new rest is similar.</p><p>You just need to focus on the process of building the software.</p><p><strong>TIP:</strong> When you’re just starting out, Do not get into the depth of anything, and stay away from jargon.</p><p>Just focus on building blocks and how to use them to create meaningful small apps.</p><p>I would recommend learning <strong>HTML, CSS, and JavaScrip</strong>t. That&#39;s all you need to create a web app, iOS app, android app literally anything.</p><p>So far I’ve built 3 Android and IOS apps and more than 20 web apps and integrations including Chrome extension, discord bot, canva plugin, etc. Just by using <strong>HTML, CSS, and JavaScript</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2l__P-dnnQ1TxGUY8lGHyg.gif" /></figure><p>After you know the basics, You need to learn the process of building software.</p><p>The very first thing you would do before writing a single line of code is forget you’re a coder and don’t try to use whatever you’ve learned so far.</p><p>Consider yourself a noob and just start imagining. How your software would look like and how you’re gonna use it.</p><p>Trust me and just focus on imagining.</p><p>Imagine the following things in the same order. Order is very important here.</p><ol><li>How the UI of your Software would look like</li><li>Use HTML and CSS to create the UI</li><li>How you’re interacting with your app. Like clicking, scrolling, double taps, etc. Just think about the interactions.</li><li>Use JavaScript to handle interactions.</li><li>Now very important part. Think about the app’s flow. Which UI part will come first? When you interact with certain parts of your software. What will happen?</li><li>Suppose you’re building a social media app then you won’t work on the user profile screen first. You’ll create a landing page first then the user signup page, login page, and then only you’ll create the profile page.</li></ol><p>Here most of the beginners fail they start creating and thinking about the app randomly.</p><p>You might be wondering why it’s a bad thing.</p><p>You need to understand this simple thing.</p><p>Programming is a tool to create magic. it’s not like you’ll do anything and magically things will happen and your software will be ready.</p><p>How a magician uses a deck of cards (a tool) and uses it in a way to create magic. We do the same.</p><p>If don’t follow the app’s flow then just answer the below question.</p><p><strong>How would you get the user details like username and email to display on the profile page?</strong></p><p>Always remember, you can’t use something you don’t have access to.</p><p>You’ll get user details from either the signup page or the login page. and in order to make the login page work you need to work on the signup page first.</p><p>I hope you get the point. How important flow is.</p><p>Lastly, follow these rules(super important).</p><ol><li>First thing first don’t try to be smart and think you’re a genius. You’ll fail so measurably. (Trust me I learned this very hard way)</li><li>Create 5 simple projects like the todo app and tic tac toe app.</li><li>You can follow any YouTube tutorial but make sure you’re following the tutorials exactly. If the instructor uses the color <strong>red</strong> then don’t try to be smart and use <strong>green</strong> instead.</li><li>Make sure you’re following the latest tutorial because, in old tutorials, You may face dependency issues. As a beginner you’ll get confused as to why your code is not working even code is exactly similar to the instructor&#39;s. In tech, things change really quickly.</li><li>Once you’ve successfully created 5 simple projects by following the tutorials. Now you can use your brain and try to change small things in the projects you’ve built so far.</li><li>Don’t worry about the backend part. once you master the frontend part, You’ll get the backend part easily. As you would already know how to consume the backend in the frontend. You’ll be a great backend developer.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a830694b5ad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What exactly Just in time (JIT) compilation is in JavaScript?]]></title>
            <link>https://medium.com/@aamchora/what-exactly-just-in-time-jit-compilation-is-in-javascript-f7aea482843f?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7aea482843f</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Wed, 27 Jul 2022 11:08:41 GMT</pubDate>
            <atom:updated>2022-07-27T11:13:27.535Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript engines use the JIT(just in time) compiler to execute the code.</p><p>I know you must be wondering what the hell is JIT and how it works?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KXWuSh_4SycAyPbkYPmtsg.gif" /></figure><p><strong>let’s understand JIT</strong></p><p>But before understanding JIT, let’s change the topic for a while, and try to understand what compiler and interpreter are and how they work?</p><p><strong>Compiler</strong></p><p>The source code is converted into machine code once and then gets executed.</p><figure><img alt="compiler" src="https://cdn-images-1.medium.com/max/1024/1*eI8TZqEQLXc8BAOmMfOxBQ.png" /></figure><p><strong>Pros</strong></p><ul><li>Suppose we have a loop that runs 40 times, we do not need to translate the same code again and again. The time it saves is huge.</li><li>The converted code will be more efficient cause we have more time for optimization.</li></ul><p><strong>Cons</strong></p><ul><li>It takes a little bit more time to start up because it has to go through that compilation step at the beginning.</li></ul><p><strong>Interpreter</strong></p><p>Interpreters are quick. We don’t have to go through that whole compilation step before execution. It just starts translating the first line and then executes it.</p><figure><img alt="interpreter" src="https://cdn-images-1.medium.com/max/1024/1*JtEnOTSbw1GnS8osIDv6Lg.png" /></figure><p><strong>Pros</strong></p><ul><li>Fast start-up times are characteristic of interpreters. That’s why browsers used JavaScript interpreters in the beginning.</li></ul><p><strong>Cons</strong></p><ul><li>When you’re running the same code more than once. For example, if you’re in a loop. Then you have to do the same translation over and over and over again.</li><li>The code will be less efficient than the compiler cause we have less time for optimization.</li></ul><p><strong>Just In Time(JIT) compiler</strong></p><p>To get rid of the interpreter’s inefficiency, “<em>the interpreter keeps retranslating the same code every time it goes through the loop</em>”.</p><p>In the JIT compiler, we have a new component called a monitor (aka a profiler). That monitor watches the code as it runs and</p><ul><li>Identify the hot or warm components of the code eg: repetitive code.</li><li>Transform those components into machine code during run time.</li><li>Optimize the generated machine code.</li><li>Hot swap the previous implementation of the code.</li></ul><figure><img alt="Just in time (JIT) compiler" src="https://cdn-images-1.medium.com/max/1024/1*ZaPIg6zLnyFdIWjvr2L6Mg.png" /></figure><p>In short Just in time compiler is nothing but a combination of an interpreter and a compiler.</p><p>I hope you found it helpful, and if you have any questions, please let me know.</p><p><em>Feel proud to correct me if I’m wrong:)</em></p><p><a href="https://twitter.com/AamChora">Twitter</a> || <a href="https://www.linkedin.com/in/hemendrakhatik/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7aea482843f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to upload file using ExpressJS(NodeJS) — Multer]]></title>
            <link>https://medium.com/@aamchora/how-to-upload-file-using-expressjs-nodejs-multer-14b5890b9a26?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/14b5890b9a26</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 09:57:55 GMT</pubDate>
            <atom:updated>2022-07-11T09:57:55.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to upload file using ExpressJS(NodeJS) — Multer</h3><p>It took me 4-days and 100+ attempts to solve this simple issue of uploading a file using node.</p><p>And the moment I got it right, I was like…phewww</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*x66jw-AsUqSjKGKC.gif" /></figure><p>Here is how I solved this issue.</p><p>By creating a -</p><ul><li>Simple node server.</li><li>Middleware to process files.</li><li>POST route to accept files.</li><li>Route to serve files.</li><li>Middleware to Handle CORS issue(you won’t get this issue in postman).</li></ul><p><strong>Node server using express</strong></p><ul><li>Initialize the project using below command</li></ul><blockquote>node init</blockquote><ul><li>Install the required dependencies.</li></ul><blockquote>using npm -&gt; npm i express dotenv</blockquote><blockquote>using yarn -&gt; yarn add express dotenv</blockquote><ul><li>Create server.js and paste below code</li></ul><pre>const express = require(&quot;express&quot;);<br>const dotenv = require(&quot;dotenv&quot;);</pre><pre>const app = express();</pre><pre>dotenv.config(); // &lt;-- To use.env file</pre><pre>app.use(express.json());<br>/*<br>express.json() middleware helps us to parse all HTTP requests</pre><pre>like --&gt; req.body</pre><pre>And express.json() middleware always should be at the top</pre><pre>*/</pre><pre>const PORT = process.env.PORT || 5000;<br>app.listen(<br>  PORT,<br>  console.log(`Server is up and running on port ${PORT}`)<br>);</pre><p>Now run the node server using below command</p><blockquote>node server.js</blockquote><p><strong>Create a middleware to process files.</strong></p><p>Install the dependencies</p><blockquote>using npm -&gt; npm i multer</blockquote><blockquote>using yarn -&gt; yarn add multer</blockquote><p>Create processFile.js file and paste below code in it and create upload folder to store uploaded files in it.</p><pre>const multer = require(&quot;multer&quot;);<br>const path = require(&quot;path&quot;);</pre><pre>const MIME_TYPES = {<br>  &quot;image/jpg&quot;: &quot;jpg&quot;,<br>  &quot;image/jpeg&quot;: &quot;jpg&quot;,<br>  &quot;image/png&quot;: &quot;png&quot;,<br>  // you can add more here<br>};</pre><pre>const storage = multer.diskStorage({<br>  destination: (req, file, callback) =&gt; {<br>    callback(null,path.join(__dirname, &#39;./upload&#39;));<br>   // Note ./upload path should be relative. Change this path according to your folder structure<br>  },<br>  filename: (req, file, callback) =&gt; {<br>    const name = file.originalname.split(&quot; &quot;).join(&quot;_&quot;);<br>    const extension = MIME_TYPES[file.mimetype];<br>    callback(null, name + Date.now() + &quot;.&quot; + extension);<br>  },<br>});</pre><pre>const processFile = multer({ storage: storage }).single(&quot;<strong>file</strong>&quot;); //&lt;--here `<strong>file</strong>` key<br>/*<br>Look at the last example of how we will use `<strong>file</strong>` key to <br>upload files using form data and postman.</pre><pre>For accepting multiple files change above line to </pre><pre>const processFile = multer({ storage: storage }).array(&#39;<strong>file</strong>&#39;, 12);<br>Where 12 is the number of files you want to accept.</pre><pre>*/</pre><pre>module.exports = processFile;</pre><p><strong>Create a POST route to accept files.</strong></p><p>Paste below code in server.js file</p><p><em>For uploading single file</em></p><pre>const processFile = require(&quot;./processFile&quot;);</pre><pre>app.post(&quot;/api/upload&quot;, processFile, (req, res, next) =&gt; {</pre><pre>  const url = req.protocol + &quot;://&quot; + req.get(&quot;host&quot;);</pre><pre>  const file = url + &quot;/files/&quot; + req.file.filename;</pre><pre>  res.status(201).json({<br>    message: &quot;Success&quot;,<br>    file: file,<br>  });<br>});</pre><p><em>For uploading multiple files</em></p><pre>const processFile = require(&quot;./processFile&quot;);</pre><pre>app.post(&quot;/api/upload&quot;, processFile, (req, res, next) =&gt; {<br>  const files = []<br>  const url = req.protocol + &quot;://&quot; + req.get(&quot;host&quot;);<br>  req.files.forEach(file=&gt;{<br>    const file_url = url + &quot;/files/&quot; + file.filename;<br>    files.push({<br>      url: file_url,<br>    });<br>  })</pre><pre>  res.status(201).json({<br>    message: &quot;files saved successfully!&quot;,<br>    files,<br>  });<br>});</pre><p>So far you would be able to store files in your upload folder but you can&#39;t access files using links you are receiving in the response and for that, we need to serve those files.</p><p><strong>Serve uploaded files</strong></p><p>Add below code in server.js file and restart the server.</p><pre>const path = require(&quot;path&quot;);</pre><pre>app.use(&quot;/files&quot;, express.static(path.join(__dirname, &quot;upload&quot;)));</pre><p>Now you should be able to see the files if you visit the links.</p><p><strong>CORS (Cross-Origin Resource Sharing)</strong></p><p><strong><em>Note:</em></strong> You won’t face this issue in the postman but in your client-side app you will face this issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*krHYy789qahn7c5b.png" /></figure><p>To resolve the CORS issue</p><ul><li>Create a cors middleware.</li><li>Apply cors middleware at the top of your file</li></ul><pre>const cors = (req, res, next) =&gt; {<br>  const origin = &quot;*&quot;; // &lt;-- change this in production<br>  res.setHeader(&quot;Access-Control-Allow-Origin&quot;, origin);<br>  res.setHeader(<br>    &quot;Access-Control-Allow-Headers&quot;,<br>    &quot;Origin, X-Requested-With, Content, Accept, Content-Type, Authorization&quot;<br>  );<br>  res.setHeader(<br>    &quot;Access-Control-Allow-Methods&quot;,<br>    &quot;GET, POST, PUT, DELETE, PATCH, OPTIONS&quot;<br>  );<br>  next();<br>};</pre><pre>app.use(cors); // &lt;-- Should be at the top</pre><p><strong>Upload file from client</strong></p><pre>const data = new FormData();<br>  data.append(&quot;file&quot;, FILE_URI);</pre><pre>  fetch(&quot;http://localhost:5000/api/upload&quot;, {<br>    method: &quot;post&quot;,<br>    body: data,<br>  })<br>  .then((res) =&gt; res.json())<br>  .catch((err) =&gt; {<br>     console.log(err);<br>  });</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pBHsYJb68vF4qGFc.png" /></figure><p>And That’s how I solved this issue. Let me know if you have any doubt.</p><p><em>follow me for more such blog posts.</em></p><p><a href="https://twitter.com/AamChora">Twitter</a> || <a href="https://www.linkedin.com/in/hemendrakhatik/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14b5890b9a26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functions are Objects in JavaScript]]></title>
            <link>https://medium.com/@aamchora/functions-are-objects-in-javascript-a25719e8443?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a25719e8443</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 09:24:38 GMT</pubDate>
            <atom:updated>2022-07-06T09:24:38.569Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Whattttt???</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/0*zNaepnLLyF6Im5Ca.gif" /></figure><p><strong>Yes, You read that correctly.</strong></p><p>Let’s deep dive into this topic.</p><p>Before we get into a serious drill, Let’s quickly revise objects and functions in JavaScript.</p><p><strong>Object:</strong></p><p>Objects in JavaScript are nothing but a non-primitive type data structure. We can define an object using curly brackets and put key-value pairs separated by a comma in it.</p><pre>const user = {<br>   name:&quot;Hemendra&quot;,<br>   nickname:&quot;Hemu&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>}</pre><pre>user.city = &quot;Bhilwara&quot; // add new value in existing object</pre><pre>user.city = &quot;Jaipur&quot; // update new value in existing object</pre><pre>console.log(user.name);</pre><pre>/*<br>output</pre><pre>Hemendra</pre><pre>*/</pre><pre>console.log(user);</pre><pre>/*<br>output</pre><pre>{<br>   name:&quot;Hemendra&quot;,<br>   nickname:&quot;Hemu&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>   city:&quot;Jaipur&quot;<br>}<br>*/</pre><p>Read more about <a href="https://medium.com/@aamchora/javascript-objects-in-depth-6faba91eab50"><strong>objects in depth.</strong></a></p><p><strong>Function</strong></p><p>Unlike other programming languages, JavaScript has implemented the functions very differently.</p><p>Let’s have a look</p><p><strong>Definition:</strong></p><p>A function is a block of organized code that performs a specific task.</p><p><strong>Advantages of functions</strong></p><ul><li>Functions make your program easier to read, understand, and debug.</li><li>Functions can make a program smaller by eliminating repetitive code.</li></ul><p>Now you would be wondering, What’s the difference then?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*UglJCGdhcRYeKq4f.gif" /></figure><p>In JavaScript, functions are<strong> first-class objects</strong>, because they can have properties and methods just like any other object. Every JavaScript function is actually a<strong> Function object.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*g-aV18pMGVn6MUMm.gif" /></figure><p>Let’s see how we define functions in JavaScript first</p><pre>function sum(a,b){<br> return a+b;<br>}</pre><pre>const res = sum(2,4);</pre><pre>console.log(res); // outputs -&gt; 6</pre><p>Above we have created a function named sum which adds two numbers.</p><p>But as I said earlier, is the sum function created above also an object? can we add properties and values to the sum function as we did in the user object above?</p><p>let’s see this in action</p><pre>function sum(a,b){<br> return a+b;<br>}</pre><pre>sum.help = &quot;use this function to add two numbers&quot;;<br>// like an object we have added help key and it&#39;s value to the above function.</pre><pre>// will work as before<br>const res = sum(3,6);<br>console.log(res) // outputs --&gt; 9</pre><pre>// but now </pre><pre>console.log(sum.help) <br>// outputs --&gt; use this function to add two numbers</pre><p>Let’s verify if the sum function is an instance of an object or not.</p><pre>function sum(a,b){<br> return a+b;<br>}</pre><pre>console.log(sum instanceof Function); // true<br>console.log(sum instanceof Object); // true</pre><pre>let name = &quot;Hemendra&quot;<br>console.log(name instanceof Object); // false</pre><p>And Voila, It proves that the functions are objects in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*7gr4qpvFYl8Z9y5u.gif" /></figure><p><em>follow me for more such blog posts.</em></p><p><em>Let me know if this blog was helpful.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a25719e8443" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is throttling in JavaScript?]]></title>
            <link>https://medium.com/@aamchora/what-is-throttling-in-javascript-b9795daaa2ad?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9795daaa2ad</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 11:44:18 GMT</pubDate>
            <atom:updated>2022-07-01T11:44:18.066Z</atom:updated>
            <content:encoded><![CDATA[<p>Again a jargonish word, but let me demystify it for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*QR6Uz_n2dCxXQvlr.gif" /></figure><p>It’s nothing but a simple technique we use to prevent unnecessary function calls to improve app’s performance.</p><p>Unlike <a href="https://medium.com/@aamchora/what-is-debouncing-in-javascript-c3b32c55b66d">Debouncing</a>, here we block a function call for a particular time if it’s been executed recently. Or we could also say that throttling ensures a function call regularly at a fixed rate.</p><p>Let’s look at the below example,</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>    &lt;head&gt;<br>        &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>        &lt;title&gt;Throttling&lt;/title&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;button class=&quot;btn&quot;&gt;Click here&lt;/button&gt;<br>        &lt;script src=&quot;index.js&quot;&gt;&lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>let count = 0;<br>function submitData(query){<br>   // some api call<br>   console.log(&quot;result&quot;,count++)<br>}</pre><pre>document.querySelector(&quot;.btn&quot;).addEventListener(&quot;click&quot;,()=&gt;{<br>submitData();<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*RXOm27Dp4DHLnlON.png" /></figure><p>In the above example, if you click 10 times in 2000ms, Function will be called 10 times, as you can clearly see in the above example.</p><p>It’s a very expensive operation, and as dev, our job is to make operations as cheap as possible.</p><p>Let’s see how throttling helps us to make these operations cheaper.</p><pre>function throttle(fn,delay){<br>  let last = 0;<br> /*  <br>here ...args is optional I&#39;ve used this in case, if you <br>want to pass some parameters you can use ...args<br>*/ <br>  return (...args)=&gt;{<br>    const now = new Date().getTime();<br>    if(now - last &lt; delay){<br>      return;<br>    }<br>   last = now;<br>   return fn(...args)<br>  }</pre><pre>}</pre><pre>const magicFunction = throttle(submitData,1000);</pre><pre>let count = 0;<br>function submitData(){<br>   // some api call<br>   console.log(&quot;result&quot;,count++)<br>}</pre><pre>document.querySelector(&quot;.btn&quot;).addEventListener(&quot;click&quot;,magicFunction);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*dBFf9n-234hTCHDl.png" /></figure><p>Now, if you click 10 times in 2000ms, Function will be called 2 times only, as you can see in the code. We have blocked the function call for 1000ms.</p><p><em>That’s how we can implement the </em><strong><em>throttling technique</em></strong><em> to </em><strong><em>improve our app’s performance</em></strong></p><p><strong><em>follow me for more such blog posts.</em></strong><em><br>Let me know if this blog was helpful.</em></p><p><a href="https://twitter.com/AamChora">Twitter</a> || <a href="https://www.linkedin.com/in/hemendrakhatik/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9795daaa2ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is debouncing in JavaScript?]]></title>
            <link>https://medium.com/@aamchora/what-is-debouncing-in-javascript-c3b32c55b66d?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3b32c55b66d</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Tue, 28 Jun 2022 08:41:07 GMT</pubDate>
            <atom:updated>2022-06-28T08:41:07.916Z</atom:updated>
            <content:encoded><![CDATA[<p>While building an app using JavaScript. We may need to call the function many times to achieve the desired result.</p><p>Some examples are</p><ul><li>While scrolling or resizing the screen you would want to compute something.</li><li>Sometimes we may need to display quick results as user types in the input field.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xngCELcmnm6C-Joh.png" /></figure><p>Let’s see, how we usually write code to achieve the desired result.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>    &lt;head&gt;<br>        &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>        &lt;title&gt;Debouncing&lt;/title&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;input class=&quot;search&quot; type=&quot;text&quot; placeholder=&quot;search&quot;/&gt;<br>        &lt;script src=&quot;index.js&quot;&gt;&lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>let count = 0;<br>function search(query){<br>   // some api call<br>   console.log(&quot;result&quot;,count++)<br>}</pre><pre>document.querySelector(&quot;.search&quot;).addEventListener(&quot;input&quot;,(e)=&gt;{<br>search(e.target.value);<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*7enNMPJN0ML3yOuz.png" /></figure><p>In the above example, If I search for a laptop, The function search will be called 6 times. Which is <strong>an inefficient way</strong> of calling a function. And it is <strong>very expensive</strong> for JavaScript.</p><p>You must be wondering what do you mean by <strong>expensive for JavaScript</strong>?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*yjylNwAe_kWB3AxY.gif" /></figure><p><a href="https://medium.com/@aamchora/what-exactly-javascript-is-ffefc0cef517">JavaScript is a synchronous single-threaded language</a>. Which means we have a single <strong>callstack</strong> to execute everything. And because it is single-threaded, we should not block the thread by calling functions unnecessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*pd1ecTlUy6HNk8m_.gif" /></figure><p><strong>But wait …</strong></p><p>How do we prevent unnecessary function calls to improve performance?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*2EARxTR-6oEt8YYs.gif" /></figure><p>Here, the concept of <strong>debouncing</strong> kicks into the picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*QpqD51O2sbxDR2cn.gif" /></figure><p><strong>Debouncing</strong> is a technique used to improve the browser’s performance. It ensures that time-consuming tasks do not fire so often, In other words, it limits the rate at which a function gets invoked.</p><p>Let’s re-write the above code using <strong>Debouncing technique</strong>.</p><pre>let count = 0;<br>function search(query){<br>   // some api call<br>   console.log(&quot;result&quot;,count++)</pre><pre>}</pre><pre>const magicFunction = debounce(search,300);</pre><pre>function debounce(func, delay){<br>  let timer;<br>  return function(...args) {<br>    clearTimeout(timer);<br>    timer = setTimeout(() =&gt; {<br>      func(...args);<br>    }, delay);<br>  };<br>}</pre><pre>document.querySelector(&quot;.search&quot;).addEventListener(&quot;input&quot;,(e)=&gt;{<br>  magicFunction(e.target.value);<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*3hlx3_VyF1a130AR.png" /></figure><p>The idea behind debouncing technique is that we <strong>do not call function during the event</strong> but after the event.</p><p>In the above example, We can clearly see.</p><p><strong>debounce</strong> is a <strong>higher order function(HOF)</strong>. Which takes two parameters the first parameter will be a function and the second will be a delay.</p><p>If the delay between two keystrokes is less than 300ms, function will not execute and setTimeout will be destroyed. And if the delay is more than 300ms, then only function will execute.</p><p><em>That’s how we can implement the </em><strong><em>debouncing technique</em></strong><em> to </em><strong><em>improve our app’s performance</em></strong></p><p><strong><em>follow me for more such blog posts.</em></strong><em><br>Let me know if this blog was helpful.</em></p><p><a href="https://twitter.com/AamChora">Twitter</a> || <a href="https://www.linkedin.com/in/hemendrakhatik/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3b32c55b66d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What exactly JavaScript is?]]></title>
            <link>https://medium.com/@aamchora/what-exactly-javascript-is-ffefc0cef517?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffefc0cef517</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 19:24:21 GMT</pubDate>
            <atom:updated>2022-06-26T20:14:12.438Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Definition</strong></p><p>JavaScript is a synchronous <strong>single-threaded</strong> scripting language that was initially meant to run on the client-side(web browsers). But nowadays, we can run JavaScript on the server-side as well.</p><p>But wait, What does it mean by synchronous and single-threaded?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*K9-ddCBA_GLT5f8x.gif" /></figure><h3>Let’s deep dive into it</h3><p><strong>Synchronous</strong></p><p>In English, it simply means that something is happening at the same time. And in terms of programming language, it simply means the code will execute in order line by line.</p><p>EG:</p><pre>console.log(&quot;one&quot;);<br>console.log(&quot;two&quot;);<br>console.log(&quot;three&quot;);</pre><pre>/*<br>The above code will execute in below order</pre><pre>one<br>two<br>three</pre><pre>*/</pre><p>But, sometimes you might encounter some code that will run asynchronously in JavaScript.</p><p>EG:</p><pre>console.log(&quot;one&quot;);</pre><pre>function magicFunction(){<br>  console.log(&quot;It&#39;s magic&quot;);<br>}</pre><pre>setTimeout(magicFunction,5000);</pre><pre>console.log(&quot;two&quot;);</pre><pre>/*<br>The above code will output the below result</pre><pre>one<br>two<br>undefined<br>It&#39;s magic --&gt; will display this after 5000ms.</pre><pre>*/</pre><p>Now you would be wondering what the hell is happening, you just have read that JavaScript is a synchronous language??</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*T3pa16JGxA84ZaqA.gif" /></figure><p>Let’s understand this more deeply why and how.</p><p>In the above example, setTimeout will execute asynchronously.</p><p>But what if I tell you that — <strong>setTimeout</strong> is not a part of the JavaScript language itself instead it’s a part of the browser’s <strong>web API</strong>.</p><p>Some examples of browser APIs are fetch, setInterval, DOM methods etc.</p><p>To make JavaScript more powerful on the client-side, browser JS-Engine attaches <strong>browser APIs</strong> with JavaScript and it will work like normal JavaScript.</p><p>So it means JavaScript is a <strong>synchronous language only</strong>. There are some other wrappers around it that make JavaScript run asynchronously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*xXfZwtxFT-eOae2Q.gif" /></figure><p>Okay, but what does it mean by single-threaded?</p><p><strong>Single-thread</strong></p><p>It simply means we have a single thread or a callstack to execute a JavaScript code. And we should not block this thread or else your app will crash and you won’t be able to perform another task while one task is executing.</p><p>In the above example, we saw that setTimeout was running asynchronously.</p><p>But here it won’t block the main thread. It will <strong>execute outside the callstack</strong>.</p><p>After timeout, <strong>callback function inside the seTimeout</strong> will wait in <strong>callback queue</strong> till the <strong>callstack gets empty</strong>.</p><p>An Event loop constantly keeps checking whether the <strong>callstack</strong> is empty or not. As soon as it gets empty event loop put <strong>callback function</strong> from <strong>callback queue</strong> to <strong>callstack</strong> and it gets executed.</p><figure><img alt="callstack" src="https://cdn-images-1.medium.com/max/880/0*hIdpt0FSrJzsQoZv.png" /></figure><p>And there you go … 🤗🤗🤗</p><figure><img alt="What javaScript is" src="https://cdn-images-1.medium.com/max/880/0*niI1Aeh4ACY1_Voc.gif" /></figure><p>Now you know what exactly JavaScript is.</p><p><strong><em>follow me for more such blog posts.</em></strong><em><br>Let me know if this blog was helpful.</em></p><p><a href="https://twitter.com/AamChora">Twitter</a> || <a href="https://www.linkedin.com/in/hemendrakhatik/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffefc0cef517" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript objects in depth.]]></title>
            <link>https://medium.com/@aamchora/javascript-objects-in-depth-6faba91eab50?source=rss-50a1604e965f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6faba91eab50</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[advanced-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hemendra Khatik]]></dc:creator>
            <pubDate>Fri, 24 Jun 2022 01:35:41 GMT</pubDate>
            <atom:updated>2023-02-21T05:38:40.488Z</atom:updated>
            <content:encoded><![CDATA[<p>Being a JavaScript developer, you might be aware of the fact that we can’t build any large-scale app without dealing with Objects.</p><p><strong>In JavaScript, Everything is an Object.</strong></p><p>Lets, Deep dive into JavaScript Objects.</p><p><strong>Object:</strong> Objects in JavaScript are nothing but a non-primitive type data structure. We can define an object using curly brackets and put key-value pairs separated by a comma in it.</p><p>EG:</p><pre>const user = {<br>   name:&quot;Hemendra&quot;,<br>   nickname:&quot;Hemu&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>   city:&quot;bhilwara&quot;<br>}</pre><h3>CRUD operations on an object</h3><p><strong>Create</strong></p><pre>let student = {}; // an empty array</pre><pre>student.name = &quot;Hemendra Khatik&quot;; <br>//important -&gt; student[&quot;name&quot;]=&quot;Hemendra Khatik&quot; is also valid</pre><pre>student.branch = &quot;CSE&quot;;<br>student.age = 25;</pre><pre>console.log(student); // will print the below structure<br>/*<br>{<br>   name:&quot;Hemendra Khatik&quot;,<br>   branch:&quot;CSE&quot;,<br>   age:25<br>}<br>*/</pre><p>or all key values at once</p><pre>let user = {<br>   name:&quot;Hemendra&quot;,<br>   nickname:&quot;Hemu&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>   city:&quot;bhilwara&quot;<br>}</pre><p><strong>Read</strong></p><p>We use . operator to access the values of an object.</p><pre>user.name; // to access the &quot;Hemendra&quot;.<br>user.city; // to access the &quot;bhilwara&quot;.<br>user.username; // will be undefined because it is not present in the user object.</pre><p>We can also access properties of an object using square brackets.</p><pre>user[&quot;name&quot;];    // to access the &quot;Hemendra&quot;.<br>user[&quot;city&quot;];    // to access the &quot;bhilwara&quot;.</pre><p><strong>Update</strong></p><p>Update an object.</p><pre>student.age = 21; // now age is changed from 25 to 21</pre><p><strong>Delete</strong></p><p>Delete key from an object.</p><pre>delete student.name; // to delete the name key from student object</pre><h3>Other Helpful methods</h3><p>print the keys only from an object.</p><pre>const user = {<br>   username:&quot;aamchora&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>};</pre><pre>Object.keys(user);<br>/* <br>Above expression returns an array containing <br>keys only from an object [&quot;username&quot;, &quot;email&quot;]<br>*/</pre><p>print the values only from an object.</p><pre>const user = {<br>   username:&quot;aamchora&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>};</pre><pre>Object.values(user);<br>/* <br>Above expression returns an array containing <br>values only from an object [&quot;aamchora&quot;, &quot;hi@aamchora.space&quot;]<br>*/</pre><p>freeze the JavaScript object</p><pre>const user = {<br>   username:&quot;aamchora&quot;,<br>   email:&quot;hi@aamchora.space&quot;,<br>};</pre><pre>Object.freeze(user);<br>/* <br>Above expression freezes the object. <br>It means we cannot add, remove or update its properties.<br>It will not throw any error unless you are in strict mode but<br>there will be no effect of value change on your object.<br>*/</pre><pre>user.username = &quot;NewUserName&quot;; // --&gt; will not work<br>user.newKey = &quot;xyz&quot;; // --&gt; will not work<br>delete user.email; // --&gt; will not work</pre><pre>console.log(user);<br>/*<br>{<br>  username:&quot;aamchora&quot;,<br>  email:&quot;hi@aamchora.space&quot;,<br>}<br>*/</pre><h3>Cloning an object</h3><blockquote><em>You can not copy non-primitive type data structure as you copy primitive type data structure.</em></blockquote><p>EG: Primitive type data structure.</p><pre>let a = 10;<br>let b = a;<br>b= b + 1;<br>console.log(a) // 10<br>console.log(b) // 11</pre><p>EG: Non-Primitive type data structure.</p><pre>let obj = {<br> a:10;<br>};<br>let obj2 = obj;<br>obj2.a = 12;</pre><pre>if(obj === obj2){<br>   console.log(&quot;obj and obj2 are same&quot;);<br>};<br>// above condition will be true </pre><pre>console.log(obj) // {a:12}<br>console.log(obj2) // {a:12}</pre><p>To understand this weird behavior of JavaScript, you can read below blog.</p><p><a href="https://medium.com/@aamchora/never-change-arrays-and-objects-directly-in-javascript-857bf4854901">Click here to read</a></p><blockquote><em>We can use </em><em>Object.assign(targetObject, sourceObject) to clone an object.</em></blockquote><pre>const obj = { a: 1 };<br>const obj2 = Object.assign({}, obj);<br>obj2.a = 2;</pre><pre>if(obj === obj2){<br>   console.log(&quot;obj and obj2 are same&quot;);<br>}else{<br> console.log(&quot;obj and obj2 are different&quot;);<br>};</pre><pre>// above condition will be false here </pre><pre>console.log(obj); // { a: 1 }<br>console.log(obj2); // { a: 2 }</pre><p><strong>Shallow copy</strong><br>A shallow copy of an object is a copy whose properties share the same references (point to the same underlying values) as those of the source object from which the copy was made.</p><p>Note: For Shallow copy we use Object.assign(targetObject, sourceObject).</p><p>Look at the below example to understand Shallow copy.</p><pre>const obj = {<br> a:1<br>}</pre><pre>const obj2 = {<br> b:2,<br> c:obj // here c&#39;s value is a reference to the other object called obj<br>}</pre><pre>const copy = Object.assign({},obj2); // here obj2 is a source object </pre><pre>// changing the copied object&#39;s value <br>copy.c.a = 1111;<br></pre><pre>if(copy.c.a === obj.a){<br>   console.log(&quot;obj and obj2 are same&quot;);<br>}<br>// above condition will be true</pre><p><strong>Deep copy</strong></p><p>A deep copy of an object is a copy whose properties do not share the same references(point to the same underlying values) as those of the source object from which the copy was made.</p><p>Note: For Deep copy we use JSON.parse(JSON.stringify(sourceObject)).</p><p>Look at the below example to understand Deep copy.</p><pre>const obj = {<br> a:1<br>}</pre><pre>const obj2 = {<br> b:2,<br> c:obj // here c&#39;s value is a reference to the other object called obj<br>}</pre><pre>const copy = JSON.parse(JSON.stringify(obj2)) // here obj2 is a source object </pre><pre>// changing the copied object&#39;s value <br>copy.c.a = 1111;<br></pre><pre>if(copy.c.a === obj.a){<br>   console.log(&quot;obj and obj2 are same&quot;);<br>}else{<br>  console.log(&quot;obj and obj2 are not same&quot;);<br>}<br>// above condition will be false</pre><p><strong><em>follow me for more such blog posts.</em></strong><em><br>Let me know if this blog was helpful.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6faba91eab50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>