<?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 Sachin on Medium]]></title>
        <description><![CDATA[Stories by Sachin on Medium]]></description>
        <link>https://medium.com/@ss428582?source=rss-54fbb6795153------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4qaS2miqhmXGfUsN.jpg</url>
            <title>Stories by Sachin on Medium</title>
            <link>https://medium.com/@ss428582?source=rss-54fbb6795153------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:02:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ss428582/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[Intro to Prototype]]></title>
            <link>https://medium.com/@ss428582/intro-to-prototype-28fa8b3dff27?source=rss-54fbb6795153------2</link>
            <guid isPermaLink="false">https://medium.com/p/28fa8b3dff27</guid>
            <category><![CDATA[prototype]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[advanced-javascript]]></category>
            <dc:creator><![CDATA[Sachin]]></dc:creator>
            <pubDate>Mon, 30 Sep 2024 04:50:14 GMT</pubDate>
            <atom:updated>2024-09-30T04:50:14.434Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ypmrnmXvhXSM6w7_" /><figcaption>Photo by <a href="https://unsplash.com/@sapegin?utm_source=medium&amp;utm_medium=referral">Artem Sapegin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article we will try to understand briefly on what is prototype in JS.</p><p>Considering that all my readers must be having basic idea of JS. So let’s get started.</p><p>If you have ever printed any object on console and when you open it you must have seen [[Prototype]] written over there. So after seeing we must have wondered what is Prototype and what is the working of it. So let’s understand everything.</p><p><strong>Prototype —</strong></p><p>So going by definition <strong>Prototype is a mechanism to inherit properties and methods from other objects</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*BINuV8_G82-rfYOaIcOJZw.png" /></figure><p>As you can see above snippet I simply print out an object and there we can see [[Prototype]] and inside Prototype what we can see is some properties and methods which we can access like if in above example I try to access toString() method I can access that it is available in Prototype of object.</p><p>In general we can say <strong>Prototype is either null or references another object</strong>.</p><p>When we try to read a property from an object and it is missing then JS automatically takes it from prototype which we call as <strong>Prototypal Inheritance.</strong></p><p>Another question in mind is that <strong>can we change the Prototype of the above object </strong>So the answer is yes. <strong>Yes</strong>, we can changes the Prototype of the above object.</p><p><strong>Now moving to setting prototype</strong></p><p>We can set prototype by setting __proto__</p><p>Let’s start with it</p><p>We will create an object named obj2 and set a method named start and will try to set prototype of object named obj1</p><pre>let obj2 = {<br>    start : () =&gt; {<br>        console.log(&quot;Start Method called&quot;)<br>    }<br>} <br><br>obj1.__proto__ = obj2;</pre><p>In above snippet we set prototype of obj1 equals to obj2. Now when we print obj1 we will see obj2 as prototype of obj1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*5d1msd50GHf3mmAh-5zaew.png" /></figure><p>and if I try obj1.start() it will work perfectly fine. This shows we can change prototype and access it easily.</p><p>In this way we can also set prototype of prototype we set and so on.</p><p>So this is a brief article on prototype giving you an <strong>idea on Prototype</strong>, <strong>Prototypal Inheritance </strong>and how we can <strong>set Prototype</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28fa8b3dff27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Polyfills]]></title>
            <link>https://medium.com/@ss428582/all-about-polyfills-0faeaa616af1?source=rss-54fbb6795153------2</link>
            <guid isPermaLink="false">https://medium.com/p/0faeaa616af1</guid>
            <category><![CDATA[what-is-pollyfill]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Sachin]]></dc:creator>
            <pubDate>Mon, 19 Feb 2024 05:17:13 GMT</pubDate>
            <atom:updated>2024-02-19T05:17:13.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FTsvx9zvpGpb0E7o" /><figcaption>Photo by <a href="https://unsplash.com/@emben?utm_source=medium&amp;utm_medium=referral">Johann Siemens</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This will be a quick guide for all those developers who want to know what is polyfill and some basic polyfill examples with syntaxes that are generally asked in interviews.</p><p>This article will be brief so starting with -</p><p><strong>What is polyfill and where it is used —</strong></p><p>So starting with the definition of polyfills. By word polyfill, we can understand it is <strong>going to fill some gaps</strong> so Polyfills are <strong>pieces of code (this can include functions) that provide new functionality on old browsers</strong>. As we know web technologies are changing so new functionalities are also coming with it. Sometimes these new functionalities are not compatible with the old browsers so to use these we have to write our own syntaxes to support old browsers. This is what we call polyfills.</p><p>So if anyone asks what is the <strong>need for polyfills </strong>we can say -</p><ul><li>Usage of new features</li><li>Support Browser compatibility</li></ul><p>O<strong>ne liner definition</strong> will be “<strong>Replicating modern functionality on older environments</strong>”</p><p>I guess now we have a basic understanding of polyfills and usage. Now we can jump into some basic polyfills which are generally asked in interviews</p><p>We will be discussing <strong>Array.map</strong>,<strong> Array.filter</strong>, and <strong>Array.reduce</strong> in this article.</p><p>Before that we will be discussing what should be the <strong>developer mindset</strong> before writing any polyfill</p><ul><li><strong>Dev should be aware of what new functionality or syntax is exactly doing</strong></li></ul><p>Now we will be directly jumping into some existing syntaxes and how we can replicate them by writing polyfill for that.</p><p><strong>Array.map</strong></p><p>We will be taking an array and simply multiplying each item by 2. Below is the simple code using .map()</p><pre>let oldArr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br><br>// Array map function<br>let newArr = oldArr.map((item, index, oldArr) =&gt; {<br>    return item * 2<br>})<br><br>console.log(&quot;New Array using map&quot;, newArr);</pre><p>Now we will be implementing polyfill for the same</p><pre>Array.prototype.myMapFn = function (callback) {<br>    let tempArr = [];<br>    for (let i = 0; i &lt; this.length; i++) {<br>        tempArr.push(callback(this[i], i, this))<br>    }<br>    return tempArr;<br>}</pre><p>Above is a simple syntax of a map using polyfill.</p><p>What we have done is we have created a function named myMapFn in which we have initialized a tempArr with [] and we pushed the item in tempArr on the condition provided inside the callback. If we try this pollyfill with any condition it will work.</p><pre>let newUpdatedArr = oldArr.myMapFn((item, index) =&gt; {<br>    return item * 3<br>})<br><br>console.log(&quot;newUpdatedArr&quot;, newUpdatedArr);</pre><p><strong>Array.filter</strong></p><p>By filter, we can understand we will be filtering data based on some condition provided by the user and returning a new array with filtered data</p><p>In this, we will be simply printing all the items which are greater than 5.</p><pre>// Filter Function<br>let oldArr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br><br>let filteredArr = oldArr.filter((item, index) =&gt; {<br>    return item &gt; 5<br>})<br><br>console.log(&quot;Filtered Arr &quot;, filteredArr);</pre><p>Now we will be writing polyfill for the same</p><pre>Array.prototype.myFilterFn = function (callback) {<br>    let filteredArr = [];<br>    for (let i = 0; i &lt; this.length; i++) {<br>        if(callback(this[i], i, this)){<br>            filteredArr.push(this[i]);<br>        }        <br>    }<br>    return filteredArr;<br>}</pre><p>What we have done above is we have created a function named myFilterFn in which we have initialized an empty array named filteredArr and iterated till length. If the condition fulfills then we push the item inside filteredArr.</p><p>Now we will be implementing filter polyfill</p><pre>let oldArr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];<br><br>let polyfillArr =  oldArr.myFilterFn((item, index) =&gt; {<br>    return item &gt; 5<br>})<br><br>console.log(&quot;PolyfillArr&quot;, polyfillArr);</pre><p><strong>Array.reduce</strong></p><p>In this, we will be summing all array elements.</p><pre>// Reduce <br>let oldArr= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];<br><br>let reducedArr = oldArr.reduce((acc, curr, i, oldArr) =&gt; {<br>    return acc + curr;<br>}, 0)<br><br>console.log(&quot;ReducedArr&quot;, reducedArr);</pre><p>It reduces the array and gives the sum of array elements.</p><p>Now we will be creating a polyfill of it.</p><pre>Array.prototype.myReduceFn = function (cb, initial){<br>    let accumulator = initial;<br>    for (let i = 0; i &lt; this.length; i++) {<br>        accumulator = accumulator ? cb(accumulator, this[i], i, this) : this[i];        <br>    }<br>    return accumulator;<br>}</pre><p>In this, we have created myReduceFn, and we have initialized the accumulator with the initial value provided. We iterated till the length inside it we checked whether there is some initial value assigned or not if yes then implement callback logic otherwise initialize it arr first element and implement callback logic afterward.</p><p>So these are some of the common functions which are generally asked in interviews. There are many more functionalities for which we can write polyfills you can try them on your own like Math.trunc, forEach, and many more and I will be back soon with some interesting topic for you guys.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0faeaa616af1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Webpack]]></title>
            <link>https://medium.com/@ss428582/introduction-to-webpack-a5e8712fccd4?source=rss-54fbb6795153------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5e8712fccd4</guid>
            <category><![CDATA[project-setup]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Sachin]]></dc:creator>
            <pubDate>Sat, 29 Jul 2023 10:55:00 GMT</pubDate>
            <atom:updated>2023-07-29T10:55:00.572Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is going to be a guide on how to set up Webpack. But before moving to set up, let’s understand what Webpack is and why it is required.</p><h4><strong>What is Webpack</strong></h4><p><strong>Webpack is a module bundler</strong> for Javascript applications. It creates a <a href="https://webpack.js.org/concepts/dependency-graph/">dependency graph</a> and combines all your files into one or more static bundle files which then will be loaded on the browser.</p><p>There are basic concepts like entry, output, modules, etc., which we will learn later in this article.</p><p><strong>Init Project —</strong></p><p>We will set up project with npm</p><pre>mkdir webpack-learning<br>cd webpack-learning<br>npm init -y</pre><p>to skip answering some questions with yes while set up we will run npm init with -y.</p><p><strong>Create webpack file —</strong></p><p>Now we will create a file with the name webpack.config.js</p><p>Now we will start writing webpack file and also gets a basic understanding of all the concepts.</p><p>We will <strong>install</strong> webpack and webpack-cli</p><pre>npm install --save-dev webpack webpack-cli</pre><p><strong>Understanding concepts</strong></p><p><strong>Entry —</strong></p><p>Entry is the point from where webpack starts creating its dependency graph. It can be single or multiple but for now, we will use a single entry point.</p><pre>module.exports = {<br>    entry : &quot;./app/index.js&quot;<br>}</pre><p>In the above snippet, webpack will start creating its dependency graph from index.js inside the app folder.</p><p><strong>Loaders —</strong></p><p>Loaders job is to work on things while they are getting loaded. Whatever we need to do before the bundle file is created we can do in loaders like loading styles, images, etc.</p><p><strong>Basic loaders</strong> for webpack with snippets</p><ul><li><strong>images like png, SVG, etc</strong></li></ul><pre>module.exports = {<br>  entry: &quot;./app/index.js&quot;,<br>  module: {<br>    rules: [<br>      {<br>        test: /\.(svg|.png|.gif|.jpg)$/,<br>        use: &quot;file-loader&quot;,<br>      },<br>    ],<br>  },<br>};</pre><p>In the above snippet, we can see 2 keys inside the rules array of objects ie. test and use</p><p><strong>test</strong> — The value of the test will be a regex.</p><p><strong>use</strong> — loader which we will be using. In use, if there is an array then the loader goes from right to left.</p><ul><li><strong>styling i.e. CSS</strong> —</li></ul><p>For that first, we have to install style-loader</p><pre>npm install --save-dev style-loader css-loader</pre><p>Code Snippet for webpack style-loader</p><pre>{<br>  test: /\.(css)$/,<br>  use: [&quot;style-loader&quot;, &quot;css-loader&quot;]<br>}</pre><p>If one wants to use sass we can use it there are sass-loaders available on npm.</p><ul><li><strong>js files</strong></li></ul><p>For js files, we need a babel-loader and transpiler to convert the latest js code to code which can be supported by old browsers. For that, we will use Babel.</p><pre>npm install --save-dev babel-loader @babel/core @babel/preset-env</pre><p>babel-loader is a webpack loader and babel/preset-env is for transpiling 2015+ syntax.</p><p>code snippet</p><pre>{<br>  test: /\.(js)$/,<br>  use: {<br>    loader: &quot;babel-loader&quot;,<br>    options : {<br>      presets : [[&quot;@babel/preset-env&quot;, { targets: &quot;defaults&quot; }]]<br>    }<br>  },<br>},</pre><p><strong>Output File —</strong></p><p>Here we mention the location where we need our bundler file.</p><pre>const path = require(&#39;path&#39;);<br>module.exports = {<br>  output : {<br>    path : path.resolve(__dirname, &quot;dist&quot;),<br>    filename: &quot;bundler.js&quot;<br>  }<br>}</pre><p>here the path is the native node package that we use. In the output object we are mentioning that we need bundled file inside the dist folder and the filename will be bundler.js</p><p><strong>Plugins —</strong></p><p>Once our bundled file is ready we need to inject it into an HTML file for that we need to use plugins. We use plugins for whatever we need to perform once a bundled file is created.</p><p>For injecting bundled files in HTML we will be using html-webpack-plugin</p><pre>npm install --save-dev html-webpack-plugin</pre><p>After installing we will be using this in webpack</p><pre>module.exports = {<br>  plugins : [new HtmlWebpackPlugin()]<br>}</pre><p>So if we keep this empty then it will create an index.html file and also inject a bundle.js file in that HTML file.</p><p>So our final Webpack looks like this</p><pre>const path = require(&quot;path&quot;);<br>const HtmlWebpackPlugin = require(&quot;html-webpack-plugin&quot;);<br><br>module.exports = {<br>  entry: &quot;./app/index.js&quot;,<br>  module: {<br>    rules: [<br>      {<br>        test: /\.(svg|.png|.gif|.jpg)$/,<br>        use: &quot;file-loader&quot;,<br>      },<br>      {<br>        test: /\.(css)$/,<br>        use: [&quot;style-loader&quot;, &quot;css-loader&quot;],<br>      },<br>      {<br>        test: /\.(js)$/,<br>        use: {<br>          loader: &quot;babel-loader&quot;,<br>          options: {<br>            presets: [[&quot;@babel/preset-env&quot;, { targets: &quot;defaults&quot; }]],<br>          },<br>        },<br>      },<br>    ],<br>  },<br>  output: {<br>    path: path.resolve(__dirname, &quot;dist&quot;),<br>    filename: &quot;bundler.js&quot;,<br>  },<br>  plugins: [new HtmlWebpackPlugin()],<br>  mode: &quot;development&quot;,<br>};</pre><p><strong>Server</strong></p><p>The final part is our server and we will be using webpack-dev-server</p><pre>npm install --save-dev webpack-dev-server</pre><p>and configuration will be done in package.json</p><pre>&quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;webpack serve&quot;,<br>    &quot;build&quot;: &quot;webpack&quot;,<br>  }</pre><p>And this is it. We have implemented our webpack with basic configs.</p><p>Hope this helps in getting a basic understanding of webpack. So go ahead and start your first project setup using webpack. And keep learning!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5e8712fccd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>