<?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 Greeshma Balakrishnan on Medium]]></title>
        <description><![CDATA[Stories by Greeshma Balakrishnan on Medium]]></description>
        <link>https://medium.com/@greeshmameengoth?source=rss-aa90309153cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TOi5E7_UQnTgEAcYd5uueg.jpeg</url>
            <title>Stories by Greeshma Balakrishnan on Medium</title>
            <link>https://medium.com/@greeshmameengoth?source=rss-aa90309153cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:37:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@greeshmameengoth/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 npm and Yarn: The JavaScript Package Managers]]></title>
            <link>https://medium.com/@greeshmameengoth/understanding-npm-and-yarn-the-javascript-package-managers-ed1c44ffbf36?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed1c44ffbf36</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[yarn]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Mon, 16 Jun 2025 11:34:20 GMT</pubDate>
            <atom:updated>2025-06-16T11:34:20.921Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>NPM and Yarn</strong> are package managers used to manage a project’s dependencies. A <em>dependency</em> is exactly what it sounds like — a piece of code that a project relies on to function correctly. Managing dependencies manually can quickly become tedious and overwhelming, especially as the project grows in size and complexity.</p><p>Package managers like NPM and Yarn simplify this process by allowing developers to easily install, remove, and update dependencies. While both tools serve the same primary purpose, they each offer distinct features, workflows, and advantages.</p><h4>What is npm?</h4><p>npm stands for <strong>Node Package Manager</strong>, and is the default package manager Node.js. NPM makes it easy to install and manage Node.js dependencies in your project.</p><p>Common Commands:</p><pre>npm init        # Initialize a project<br>npm install     # Install dependencies<br>npm update      # Update all packages<br>npm run build   # Run a script from package.json</pre><h4>What is Yarn?</h4><p>Yarn stands for <strong>Yet Another Resource Negotiator </strong>and it is a package manager just like npm. It was developed by Facebook and is now open-source. The intention behind developing yarn(at that time) was to fix performance and security concerns with npm. Yarn offers faster installations, robust offline support, and strong workspace management, making it ideal for large projects.</p><p>Common Commands:</p><pre>yarn init<br>yarn install<br>yarn upgrade<br>yarn run build</pre><p><strong>The differences between npm and yarn</strong></p><ol><li>Installation Procedure:</li></ol><ul><li><strong>npm- </strong>npm is installed with Node automatically.</li><li><strong>Yarn - </strong>Before installing Yarn, ensure you have <strong>Node.js</strong> installed on your system.</li></ul><p>2. Lockfiles: When working on JavaScript projects, consistency is key — especially when it comes to dependencies. A <strong>lockfile</strong> is an automatically generated file that records the exact versions of every package and sub-package (dependency) installed in your project.</p><ul><li><strong>npm- </strong>NPM generates a ‘package-lock.json’ file. The package-lock.json file is a little more complex due to a trade-off between determinism and simplicity. Due to this complexity, the package-lock will generate the same node_modules folder for different npm versions. Every dependency will have an exact version number associated with it in the package-lock file.</li><li><strong>yarn- </strong>Yarn generates a ‘yarn.lock’ file. Yarn lock files help in easy merge. The merges are predictable as well, because of the design of the lock file.</li></ul><p>3. Fetching packages:</p><ul><li><strong>npm- </strong>npm fetches dependencies from the npm registry during every ‘npm install‘ command.</li><li><strong>Yarn- </strong>yarn stores dependencies locally, and fetches from the disk during a ‘yarn add‘ command (assuming the dependency(with the specific version) is present locally).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OaNBmV42Voyp2TQ6giKrg.png" /></figure><p><strong>Yarn</strong> offers faster installations, robust offline support, and strong workspace management, making it ideal for large projects. <strong>NPM</strong>, however, is more widely adopted, comes pre-installed with Node.js, and has improved performance and security features in recent versions.</p><h3>Which One Should You Use?</h3><ul><li><strong>npm</strong>: Default choice, especially for beginners or standard Node.js environments. It’s mature, widely supported, and has improved greatly.</li><li><strong>Yarn</strong>: Preferred in large projects, monorepos, or CI/CD environments where speed and reliability are crucial.</li></ul><p><strong>Note:</strong></p><p>If your project uses:</p><ul><li>package-lock.json ➝ use <strong>npm</strong></li><li>yarn.lock ➝ use <strong>Yarn</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed1c44ffbf36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between Modules and Components in web development]]></title>
            <link>https://medium.com/@greeshmameengoth/difference-between-modules-and-components-in-web-development-e3257d8dc142?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3257d8dc142</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Sun, 30 Mar 2025 14:06:13 GMT</pubDate>
            <atom:updated>2025-03-30T14:06:13.214Z</atom:updated>
            <content:encoded><![CDATA[<h3>Difference between modules and components in web development</h3><p>The terms <strong>modules</strong> and <strong>components</strong> are often used in software development, especially in the context of frameworks like React, Angular, or even general programming. While they may seem similar, they have distinct meanings and purposes:</p><h3>What Are Modules?</h3><p>A <strong>module</strong> is a self-contained unit of functionality that groups related pieces of code. Modules help in organizing code, making it reusable, maintainable, and scalable. They typically include classes, functions, and variables.</p><h4>Characteristics of Modules:</h4><ul><li><strong>Encapsulation</strong>: Modules contain code that performs specific functions and hides internal details.</li><li><strong>Reusability</strong>: Modules can be reused across different parts of an application.</li><li><strong>Independence</strong>: Modules should have minimal dependencies on other modules to ensure modularity.</li><li><strong>Organization</strong>: Helps in structuring the application for better readability and maintenance.</li></ul><p>Example of Modules in Programming:</p><pre>// math.js<br>export function add(x, y) {<br>    return x+ y;<br>}</pre><p>This file (<strong>math.js</strong>) is a <strong>module</strong>, meaning it contains a reusable piece of code that can be imported into other JavaScript files.</p><p>The <strong>export</strong> keyword makes the <strong>add</strong> function available for use in other modules. The function <strong>add(x, y)</strong> takes two parameters and returns their sum.</p><p>To use the <strong>add</strong> function in another file, you would import it like this:</p><pre>import { add } from &#39;./math.js&#39;;  console.log(add(8, 5)); // Output: 13</pre><p>The { add } syntax ensures only the exported function is imported.</p><p>This modular approach helps in <strong>code organization, reusability, and maintainability</strong>.</p><h3>What Are Components?</h3><p>A <strong>component</strong> is a smaller, reusable piece of an application that is responsible for a specific function or feature. In frontend development, components define the UI and behavior of an application.</p><h4>Characteristics of Components:</h4><ul><li><strong>Reusability</strong>: Components can be used multiple times within an application.</li><li><strong>Encapsulation</strong>: They encapsulate logic, styles, and templates.</li><li><strong>State Management</strong>: Many components manage their own state or receive data from parent components.</li></ul><p>Example of Components</p><p><strong>Vue.js</strong>:</p><pre>&lt;template&gt;<br>    &lt;h1&gt;Example Of Components&lt;/h1&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>    name: &#39;HeaderComponent&#39;<br>};<br>&lt;/script&gt;</pre><p>This contains the HTML structure of the component. In this case, it simply renders an <strong>&lt;h1&gt;</strong> tag with the text &quot;Example Of Components&quot;</p><p><strong>export default { name: &#39;HeaderComponent&#39; }</strong>: Assigns the name <strong>HeaderComponent</strong> to the component, making it easier to debug and reference.</p><p>The component can be used in another Vue file like this:</p><pre>&lt;HeaderComponent /&gt;</pre><p>But before using it, you need to <strong>import </strong>and<strong> register</strong> it in a parent component:</p><pre>&lt;script&gt;<br>import HeaderComponent from &#39;./HeaderComponent.vue&#39;;<br><br>export default {<br>    components: {<br>        HeaderComponent<br>    }<br>};<br>&lt;/script&gt;</pre><p>This makes the component <strong>reusable</strong> and <strong>modular</strong>, aligning with Vue’s component-based architecture.</p><h3>Key Differences Between Modules and Components</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*R0h6xUylmIsnG0UVeGy6IQ.png" /></figure><h3>How Modules and Components Work Together</h3><p>In frameworks like <strong>Angular</strong>, <strong>React</strong>, and <strong>Vue.js</strong>, modules and components work together:</p><ul><li><strong>Angular</strong>: Uses NgModule to group related components, services, and directives into logical units. Each module can have multiple components that define UI elements and behavior.</li><li><strong>React</strong>: Organizes components into separate files, effectively treating each file as a module. Components can be imported and reused across different parts of the application.</li><li><strong>Vue.js</strong>: Components are treated as modules and are imported/exported accordingly. A Vue module can group multiple components together to form a cohesive feature.</li></ul><p>By combining modules and components, applications remain <strong>modular, scalable, and maintainable</strong>. Modules provide organization and structure, while components handle UI and user interactions efficiently.</p><p>While <strong>modules</strong> focus on organizing code and functionality, <strong>components</strong> are more about UI and user interactions. Both play crucial roles in software development, ensuring maintainability, reusability, and scalability. Understanding the difference between modules and components helps in writing clean and efficient code, making development easier and more structured.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3257d8dc142" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complexity Analysis: Understanding the Efficiency of Algorithms]]></title>
            <link>https://medium.com/@greeshmameengoth/complexity-analysis-understanding-the-efficiency-of-algorithms-b164818b3e06?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b164818b3e06</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[complexity]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 19:20:39 GMT</pubDate>
            <atom:updated>2024-11-24T19:20:39.497Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Complexity analysis</strong> is defined as a technique to characterise the time taken by an<strong> algorithm</strong> with respect to input size (independent from the machine, language, and compiler). It is used to evaluate the<strong> variations of execution time</strong> on different algorithms. By understanding how algorithms behave in terms of time and space under varying input sizes, developers and researchers can choose or design solutions that are both efficient and scalable</p><h3>How do we measure complexity?</h3><p>The complexity of an algorithm can be measured in three ways:</p><h4>1. Time complexity</h4><p>The <strong>time complexity </strong>of an algorithm is defined as the amount of time taken by an algorithm to run as a function of the length of the input. Note that the time to run is a<strong> function of the length of the input</strong> and not the actual execution time of the machine on which the algorithm is running.<br>To estimate the time complexity, we need to consider the cost of each fundamental instruction and the number of times the instruction is executed.</p><p>→ If we have statements with basic operations like <strong>comparisons,</strong> <strong>return statements,</strong> <strong>assignments, and reading a variable.</strong> We can assume they take <strong>constant time each O(1).</strong></p><p>Eg:</p><pre>Statement 1: let num=5;            // reading a variable<br>statement 2; if( num==5) return true;  // return statement<br>statement 3; int compare= 10&gt;8 ? 1:0;     // comparison<br>statement 4; let flag=true;      // Assignment</pre><p>The result of calculating the overall time complexity should be</p><pre>total time = time(statement1) + time(statement2) + ... time (statementN)</pre><p>Assuming that<strong> ‘n’ is the size</strong> of the input, <strong>let’s use T(n)</strong> to represent the <strong>overall time</strong> and ‘t’ to represent the<strong> amount of time</strong> that a<strong> statement or collection</strong> of statements takes to<strong> execute.</strong></p><pre>T(n) = t(statement1) + t(statement2) + ... + t(statementN);</pre><p><strong>T(n)= O(1), → constant complexity.</strong></p><p>→ For any loop, we find out the runtime of the block inside it and multiply it by the number of times the program will repeat the loop.</p><pre>for (let i = 0; i &lt; n; i++) {<br> console.log(&quot;Complexity Analysis for &#39;for&#39; loop &quot;)<br>}</pre><p>for the above example, the loop will execute <strong>n times,</strong> and it will print <strong>“</strong>Complexity Analysis for ‘for’ loop<strong>”</strong> <strong>n</strong> <strong>number of times. </strong>so the time taken to run this program is:</p><pre>T(N)= n *( t(print statement))<br>    = n * O(1)<br>    =O(n)</pre><p>O(n) → Linear complexity.</p><p>→ For 2D arrays, we would have nested loop concepts, which means a loop inside a loop.</p><pre>for (let i = 0; i &lt; n; i++) {<br> for (let j = 0; j &lt; m; j++) {<br> console.log(&quot;complexity Analysis for 2D loop&quot;)<br> }<br>}</pre><p>For the above example, the console statement will execute <strong>n*m times,</strong> and it will print <strong>“</strong>complexity Analysis for 2D loop<strong>”</strong> <strong>N*M number of times. </strong>so the time taken to run this program is:</p><pre>T(N)= n * m *(t(console statement))<br>    = n * m * O(1)<br>    =O(n*m)</pre><p>O(n*m) → Quadratic Complexity.</p><h4>2. Space Complexity</h4><p><strong>The amount of memory required</strong> by the algorithm to solve a given problem is called the space complexity of the algorithm. Problem-solving using a computer requires memory to hold temporary data or final result while the program is in execution.</p><p>The space Complexity of an algorithm is the total space taken by the algorithm with respect to the input size. Space complexity includes both Auxiliary space and space used by input. <br>Space complexity is a parallel concept to time complexity. If we need to create an array of size n, this will <strong>require O(n) space</strong>. If we create a two-dimensional array of size <strong>n*n</strong>, this will require<strong> O(n2) space.</strong></p><p><strong>In recursive calls stack space also counts.</strong></p><h4>3. Auxilary Space</h4><p>The temporary space needed for the use of an algorithm is referred to as auxiliary space. Like temporary arrays, pointers, etc. <br>It is preferable to make use of Auxiliary Space when comparing things like sorting algorithms. <br>for example, <strong>sorting algorithms</strong> take <strong>O(n)</strong> space, as there is an input array to sort. but <strong>auxiliary space is O(1)</strong> in that case.</p><blockquote><em>Time complexity of an algorithm</em><strong><em> quantifies the amount of time</em></strong><em> taken by an algorithm to run as a</em><strong><em> function of length of the input</em></strong><em>. While, the</em><strong><em> space complexity</em></strong><em> of an algorithm</em><strong><em> quantifies the amount of space</em></strong><em> or memory taken by an algorithm to run as a </em><strong><em>function of the length of the input.</em></strong></blockquote><h4>Key Concepts in Complexity Analysis</h4><ol><li><strong>Input Size (n)</strong>: The size of the input data, often denoted as n, is a critical factor influencing an algorithm’s performance. It could represent the number of elements in an array, the size of a graph, or any other metric tied to the problem’s nature.</li><li><strong>Growth Rate:</strong> Algorithms are analyzed based on how their performance scales with increasing input size. This is typically expressed using <strong>asymptotic notations</strong>, which abstract away constants and lower-order terms to focus on the dominant factors.</li></ol><h3>Asymptotic Notations in Complexity Analysis:</h3><p>These notations provide a mathematical basis for describing the efficiency of algorithms:</p><ol><li><strong>Big-O Notation (O):</strong> Represents the upper bound of an algorithm’s growth rate. It describes the worst-case scenario, ensuring the algorithm performs within this bound regardless of input characteristics. [Example: O(n²) implies the algorithm’s time increases quadratically with n.]</li><li><strong>Omega Notation (Ω):</strong> Represents the lower bound of an algorithm’s growth rate, describing the best-case performance.</li><li><strong>Theta Notation (Θ):</strong> Provides a tight bound, signifying that the algorithm’s growth rate is both O(f(n)) and Ω(f(n)).</li><li><strong>Little-o and Little-ω\omegaω:</strong> Describe non-tight bounds for cases where an algorithm is strictly less or greater than a certain growth rate.</li></ol><h3>Different types of Complexity exist in the program:</h3><ol><li><strong>Constant Time (O(1)):</strong> The algorithm’s runtime is independent of the input size. If the function or method of the program takes negligible execution time. Then that will be considered as constant complexity. Example: Accessing an element in an array by index.</li><li><strong>Logarithmic Time (O(log⁡ n)):</strong> Performance scales logarithmically with input size, often seen in divide-and-conquer algorithms like binary search. It undergoes the execution of the order of<strong> log(N) </strong>steps.</li><li><strong>Linear Time (O(n))</strong>: Runtime scales directly with input size. It imposes a complexity of O(N). It encompasses the same number of steps as that of the total number of elements to implement an operation on N elements. Example: Iterating through an array.</li><li><strong>Linearithmic Time (O(n log⁡ n)):</strong> Combines linear and logarithmic growth, common in efficient sorting algorithms like mergesort.</li><li><strong>Quadratic Time:</strong> Runtime grows quadratically with input size, often associated with nested loops. It imposes a complexity of O(n2). For N input data size, it undergoes the order of N2 count of operations on N number of elements for solving a given problem. Simple implementations of bubble sort is an example of Quadratic Time.</li><li><strong>Exponential Time: </strong>For N elements, it will execute the order of the count of operations that is exponentially dependable on the input data size.</li><li><strong>Factorial Time (O(n!)):</strong> It imposes a complexity of O(n!). For N input data size, it executes the order of N! steps on N elements to solve a given problem.</li></ol><h3>Importance of Complexity Analysis</h3><ol><li><strong>Optimization:</strong> By analyzing an algorithm’s complexity, developers can identify bottlenecks and make improvements.</li><li><strong>Scalability:</strong> Algorithms with lower complexity are more likely to perform well on large datasets.</li><li><strong>Comparison:</strong> Complexity analysis allows for objective comparisons between different algorithms, enabling informed decision-making in software design.</li><li><strong>Predictability:</strong> Knowing the bounds of resource usage ensures systems can handle real-world demands without unexpected failures.</li></ol><p>Complexity analysis is a fundamental skill for any computer scientist or software engineer. By providing insights into the efficiency of algorithms, it empowers developers to create robust, scalable, and efficient solutions to computational problems. Understanding and applying complexity analysis principles not only ensures better algorithmic design but also enhances the overall performance of software systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b164818b3e06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Event Bubbling and Event Capturing in JavaScript.]]></title>
            <link>https://medium.com/@greeshmameengoth/understanding-event-bubbling-and-event-capturing-in-javascript-4b37b6f74e70?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b37b6f74e70</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 16:44:11 GMT</pubDate>
            <atom:updated>2024-06-17T16:44:11.153Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of web development, effectively handling user interactions is crucial. JavaScript provides mechanisms to manage how events propagate through the Document Object Model (DOM). Two fundamental concepts in this realm are <em>Event Bubbling</em> and <em>Event Capturing</em>. This article delves into these concepts, explaining their workings, differences, and practical usage.</p><h4>What is Event Propagation</h4><p>Event propagation refers to the order in which events are received by elements in the DOM. When an event occurs on an element, it doesn’t just stay confined to that element. Instead, it propagates through a sequence of phases, allowing parent elements to also respond to the event.</p><p>The two main phases of event propagation are:</p><ol><li>Event capturing — The event starts from the root of the DOM tree and travels down to the target element.</li><li>Event Bubbling — The event starts from the target element and bubbles up through its ancestors to the root of the DOM tree.</li></ol><h3>Event Bubbling</h3><p><em>Event bubbling</em> is the default behavior in most web browsers. When an event is triggered on a target element, it first triggers any event listeners on that element. Then, it propagates upwards through each parent element until it reaches the root of the document.</p><p>Example:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;outerPart&quot;&gt;<br>      &lt;button id=&quot;innerPart&quot;&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>document.getElementById(&#39;outerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Outer Layer clicked&#39;);<br>});<br><br>document.getElementById(&#39;innerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Inner Layer  clicked&#39;);<br>});</pre><p>Output- When you click the button, the following will be logged to the console:</p><pre>Inner Layer  clicked<br>Outer Layer clicked</pre><p>We can also understand the flow of event with the help of the below flow chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*lilbzIcx5b7PreFqgZso3w.png" /></figure><p>It means when the user click on the button, the click event flows in this order from bottom to top.</p><h4>Stopping Event Bubbling</h4><p>Beginning from the target and moving towards the top is the bubbling i.e. starting from the child to its parent, it moves straight upwards. But a handler can also take decision to stop the bubbling when the event has been processed completely. In JavaScript, we use the <strong>event.stopPropagation ()</strong> method.</p><p>Example:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;outerPart&quot;&gt;<br>      &lt;button id=&quot;innerPart&quot;&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>document.getElementById(&#39;outerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Outer Layer clicked&#39;);<br>});<br><br>document.getElementById(&#39;innerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Inner Layer  clicked&#39;);<br>    event.stopPropagation();<br>});</pre><p>Output:</p><pre>Inner Layer  clicked</pre><p>The event does not bubble up to the div element.</p><blockquote>The event.stopPropagation () method stops the move upwards bubbling (on one event only), but all the other handlers still run on the current element.</blockquote><h4>Practical Usage of Event Bubbling</h4><p>Event bubbling mechanism can be particularly useful in various practical scenarios. Here are some examples of when and why you might use event bubbling in your web development projects:</p><ol><li>Event Delegation — Event delegation is a technique where a single event listener is added to a parent element to manage events for multiple child elements. This is particularly useful when dealing with dynamic content, such as lists or tables.</li><li>Handling Multiple Similar Events — If you need to perform the same action for multiple similar elements, event bubbling allows you to set a single event listener on a common ancestor instead of on each individual element.</li><li>Centralized Event Handling — Centralized event handling can simplify your code by managing related events in one place. For example, you can manage form inputs or navigation links through a common parent element.</li><li>Dynamic Content Management — When elements are dynamically added or removed from the DOM, event delegation using bubbling ensures that the event listeners continue to work without needing to reattach them.</li><li>Simplifying Code for Nested Elements — In complex UIs with nested elements, using event bubbling can simplify event handling logic by allowing you to handle events at higher levels in the DOM.</li><li>Form Validation and submission — Event bubbling can be useful in forms where you want to validate inputs before submission. You can add a listener to the form element to handle input validation for all its child elements.</li></ol><p><strong>Note</strong>:</p><p>Event bubbling, where an event propagates from the target element up through its parent elements, can be powerful but might introduce complexity or unintended behavior if not carefully managed. Use it only when it provides a clear benefit or solves a specific problem in your application.</p><h3>Event Capturing</h3><p>Event Capturing is opposite to event bubbling, where in event capturing, an event moves from the outermost element to the target. Otherwise, in case of event bubbling, the event movement begins from the target to the outermost element in the file. Event Capturing is performed before event bubbling but capturing is used very rarely because event bubbling is sufficient to handle the event flow.</p><p>Netscape Browser was the first to introduce the concept of Event Capturing.</p><p>To use event capturing, you need to set the <strong><em>capture</em></strong> parameter to <strong><em>true</em></strong> when adding an event listener.</p><p>Example:</p><pre>document.getElementById(&#39;outerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Outer Layer clicked&#39;);<br>}, true); // true indicates capturing phase<br><br>document.getElementById(&#39;innerPart&#39;).addEventListener(&#39;click&#39;, function() {<br>    console.log(&#39;Inner Layer clicked&#39;);<br>}, false);</pre><p>Output:</p><pre>Outer Layer clicked<br>Inner Layer clicked</pre><p>The event is captured by the div first, then trickles down to the button.</p><p>We can also understand the flow of event with the help of the below flow chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Le4D7JwRNhmYD00xBn6Nw.png" /></figure><h4>Practical Usage of Event Capturing</h4><p>Event capturing can be particularly useful in scenarios where you need to implement functionality that should take precedence before any bubbling handlers.</p><ol><li>Form validation and Handling — If you have a nested form structure and want to validate user input or handle form submissions starting from the outermost container, event capturing ensures that your validation logic runs before any event bubbling can interfere.</li><li>Early Event Handling for Performance Optimization — By using event capturing, you can handle events at higher levels in the DOM before they reach deeply nested elements. This can prevent unnecessary event handling in lower-level elements, improving performance.</li><li>Custom User Interface Components — When building complex UI components, like custom dropdown menus or modal dialogs, you might need to manage event propagation carefully to ensure that interactions are handled correctly.</li><li>Event Delegation with Priority — In cases where you want parent elements to have a chance to respond to events before child elements, event capturing ensures the parent elements process the events first.</li><li>Stopping Unwanted Propagation Early — Sometimes you need to prevent certain events from reaching child elements. Using event capturing allows you to intercept and stop these events before they propagate downward.</li></ol><p><strong>Event Bubbling</strong> event propagates from the target element to its ancestors. It is the default phase and widely used. <strong>Event Capturing </strong>event propagates from the root to the target element. It is explicitly enabled by setting the <strong>capture</strong> parameter to <strong>true</strong>.</p><p>Both phases can be controlled using <strong>stopPropagation()</strong>, providing flexibility in managing event propagation.</p><p>Understanding these concepts allows developers to design more intuitive and responsive user interfaces. By strategically using event bubbling and capturing, you can create robust event handling mechanisms, enhancing the interactivity and user experience of your web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b37b6f74e70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript interview questions with answers]]></title>
            <link>https://medium.com/@greeshmameengoth/javascript-interview-questions-with-answers-f1f769e63231?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1f769e63231</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Fri, 19 Apr 2024 14:55:26 GMT</pubDate>
            <atom:updated>2024-04-19T14:55:26.548Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5V0KDzdELjvGTy8-AZ4_Gg.jpeg" /></figure><p>JavaScript, often abbreviated as JS, is a programming language and core technology of the Web, alongside HTML and CSS. 99% of websites use JavaScript on the client side for web page behavior. Web browsers have a dedicated JavaScript engine that executes the client code.</p><p>Q1: What are Data Types in JavaScript?</p><p>Ans: <strong><em>Data types in JavaScript</em></strong> define the data type that a variable can store. JavaScript includes <strong>primitive</strong> and <strong>non-primitive</strong> data types. The primitive data types in JavaScript include string, number, boolean, undefined, null, and symbol. The non-primitive data type includes the object.</p><p>A variable of primitive data type can contain only a single value.</p><h4><strong>Primitive types</strong></h4><p>Primitive are the lowest level of data value in the JavaScript programming language. They define immutable values — which can’t be changed.</p><p><strong>=&gt; String — </strong>String represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.</p><p>Example:</p><pre>var str = &quot;Greeshma Balakrishnan&quot;; //using double quotes<br>var str2 = &#39;Software Engineer&#39;; //using single quotes</pre><p>=&gt; <strong>Number</strong> — Number represents a number and can be written with or without decimals.</p><p>Example:</p><pre>var num = 5; //without decimal<br>var num2 = 9.8; //without decimal</pre><p>=&gt; <strong>BigInt — </strong>This data type is used to store numbers which are above the limitation of the Number data type. It can store large integers and is represented by adding “n” to an integer literal.</p><p>Example :</p><pre>var bigInteger =  222967890123456789012345678901234567890;</pre><p>=&gt;<strong>Boolean — </strong>Boolean represents a logical entity and can have only two values : true or false. Booleans are generally used for conditional testing.</p><p>Example :</p><pre>var a = 5;<br>var b =  55;<br>var c =  5;<br>(a == b) // will return false<br>(a == c) //will return true</pre><p>=&gt;<strong>Undefined — </strong>When a variable is declared but not assigned, it has the value of undefined and it’s type is also undefined.</p><p>Example :</p><pre>var x; // value of x is undefined<br>var y = undefined; // we can also set the value of a variable as undefined</pre><p><strong>=&gt;Null — </strong>A null value means no value. It means an empty value or absence of value.</p><p>Example:</p><pre>var x = null;</pre><p>=&gt;<strong>Symbol </strong>— Symbol is a new data type introduced in the ES6 version of javascript. The symbol data type in JavaScript defines a property of an object which is private to the object. The value with the Symbol data type can be referred to as a symbol value. The symbol refers to the ‘key’ of the key-value pair of an object. Every symbol is unique. Two symbols with the same key values are not the same.</p><p>Example :</p><pre>var symbol1 = Symbol(&#39;symbol&#39;);</pre><h4><strong>Non-primitive types</strong></h4><p>Primitive data types can store only a single value. To store multiple and complex values, non-primitive data types are used.</p><p><strong>Object — </strong>An object data type stores multiple values or data collection regarding properties and methods. It contains key-value pairs in its address. The properties of the object are written as key: value pairs. Each pair is separated by commas, enclosed in curly braces {}. The key must be a string, and the value can be of any data type.</p><p>Example:</p><pre>var profile= {<br>   firstName:  &quot;Greeshma&quot;,<br>   lastName:  &quot;Balakrishnan&quot;,<br>   hobbies: function(){<br>      return this.myHobbies;<br>   }<br>}</pre><p>Q2: What is the difference between “==” and “===” operators?</p><p>Ans: Both “==” and “ ===” are comparison operator. The difference between both the operators is that “==” is used to compare values whereas, “ ===” is used to compare both values and types.</p><p>Example:</p><pre>var x = 2;<br>var y = &quot;2&quot;;<br>(x == y)  // Returns true since the value of both x and y is the same<br>(x === y) // Returns false since the typeof x is &quot;number&quot; and typeof y is &quot;string&quot;</pre><p>Q3: What is NaN property in JavaScript?</p><p>Ans: <strong>NaN</strong> stands for “<strong><em>Not a Number</em></strong>” and is a value in JavaScript used to represent an undefined or unrepresentable value. NaN is the result of an operation that was supposed to return a number, but couldn’t because of an error or undefined/empty value. For example, dividing zero by zero or attempting to parse a string that doesn’t contain a valid number will result in NaN. It indicates a value that is not a legal number.</p><p>Example:</p><pre>console.log(0/0); // This will return NaN<br>console.log(parseInt(&quot;hello&quot;)); // This will return NaN</pre><p>Q4:What are the different ways to create objects in JavaScript?</p><p>Ans: In JavaScript, objects are versatile tools that can be created in various ways, each suitable for different scenarios. Objects can be created using object literals, the object constructor, or constructor functions. ES6 introduced class syntax for creating objects as well.</p><p>=&gt; Object literals — This is the simplest way to create an object. You define properties and methods directly within curly braces {}.</p><p>Example:</p><pre>const profile = {<br>  name: &quot;Greeshma&quot;,<br>  age: 28,<br>  greet() {<br>    console.log(`Hello, my name is ${this.name}`);<br>  }<br>};</pre><p>=&gt; Using the Object constructor — Using the Object constructor you can create an object . This method allows you to add properties and methods dynamically.</p><p>Example:</p><pre>const profile = new Object();<br>profile.name = &quot;Greeshma&quot;;<br>profile.age = 25;<br>profile.greet = function() {<br>  console.log(`Hello, my name is ${this.name}`);<br>};</pre><p>=&gt; Constructor functions — Constructor functions are used to create multiple similar objects with the same structure. You define a function and use the new keyword to create instances.</p><p>Example:</p><pre>function profile(name, age) {<br>  this.name = name;<br>  this.age = age;<br>  this.greet = function() {<br>    console.log(`Hello, my name is ${this.name}`);<br>  };<br>}<br><br>const myProfile = new profile(&quot;Greeshma&quot;, 25);</pre><p>=&gt; Using ES6 Classes — ES6 introduced class syntax, which provides a more familiar way to create objects with a constructor and methods.</p><pre>class profile {<br>  constructor(name, age) {<br>    this.name = name;<br>    this.age = age;<br>  }<br><br>  greet() {<br>    console.log(`Hello, my name is ${this.name}`);<br>  }<br>}<br><br>const myProfile = new profile(&quot;Greeshma&quot;, 25);</pre><p>Each of these methods has its own advantages and use cases. Object literals are simple and straightforward for creating single objects. The Objecct constructor allows for dynamic property addition. Constructor functions are useful for creating multiple instances with shared properties and methods. ES6 classes provide syntactic sugar on top of constructor functions, making object-oriented programming in JavaScript more familiar to developers coming from other languages.</p><p>Q5: What is the event loop in JavaScript?</p><p>Ans:The event loop is a critical concept in JavaScript that enables asynchronous programming. JavaScript is a single-threaded language, meaning it can only execute one piece of code at a time. However, it often needs to perform tasks asynchronously, such as fetching data from a server or handling user interactions.</p><p>The event loop is responsible for managing the execution of asynchronous tasks and ensuring that the JavaScript runtime remains responsive. Here’s how it works:</p><p>=&gt; Call Stack — When you execute synchronous code, JavaScript uses a data structure called the call stack to keep track of function calls and their execution contexts. Each function call is added to the top of the stack, and when a function completes, it is removed from the stack.</p><p>=&gt; Callback Queue — Asynchronous operations, such as setTimeout callbacks, DOM events, or AJAX requests, are handled by the browser or the environment in which JavaScript is running. When an asynchronous operation completes, its callback function is pushed into a queue called the callback queue.</p><p>=&gt; Event Loop — The event loop continuously checks two main components: the call stack and the callback queue.</p><ul><li>If the call stack is empty and there are functions waiting in the callback queue, the event loop will take the first callback function from the queue and push it onto the call stack for execution.</li><li>This process allows asynchronous operations to be processed in a non-blocking manner, ensuring that the JavaScript runtime remains responsive to user interactions and other events.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1f769e63231" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Conditional and List Rendering in vue.js]]></title>
            <link>https://medium.com/@greeshmameengoth/exploring-conditional-and-list-rendering-in-vue-js-5b6e4a666ee6?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b6e4a666ee6</guid>
            <category><![CDATA[conditional-statements]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Sun, 10 Dec 2023 18:01:33 GMT</pubDate>
            <atom:updated>2023-12-10T18:01:33.402Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZ9pBpw3ykV4yqsVSvDVVg.png" /></figure><p>Vue.js provides a progressive and flexible framework for building user interfaces, allowing developers to incrementally adopt it and scale their applications as needed. The framework’s focus on simplicity, reactivity, and component-based architecture empowers developers to create dynamic and interactive UIs.</p><p><strong>Conditional rendering </strong>and L<strong>ist rendering</strong> are two fundamental concepts within Vue.js that enhance the dynamism of user interfaces, enabling developers to craft applications that respond intelligently to user actions and changing data. These features contribute to Vue.js’s reputation as a powerful and developer-friendly framework for building modern web applications.</p><h3><strong>Conditional Rendering</strong></h3><p>Conditional rendering in web development refers to the process of displaying or rendering different content based on certain conditions or criteria.</p><p>Conditional rendering in Vue.js allows developers to display content based on certain conditions. This is achieved using the v-if, v-else-if, and v-else directives.</p><p><em>Example</em>:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;p v-if=&quot;number&gt;0&quot;&gt;It is a positive number&lt;/p&gt;<br>    &lt;p v-else-if=&quot;number&lt;0&quot;&gt;It is a negative number&lt;/p&gt;<br>    &lt;p v-else&gt;The number is zero&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      <br>      number: 5<br>    };<br>  }<br>};<br>&lt;/script&gt;</pre><p>In this example, the content displayed is determined by the value of number . Vue.js dynamically updates the DOM based on changes to this variable.</p><h4>v-if</h4><p>The directive v-if is used to conditionally render a block. The block will only be rendered if the directive&#39;s expression returns a truthy value.</p><p><em>Example</em>:</p><pre>&lt;h1 v-if=&quot;true&quot;&gt;Hello World&lt;/h1&gt;</pre><h4>v-else</h4><p>You can use the v-else directive to indicate an &quot;else block&quot; for v-if:</p><p><em>Example:</em></p><pre><br><br>&lt;h1 v-if=&quot;number&gt;0&quot;&gt;Poistive Number&lt;/h1&gt;<br>&lt;h1 v-else&gt;It is not a positive number&lt;/h1&gt;</pre><h4>v-else-if</h4><p>The v-else-if, as the name suggests, serves as an &quot;else if block&quot; for v-if. It can also be chained multiple times.</p><p>Similar to v-else, a v-else-if element must immediately follow a v-if or a v-else-if element.</p><p><em>Example</em>:</p><pre>&lt;div v-if=&quot;type === &#39;A&#39;&quot;&gt;<br>  A<br>&lt;/div&gt;<br>&lt;div v-else-if=&quot;type === &#39;B&#39;&quot;&gt;<br>  B<br>&lt;/div&gt;<br>&lt;div v-else-if=&quot;type === &#39;C&#39;&quot;&gt;<br>  C<br>&lt;/div&gt;<br>&lt;div v-else&gt;<br>  Not A/B/C<br>&lt;/div&gt;</pre><h4>v-show</h4><p>The v-show directive toggles the visibility of an element based on the truthiness of the expression. Unlike v-if, the element is always rendered in the DOM, and only its CSS display property is modified. v-show doesn&#39;t support the &lt;template&gt; element, nor does it work with v-else.</p><p><em>Example</em>:</p><pre>&lt;h1 v-show=&quot;isDetailsVisible&quot;&gt;All details are visible!&lt;/h1&gt;</pre><blockquote>These directives provide a powerful way to conditionally render content in Vue.js applications. Developers can use these directives to adapt the UI based on various states, such as user authentication, dynamic data availability, or user interactions. The choice between v-if and v-show depends on the use case: v-if is suitable for cases where the condition rarely changes, and v-show is useful for toggling visibility frequently without re-rendering the element.</blockquote><h3>List Rendering</h3><p>In Vue.js, list rendering is a powerful feature that allows you to iterate over an array and render dynamic content based on the data. This is typically done using the v-for directive.</p><p><em>Example</em>:</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h2&gt;Fruits List:&lt;/h2&gt;<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(item, index) in fruitsList&quot; :key=&quot;index&quot;&gt;<br>        {{ item }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  data() {<br>    return {<br>      fruitsList: [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Oranges&#39;, &#39;Grapes&#39;]<br>    };<br>  }<br>};<br>&lt;/script&gt;</pre><p>n this example:</p><ul><li>The v-for directive is used to iterate over the fruitsList array.</li><li>(item, index) represents the individual element and its index in the array.</li><li>:key=&quot;index&quot; is crucial for Vue.js to efficiently update the DOM when the array changes.</li></ul><p>The rendered HTML will look like:</p><pre>&lt;div&gt;<br>  &lt;h2&gt;Shopping List:&lt;/h2&gt;<br>  &lt;ul&gt;<br>    &lt;li&gt;Apples&lt;/li&gt;<br>    &lt;li&gt;Bananas&lt;/li&gt;<br>    &lt;li&gt;Oranges&lt;/li&gt;<br>    &lt;li&gt;Grapes&lt;/li&gt;<br>  &lt;/ul&gt;<br>&lt;/div&gt;</pre><blockquote>When v-if and v-for are both used on the same element, v-if will be evaluated first.</blockquote><p>Conditional rendering and list rendering in Vue.js significantly contribute to creating dynamic and responsive user interfaces. These features provide developers with the flexibility to adapt content based on various conditions and iterate over data to generate dynamic lists.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b6e4a666ee6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unsderstanding APIs in Vue.js-Composition API and Options API]]></title>
            <link>https://medium.com/@greeshmameengoth/unsderstanding-apis-in-vue-js-composition-api-and-options-api-f6b2e902ec28?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6b2e902ec28</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[composition-api]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[options-api]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Mon, 27 Nov 2023 09:03:49 GMT</pubDate>
            <atom:updated>2023-11-27T09:03:49.198Z</atom:updated>
            <content:encoded><![CDATA[<p>Vue is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS, and JavaScript and provides a declarative and component-based programming model that helps you efficiently develop user interfaces, be they simple or complex.</p><p>Vue components can be authored in two different API styles: <strong>Options API</strong> and <strong>Composition API</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJd0IlJQDRs0mS8zD9AjPg.jpeg" /></figure><h3>Options API</h3><p>The Options API in Vue.js is a set of options or properties that define the behavior of a Vue instance or component. These options are essentially the building blocks of a Vue component and allow developers to specify data, methods, computed properties, lifecycle hooks, and more.</p><p>With Options API, we define a component’s logic using an object of options such as data, methods, and mounted.</p><p><em>Example for Options API:</em></p><pre>&lt;script&gt;<br>export default {<br><br>  data() {<br>    return {<br>      count: 0<br>    }<br>  },<br><br>  methods: {<br>    increment() {<br>      this.count++<br>    }<br>  },<br><br>  mounted() {<br>    console.log(`The initial count is ${this.count}.`)<br>  }<br>}<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;button @click=&quot;increment&quot;&gt;Count is: {{ count }}&lt;/button&gt;<br>&lt;/template&gt;</pre><h4>Understanding the structure of Options API</h4><ol><li>Data: The ‘Data’ option is where you define the state of your component. It returns an object containing the data properties.</li></ol><p><em>Example:</em></p><pre>data() {<br>  return {<br>    message: &#39;Hello, World!&#39;,<br>    count: 0,<br>  };<br>},</pre><p>2. Methods: The ‘methods’ option is used to define custom methods that can be called within the component.</p><p><em>Example</em>:</p><pre>methods: {<br>  increment() {<br>    this.count++;<br>  },<br>},</pre><p>3. Computed Properties: The computed option allows you to define properties based on the state of the data, providing a way to perform calculations and cache the results.</p><p><em>Example</em>:</p><pre>computed: {<br>  doubledCount() {<br>    return this.count * 2;<br>  },<br>},</pre><p>4. Lifecycle Hooks: Vue.js provides various lifecycle hooks (e.g., created, mounted, updated) that allow you to execute code at different stages of a component&#39;s lifecycle.</p><p><em>Example</em>:</p><pre>created() {<br>  console.log(&#39;Component created&#39;);<br>},</pre><h4>Benefits of the Options API:</h4><ol><li>Readability and Maintainability: The Options API provides a clear and structured way to organize your component’s logic, making it easier to read and maintain, especially in larger projects.</li></ol><p>2. Separation of Concerns: Each option focuses on a specific aspect of the component’s functionality, promoting the separation of concerns and a more modular development approach.</p><p>3. Flexibility: The Options API allows developers to adapt to various scenarios, providing the flexibility needed to create complex and feature-rich components.</p><h3>Composition API</h3><p>Vue.js, known for its simplicity and flexibility, has evolved with the introduction of the Composition API. Released as part of Vue 3, the Composition API provides developers with a powerful and more scalable way to organize and reuse logic within Vue components.</p><p>Traditionally, Vue.js components were structured using the Options API, which, while effective, could become complex and challenging to manage in larger applications. The Composition API addresses these concerns by introducing a more modular and function-based approach to component composition.</p><p>With Composition API, we define a component’s logic using imported API functions. In SFCs, Composition API is typically used with &lt;script setup&gt;. The setup attribute is a hint that makes Vue perform compile-time transforms that allow us to use Composition API with less boilerplate. For example, imports and top-level variables/functions declared &lt;script setup&gt; are directly usable in the template.</p><p><em>Example for Composition API</em>:</p><pre>&lt;script setup&gt;<br>import { ref, onMounted } from &#39;vue&#39;<br><br><br>const count = ref(0)<br><br>function increment() {<br>  count.value++<br>}<br><br><br>onMounted(() =&gt; {<br>  console.log(`The initial count is ${count.value}.`)<br>})<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;button @click=&quot;increment&quot;&gt;Total Count is: {{ count }}&lt;/button&gt;<br>&lt;/template&gt;</pre><h4>Structure of the Composition API:</h4><ol><li>Reactive Variables: The Composition API introduces the ref function, allowing developers to create reactive variables. Unlike the Options API, where data properties are declared within the data option, reactive variables can be created anywhere in the component.</li></ol><p><em>Example</em>:</p><pre>const count = ref(0);</pre><p>2. Lifecycle Hooks: Lifecycle hooks in the Composition API are organized as functions rather than options, providing a cleaner and more intuitive way to manage component lifecycle logic.</p><p><em>Example</em>:</p><pre>onMounted(() =&gt; {<br>  console.log(`The initial count is ${count.value}.`)<br>});</pre><p>3. Composition Functions: One of the core concepts of the Composition API is the ability to encapsulate related logic into composition functions. These functions can be reused across different components, promoting code modularity and maintainability.</p><p><em>Example</em>:</p><pre>function useCounter() {<br>  const count = ref(0);<br><br>  function increment() {<br>    count.value++;<br>  }<br><br>  return { count, increment };<br>}</pre><h3>Benefits of the Composition API:</h3><ol><li>Improved Code Organization: The Composition API encourages developers to organize code based on logic rather than lifecycle hooks, resulting in cleaner and more maintainable code.</li><li>Code Reusability: Composition functions allow developers to encapsulate and reuse logic across multiple components, reducing redundancy and promoting a more modular development approach.</li><li>Better TypeScript Support: With the Composition API, TypeScript support is enhanced, providing improved type inference and better autocompletion for IDEs.</li><li>Easier Testing: The Composition API simplifies testing by isolating logic into composition functions, making it easier to write unit tests for specific functionality.</li></ol><h3>Conclusion</h3><p>Both Option API and Composition API are fully capable of covering common use cases.</p><p>The Options API is centered around the concept of a “component instance” (this as seen in the example), which typically aligns better with a class-based mental model for users coming from OOP language backgrounds. It is also more beginner-friendly by abstracting away the reactivity details and enforcing code organization via option groups.</p><p>The Composition API is centered around declaring reactive state variables directly in a function scope and composing state from multiple functions together to handle complexity. It is more free-form and requires an understanding of how reactivity works in Vue to be used effectively. In return, its flexibility enables more powerful patterns for organizing and reusing logic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6b2e902ec28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Closure in Javascript]]></title>
            <link>https://medium.com/@greeshmameengoth/closure-in-javascript-4a85ed9cf4c2?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a85ed9cf4c2</guid>
            <category><![CDATA[closure-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 04:54:47 GMT</pubDate>
            <atom:updated>2023-09-05T04:54:47.407Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is a versatile and powerful programming language used for web development. One of its distinctive features is the concept of closure, which plays a crucial role in many advanced JavaScript techniques.</p><h3>What is Closure?</h3><p>In JavaScript, closure refers to the ability of a function to retain access to variables from its containing (enclosing) lexical scope even after that scope has finished executing. This means that a function can “close over” its surrounding context, making the variables within that context available for reference, even when the outer function has completed its execution.</p><blockquote>In JavaScript, closures are created every time a function is created, at function creation time.</blockquote><h3><strong>How does Closure work?</strong></h3><p>To understand closure better, let’s look at a simple example:</p><pre>function outerFunction() {<br>  const outerVar = &quot;It is from outside Function&quot;;<br><br>  function innerFunction() {<br>    console.log(outerVar); // innerFunction has access to outerVar<br>  }<br><br>  return innerFunction;<br>}<br><br>const myClosure = outerFunction();<br>myClosure(); // Logs &quot;It is from outside Function&quot;</pre><p>Here, outerFunction contains a variable called outerVar, and it defines an inner function called innerFunction. When outerFunction is invoked, it returns innerFunction. Even after outerFunction has completed execution, myClosure still has access to outerVar. When we call myClosure(), it logs the value of outerVar, demonstrating closure in action.</p><h3>Use Cases for Closure</h3><p>Closure is a powerful concept that can be used in various scenarios in JavaScript:</p><ol><li>Data Privacy</li></ol><p>By encapsulating data within a closure, you can create private variables that are not accessible from outside the function. This helps in maintaining data integrity and preventing unintended modifications.</p><p><em>Example:</em></p><pre>function createCount() {<br>  let count = 0;<br><br>  return function() {<br>    return ++count;<br>  };<br>}<br><br>const counter = createCount();<br>console.log(counter()); // 1<br>console.log(counter()); // 2</pre><p>2. Function Factories</p><p>Closures allow you to create function factories that generate functions with specific behaviors based on the environment in which they were created.</p><p><em>Example:</em></p><pre>function greetPrefix(prefix) {<br>  return function(name) {<br>    console.log(`${prefix}, ${name}!`);<br>  };<br>}<br><br>const greetHello = greetPrefix(&quot;Hello&quot;);<br>greetHello(&quot;Greeshma&quot;); // Hello, Greeshma!</pre><p>3. Callbacks and Asynchronous Code</p><p>Closures are commonly used in callbacks and handling asynchronous operations. They help maintain the context and state of variables even after the original function has been completed.</p><p><em>Example:</em></p><pre>function fetchData(url) {<br>  fetch(url)<br>    .then((response) =&gt; response.json())<br>    .then((data) =&gt; {<br>      // data is accessible here due to closure<br>      console.log(data);<br>    });<br>}</pre><p>4. Module Pattern</p><p>Closures can be used to implement the module pattern, which enables the creation of private and public methods and variables, allowing for better organization and encapsulation of code.</p><p><em>Example:</em></p><pre>const counterModule = (function() {<br>  let count = 0;<br><br>  function increment() {<br>    count++;<br>  }<br><br>  function getCount() {<br>    return count;<br>  }<br><br>  return {<br>    increment,<br>    getCount<br>  };<br>})();<br><br>counterModule.increment();<br>console.log(counterModule.getCount()); </pre><p>Here output should be 1.</p><p>5. Memoization</p><p>Closures can be used to cache and remember the results of expensive function calls, which can significantly improve the performance of algorithms or functions.</p><p><em>Example:</em></p><pre>function memoize(func) {<br>  const cache = {};<br><br>  return function(...args) {<br>    const key = JSON.stringify(args);<br>    if (!(key in cache)) {<br>      cache[key] = func(...args);<br>    }<br>    return cache[key];<br>  };<br>}<br><br>const memoizedAdd = memoize((a, b) =&gt; a + b);<br>console.log(memoizedAdd(5, 3)); // 8(result is cached)</pre><p>6. Partial Application and Currying</p><p>Closures are useful for implementing techniques like partial application and currying, which allow you to create new functions by pre-filling some arguments of existing functions.</p><p><em>Example:</em></p><pre>function multiply(a) {<br>  return function(b) {<br>    retufunction multiply(a) {<br>  return function(b) {<br>    return a * b;<br>  };<br>}<br><br>const double = multiply(2);<br>console.log(double(5)); // 10 a * b;<br>  };<br>}<br><br>const double = multiply(2);<br>console.log(double(5)); // 10</pre><p>Closure is a fundamental concept in JavaScript that allows functions to remember and access variables from their enclosing scopes. This capability enables powerful patterns in JavaScript, such as data privacy, function factories, and handling asynchronous code. Understanding and utilizing closure effectively can lead to cleaner, more maintainable, and more efficient JavaScript code</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a85ed9cf4c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common questions asked in every interview — with sample response: Part II]]></title>
            <link>https://medium.com/@greeshmameengoth/common-questions-asked-in-every-interview-with-sample-response-part-ii-80d5a5d16f0f?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/80d5a5d16f0f</guid>
            <category><![CDATA[job-interview]]></category>
            <category><![CDATA[good-interview-answers]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[common-interview-question]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Tue, 27 Jun 2023 18:46:26 GMT</pubDate>
            <atom:updated>2023-06-27T18:46:26.112Z</atom:updated>
            <content:encoded><![CDATA[<h3>Common questions asked in every interview — with sample response: Part II</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*o-gayMmAYas97OSA49Wr2g.png" /></figure><p>Job interviews can be nerve-wracking, but with preparation and practice, you can boost your confidence and improve your chances of success. In <a href="https://medium.com/@greeshmameengoth/10-common-questions-asked-in-every-interview-with-sample-response-21a5117bcfeb">part 1</a> of this series, we went through some common questions asked in job interviews. Let’s explore a few additional tough questions that are commonly posed during interviews.</p><p>Q1: Explain a scenario when you faced a challenging situation at work and how you resolved it.</p><p>While answering this question, it’s important to provide a clear and structured response that highlights your problem-solving skills and ability to handle adversity. Start with briefly describing the challenging situation you encountered at work. Provide enough background information to help the interviewer understand the scope and impact of the challenge. Be concise and focus on the key details. Focus on your thought process, decision-making, and the actions you implemented to tackle the situation. Emphasize your problem-solving abilities and highlight any leadership or collaboration skills you utilized. Share the positive results or impact of your actions. Highlight any specific achievements, improvements, or lessons learned from the experience. Quantify the results if possible, such as increased application performance, improved user experience, or meeting the deadline despite the challenges.</p><p>Sample response:</p><blockquote>In my previous role as a front-end developer, we faced a critical deadline to deliver a complex web application for a high-profile client. However, due to unforeseen technical issues, our team encountered significant performance problems that were affecting the application’s usability and responsiveness. To address the performance issues, I initiated a thorough analysis of the application’s codebase and identified several areas that required optimization. I immediately coordinated with the back-end developers to understand the underlying data flow and implemented caching mechanisms to reduce unnecessary server requests.As a result of our efforts, we were able to significantly improve the application’s performance, reducing page load times by 40%. This not only enhanced the user experience but also prevented potential client dissatisfaction. We successfully delivered the application within the deadline, exceeding client expectations. The experience taught me the importance of proactive problem-solving, effective collaboration, and the value of thorough testing and optimization in ensuring a successful project outcome.</blockquote><p>Q2: How do you see yourself in 10 years?</p><p>When asked about how you see yourself in 10 years, it’s important to strike a balance between expressing ambition and being realistic. You can share with them both your short-term plan and long-term plan.</p><p>Sample response:</p><blockquote>In the next 10 years, I see myself continuing to grow both professionally and personally as a front-end developer. I have a strong passion for this field, and I am committed to staying at the forefront of emerging technologies and industry trends.</blockquote><blockquote>In the short term, I aim to deepen my expertise in front-end development by mastering new frameworks, libraries, and tools. I also plan to expand my knowledge in areas such as user experience design, accessibility, and performance optimization.</blockquote><blockquote>I believe that continuous learning and adaptability are crucial for long-term success. In 10 years, I see myself embracing new challenges and exploring opportunities beyond front-end development. This might include gaining expertise in related fields like full-stack development, and product management, or even starting my own ventures.</blockquote><p>Q3: What is your expectation about the new job?</p><p>When answering the question, “What is your expectation about the new job?” it’s important to strike a balance between expressing your enthusiasm for the role and demonstrating a realistic understanding of what the job entails. Begin by expressing your enthusiasm for the opportunity and your eagerness to contribute to the company’s success. Highlight your genuine interest in the position and the value you believe you can bring to the role. Emphasize your understanding of the role and its importance within the organization. Express your desire for continuous learning and professional development. Discuss your expectations for opportunities to expand your skill set, take on new challenges, and grow within the company. Express your expectation of working alongside motivated and talented colleagues, fostering teamwork, and maintaining a positive workplace culture.</p><p>Sample response:</p><blockquote>I’m truly excited about the prospect of joining this company and the [specific role] position. I’ve been following the company’s success and admire its commitment to [mention a specific aspect or value of the company]. I believe that my skills and experience align perfectly with the requirements of the role, and I’m enthusiastic about the opportunity to contribute to the company’s growth and make a meaningful impact. Based on the job description and my research, I have a clear understanding of the role’s responsibilities and expectations. I’m excited about the chance to [mention specific responsibilities or tasks] and leverage my [relevant skills or experiences] to contribute to the team’s success. One of my expectations for this new job is to have opportunities for continuous learning and professional development. I’m eager to expand my knowledge and stay up-to-date with the latest industry trends and technologies. I hope to engage in relevant training programs, attend conferences or workshops, and collaborate with talented colleagues who can challenge and inspire me. I value collaboration and believe that working in a supportive and inclusive environment leads to better outcomes. I expect open communication, the opportunity to exchange ideas, and a culture that encourages innovation and mutual support. I’m confident that such an environment will not only enhance my personal growth but also contribute to the overall success of the team and the company.</blockquote><p>Q4: Tell me about a time when you had to work with a difficult team member.</p><p>When responding to the question, “Tell me about a time when you had to work with a difficult team member,” it’s essential to showcase your interpersonal skills, conflict resolution abilities, and ability to maintain professionalism in challenging situations. Emphasize the importance of maintaining a positive and collaborative work environment. Start by briefly explaining the context of the situation, such as the project or team you were working on and the importance of collaboration within that setting. Keep the focus on the specific incident and the difficult team member involved. Explain the specific challenges or conflicts that arose due to the difficult team member’s behavior. Focus on objective observations and provide examples of specific incidents or issues that occurred. Detail the steps you took to address the challenges and promote collaboration. Emphasize your communication and conflict resolution skills, as well as your ability to empathize and find common ground. Conclude by discussing the positive outcomes resulting from your efforts and the lessons you learned from the experience. Emphasize any improvements in collaboration, project outcomes, or personal growth.</p><p>Sample response:</p><blockquote>In my previous role as a software developer, I was assigned to a project where I had to collaborate closely with a team member who had a reputation for being difficult to work with. This team member, let’s call him Johny, often exhibited a negative attitude, was resistant to new ideas, and had a tendency to dominate discussions without considering others’ input. Rather than allowing these challenges to hinder our progress, I took a proactive approach to address the situation. Firstly, I made an effort to understand Johny’s perspective and tried to identify any underlying reasons for his behavior. I found out that Johny had experienced a previous project failure, which had affected his confidence and trust in the team.</blockquote><blockquote>To foster a more positive working relationship, I decided to have a one-on-one conversation with Johny. I expressed my desire to create a harmonious and productive team environment, highlighting the importance of open communication and mutual respect. I listened to his concerns and acknowledged his expertise, which helped to build trust between us. To encourage collaboration and ensure everyone’s ideas were heard, I suggested implementing a structured meeting format where each team member would have an opportunity to share their thoughts and concerns. I also emphasized the importance of constructive feedback and encouraged Johny to voice his opinions in a more inclusive manner. Over time, our efforts started to pay off. John gradually became more receptive to other team members’ ideas and began actively participating in discussions. I made sure to acknowledge his valuable contributions and provided positive feedback whenever possible. Despite the initial challenges, our team successfully completed the project within the designated timeline. Not only did we achieve our goals, but we also managed to improve the overall team dynamics along the way.</blockquote><blockquote>This experience taught me the significance of empathy, active communication, and patience when working with difficult team members. By addressing the issues directly, fostering understanding, and promoting a supportive team environment, it’s possible to transform a challenging situation into an opportunity for growth and collaboration.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80d5a5d16f0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference b/w Volatile memory & Non-volatile memory]]></title>
            <link>https://medium.com/@greeshmameengoth/difference-b-w-volatile-memory-non-volatile-memory-d7d1996b6042?source=rss-aa90309153cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7d1996b6042</guid>
            <category><![CDATA[non-volatile-memory]]></category>
            <category><![CDATA[memory-storage]]></category>
            <category><![CDATA[memory-structure]]></category>
            <category><![CDATA[volatile-memory]]></category>
            <dc:creator><![CDATA[Greeshma Balakrishnan]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 08:46:12 GMT</pubDate>
            <atom:updated>2023-06-12T08:46:12.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>Difference b/w volatile memory &amp; non-volatile memory</h3><p>In the realm of computer memory, two fundamental categories exist: volatile memory and non-volatile memory. Each type serves a unique purpose and possesses distinct characteristics that significantly impact its functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NH0lyYLUu_HjkdQjvTPBLA.jpeg" /></figure><h3>What is Volatile memory?</h3><p>Volatile memory is a temporary memory that stores data when the computer is on but erases it as soon as the computer is switched off. Volatile memory is also known as dynamic memory. Volatile memory is a type of memory hardware that fetches and stores data at a very high speed. It relies on the presence of power to maintain stored information. The most widely used form of volatile memory in modern computing is Random Access Memory (RAM). RAM allows for quick and direct access to data, making it an essential component in the performance of computers, servers, and other digital devices.</p><p>Volatile memory finds applications across a wide range of computing systems and industries. Some notable examples include:</p><ol><li>Personal Computers: Volatile memory, in the form of RAM, is crucial for ensuring smooth and responsive computing experiences. It allows for the seamless execution of applications and multitasking capabilities, as well as the quick loading of operating systems and software.</li><li>Servers and Data Centers: Volatile memory is integral to the efficient functioning of servers and data centers, which handle vast amounts of data and require high-performance processing. It enables rapid data access and retrieval, enhancing the overall performance of these systems.</li><li>Gaming Consoles: Volatile memory plays a crucial role in gaming consoles, as it allows for real-time rendering, quick loading times, and seamless gameplay experiences. The high-speed nature of volatile memory is vital in delivering immersive and visually stunning gaming environments.</li></ol><h3>What is non-volatile memory?</h3><p>Non-volatile memory, also known as static or permanent memory, is a type of memory hardware that does not lose the data stored within it when the system shuts down. Non-volatile memory is often used for secondary storage or long-term storage. However, it takes the operating system a long time to load this memory, and as a result, it delivers slower performance and lower data transfer rates.</p><p>Non-volatile memory devices ensure data persistence, allowing for long-term storage and retrieval. Common examples of non-volatile memory include hard disk drives (HDDs), solid-state drives (SSDs), flash memory, and electrically erasable programmable read-only memory (EEPROM).</p><p>Non-volatile memory finds widespread applications across diverse industries and computing systems:</p><ol><li>Personal Computing: Hard disk drives (HDDs) and solid-state drives (SSDs) serve as primary storage devices in personal computers, enabling the installation and execution of operating systems, software applications, and user data storage.</li><li>Enterprise Storage: Non-volatile memory plays a crucial role in enterprise storage systems, providing reliable and scalable solutions for storing vast amounts of business-critical data. It ensures data persistence, accessibility, and quick retrieval for efficient business operations.</li><li>Mobile Devices: Flash memory, a type of non-volatile memory, is extensively used in smartphones, tablets, and portable media players. It enables persistent storage of apps, media files, and user data in a compact and energy-efficient form.</li><li>Embedded Systems: Non-volatile memory is an essential component of embedded systems, including Internet of Things (IoT) devices, automotive systems, and industrial control systems. It facilitates firmware storage, configuration data, and critical system information.</li></ol><h3>Key Differences b/w volatile &amp; non-volatile Memory</h3><ol><li>Data Retention: Volatile memory is volatile by nature, requiring a constant power supply to retain data. On the other hand, non-volatile memory maintains data integrity even in the absence of power.</li><li>Speed: Volatile memory, particularly RAM, provides rapid access to stored data, making it ideal for applications that require real-time data processing and manipulation. Non-volatile memory, while capable of high-speed data transfer, generally lags behind volatile memory in terms of access speed.</li><li>Storage Capacity: Volatile memory, primarily RAM, typically offers smaller storage capacities compared to non-volatile memory devices like HDDs and SSDs. Non-volatile memory excels in providing larger storage capacities, enabling long-term data storage and retrieval.</li><li>Data Persistence: Volatile memory is temporary and loses all data once power is interrupted. In contrast, non-volatile memory ensures data persistence, making it suitable for long-term storage and retrieval.</li><li>Types of data stored: Volatile memory stores data from the programs that the CPU is processing in real time, and the system stores all the frequently-used information and data in the device’s volatile memory. Non-volatile memory stores data from the basic booting process of any computer system’s BIOS (Basic Input/Output System). It stores all the data and media that need to stay on the computer long-term or permanently.</li><li>CPU access: Volatile memory provides fast random access, allowing the CPU to quickly read and write data. For non-volatile memory, the system needs to copy data onto volatile memory so the CPU can access it.</li><li>Position of memory: Volatile memory (e.g., RAM) is typically located directly on the motherboard, while non-volatile memory (e.g., HDDs, SSDs, flash memory) can be found in storage devices or modules connected externally to the motherboard.</li></ol><p>In the world of computer memory, understanding the differences between volatile memory and non-volatile memory is essential. Volatile memory, exemplified by RAM, provides fast and temporary storage for active computing operations but does not retain data once power is lost. Non-volatile memory, represented by HDDs, SSDs, and flash memory, offers persistent data storage, enabling long-term retention and retrieval. The unique characteristics of each type of memory contribute to their specific applications in various computing systems, from personal computers to data centers. As technology advances, a balance between volatile and non-volatile memory is crucial to harness the benefits of both for optimal system performance and data management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7d1996b6042" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>