<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Coding Tutorial</title>
	<atom:link href="https://codingizfun.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://codingizfun.com/</link>
	<description>Software Architecture and javascript concepts explained in detail with examples</description>
	<lastBuildDate>Sun, 25 Feb 2024 01:03:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>
<site xmlns="com-wordpress:feed-additions:1">214557465</site>	<item>
		<title>Unveiling .NET Core: Introduction</title>
		<link>https://codingizfun.com/unveiling-net-core-introduction/</link>
					<comments>https://codingizfun.com/unveiling-net-core-introduction/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Feb 2024 01:03:45 +0000</pubDate>
				<category><![CDATA[DotNet Core Mastery: Unraveling Basics to Advanced Techniques]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=152</guid>

					<description><![CDATA[<p>Welcome to the World of .NET Core! Embark on an exciting journey into the realm of .NET Core! Before we dive into the technicalities, let&#8217;s take a quick stroll through the history of .NET and uncover details about .NET Core introduction. .NET, a robust framework crafted by Microsoft, has been a stalwart in software development....</p>
<p>The post <a href="https://codingizfun.com/unveiling-net-core-introduction/">Unveiling .NET Core: Introduction</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Welcome to the World of .NET Core!</h2>



<p class="">Embark on an exciting journey into the realm of .NET Core! Before we dive into the technicalities, let&#8217;s take a quick stroll through the history of .NET and uncover details about .NET Core introduction.</p>



<p class="">.NET, a robust framework crafted by Microsoft, has been a stalwart in software development. As technology evolved, a demand for a more adaptable, cross-platform solution arose. This demand gave birth to .NET Core, a framework designed to meet the dynamic needs of modern development. </p>



<h2 class="wp-block-heading">Unlocking .NET Core&#8217;s Power: Key Features and Advantages</h2>



<p class="">Now, let&#8217;s unravel the fascinating features that set .NET Core apart.</p>



<ul class="wp-block-list">
<li class=""><strong>Cross-Platform Flexibility:</strong>&nbsp;Build and run dotnet applications on Windows, macOS, and Linux.</li>



<li class=""><strong>Open-Source Transparency:</strong>&nbsp;With the source code available to everyone, .NET Core promotes transparency and encourages community contributions.</li>



<li class=""><strong>Modular:</strong>&nbsp;.NET Core&#8217;s modular architecture empowers developers to pick only the components needed.</li>
</ul>



<h2 class="wp-block-heading">Contrasting .NET Core with the Traditional .NET Framework</h2>



<p class="">Let&#8217;s compare the innovative .NET Core and the traditional .NET Framework.</p>



<ul class="wp-block-list">
<li class=""><strong>Cross-Platform Prowess:</strong>&nbsp;While .NET Core effortlessly spans Windows, macOS, and Linux, the .NET Framework primarily caters to Windows.</li>



<li class=""><strong>Open-Source Collaboration:</strong>&nbsp;.NET Core embraces an open-source ethos, fostering community collaboration, while the .NET Framework relies heavily on Microsoft&#8217;s development.</li>



<li class=""><strong>Modularity vs. Monolith:</strong> .NET Core&#8217;s modular design allows component selection, whereas the .NET Framework operates as a monolithic entity.</li>



<li class=""><strong>Ability to house multiplt dotnet versions: </strong>In .NET Core, projects can independently specify and switch between different SDK versions using SDK-style projects and the <code>global.json</code> file. This flexibility contrasts with .NET Framework, where SDK versions are determined system-wide, making it less adaptable for projects with varying SDK requirements.</li>
</ul>



<h2 class="wp-block-heading">Hands-On Adventure: Crafting a &#8220;Hello World&#8221; Application</h2>



<p class="">Let&#8217;s get our hands dirty and create a simple yet impactful &#8220;Hello World&#8221; application.</p>



<ol class="wp-block-list">
<li class=""><strong>Install .NET Core SDK:</strong>&nbsp;Set the stage by installing the .NET Core Software Development Kit.</li>



<li class=""><strong>Open a Terminal or Command Prompt:</strong>&nbsp;It&#8217;s your gateway to the world of coding.</li>



<li class=""><strong>Create a Console Masterpiece:</strong>&nbsp;Execute the magic command, dotnet new console -n HelloWorld, or leverage the user-friendly Visual Studio editor.</li>



<li class=""><strong>Navigate to the HelloWorld Directory:</strong>&nbsp;Dive into your newly created project with cd HelloWorld.</li>



<li class=""><strong>Run the Application:</strong>&nbsp;Witness the magic unfold with dotnet run.</li>
</ol>



<p class="">Congratulations! You&#8217;ve taken the first steps into the exciting universe of .NET Core. Keep the momentum going, and in the next leg of our journey, we&#8217;ll explore even more captivating concepts and practical applications.</p>



<p class="">Ready to delve deeper? Stay tuned for the next post in our .NET Core series!</p>



<p class=""><strong>References:</strong></p>



<p class=""><a href="https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/september/net-standard-demystifying-net-core-and-net-standard">https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/september/net-standard-demystifying-net-core-and-net-standard</a></p>
<p>The post <a href="https://codingizfun.com/unveiling-net-core-introduction/">Unveiling .NET Core: Introduction</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/unveiling-net-core-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">152</post-id>	</item>
		<item>
		<title>Angular Material Virtual scrolling</title>
		<link>https://codingizfun.com/angular-material-virtual-scrolling/</link>
					<comments>https://codingizfun.com/angular-material-virtual-scrolling/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 23 Feb 2024 22:15:19 +0000</pubDate>
				<category><![CDATA[Angular and Javascript Interview questions]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=142</guid>

					<description><![CDATA[<p>In web applications, virtual scrolling is used to render and display large lists or grids efficienty. Angular Material, a popular UI component library for Angular, provides built-in support for virtual scrolling. Let&#8217;s understand virtual scrolling, it&#8217;s benefits, and how to implement it using Angular Material. What is Virtual Scrolling? Virtual scrolling renders only the visible...</p>
<p>The post <a href="https://codingizfun.com/angular-material-virtual-scrolling/">Angular Material Virtual scrolling</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="">In web applications, virtual scrolling is used to render and display large lists or grids efficienty. Angular Material, a popular UI component library for Angular, provides built-in support for virtual scrolling. Let&#8217;s understand virtual scrolling, it&#8217;s benefits, and how to implement it using Angular Material.</p>



<h3 class="wp-block-heading">What is Virtual Scrolling?</h3>



<p class="">Virtual scrolling renders only the visible items in a list or grid, instead of loading the entire dataset at once. It dynamically creates and removes elements from the DOM as the user scrolls through the list. This approach is useful when dealing with huge data because it significantly improves performance and reduces memory consumption.</p>



<h3 class="wp-block-heading">Benefits of Virtual Scrolling:</h3>



<ol class="wp-block-list">
<li class=""><strong>Improved Performance</strong>: Virtual scrolling dramatically enhances the performance of web applications by rendering only the visible items. This results in faster initial loading times and smoother scrolling.</li>



<li class=""><strong>Reduced Memory Usage</strong>: Since only a subset of items is in the DOM at any given time, memory usage reduces significantly, making it feasible to work with large datasets without causing memory-related issues.</li>



<li class=""><strong>Consistent User Experience</strong>: Virtual scrolling provides a consistent user experience, regardless of the data size, as the scrolling remains smooth and responsive.</li>
</ol>



<h3 class="wp-block-heading">Implementing Virtual Scrolling in Angular Material:</h3>



<p class="">Angular Material provides a <strong>CdkVirtualScrollViewport </strong>directive to implement virtual scrolling.&nbsp;</p>



<p class="">Below are the steps for the same</p>



<ul class="wp-block-list">
<li class=""><strong>Install Angular Material using the below command</strong></li>
</ul>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<pre class="wp-block-code"><code>      <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">  ng add @angular/material</mark></code></pre>



<ul class="wp-block-list">
<li class=""><strong>In your Angular module import the ScrollingModule:</strong></li>
</ul>
</div></div>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<pre class="wp-block-code"><code>    <mark style="background-color:#ffffff" class="has-inline-color has-vivid-red-color">import { ScrollingModule } from '@angular/cdk/scrolling';
    @NgModule({
       imports: &#91;ScrollingModule],
    })</mark></code></pre>
</div></div>
</div></div>
</div></div>



<ul class="wp-block-list">
<li class=""><strong>Create the Virtual Scroll Container:</strong></li>
</ul>



<p class="">      In your component&#8217;s template, create a container element (e.g., &lt;cdk-virtual-scroll-viewport&gt;) to host       the virtual scroll:</p>



<pre class="wp-block-code"><code>
<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">&lt;cdk-virtual-scroll-viewport itemSize="50" minBufferPx="200" maxBufferPx="400"
                             class="example-viewport"&gt;
  &lt;div *cdkVirtualFor="let item of items" class="example-item"&gt;{{item}}&lt;/div&gt;
&lt;/cdk-virtual-scroll-viewport&gt;--&gt;</mark></code></pre>



<ul class="wp-block-list">
<li class=""><em>itemSize<strong>:</strong> This attribute specifies the size of each item in pixels.</em></li>
</ul>



<ul class="wp-block-list">
<li class=""><strong>Provide Data:</strong></li>
</ul>



<p class="">Just pass the data and Angular Material will handle the rest. As we scroll through the list, virtual scroll will efficiently create and delete elements as needed, providing a seamless user experience.</p>



<p class="">Now let&#8217;s compare the performance with and without virtual scrolling</p>



<p class="">Considering the example of displaying a list of 20,000 strings.</p>



<ul class="wp-block-list">
<li class=""><strong>With initial scrolling</strong></li>
</ul>



<p class=""><strong>Code</strong></p>



<pre class="wp-block-code"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">&lt;h4>Items list with Virtual scrolling enabled&lt;/h4>
&lt;cdk-virtual-scroll-viewport itemSize="50" minBufferPx="200" maxBufferPx="400"
                             class="example-viewport">
  &lt;div *cdkVirtualFor="let item of items" class="example-item">{{item}}&lt;/div>
&lt;/cdk-virtual-scroll-viewport></mark>      </code></pre>
</div></div>



<p class=""><strong>Performance:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="640" height="27" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-1.png?resize=640%2C27&#038;ssl=1" alt="" class="wp-image-147" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-1.png?w=984&amp;ssl=1 984w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-1.png?resize=300%2C13&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-1.png?resize=768%2C33&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-1.png?resize=850%2C36&amp;ssl=1 850w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<ul class="wp-block-list">
<li class=""><strong>Displaying plain list without virtual scrolling</strong></li>
</ul>



<p class=""><strong>Code</strong></p>



<pre class="wp-block-code"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">&lt;div>
  &lt;h2>List of Items&lt;/h2>
  &lt;ul>
    &lt;li *ngFor="let item of items">{{ item }}&lt;/li>
  &lt;/ul>
&lt;/div></mark>
</code></pre>



<p class=""><strong>Performance:</strong></p>



<figure class="wp-block-image size-full"><img decoding="async" width="640" height="23" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-2.png?resize=640%2C23&#038;ssl=1" alt="Angular virtual scroll" class="wp-image-148" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-2.png?w=985&amp;ssl=1 985w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-2.png?resize=300%2C11&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-2.png?resize=768%2C28&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2024/02/image-2.png?resize=850%2C31&amp;ssl=1 850w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<p class=""><strong>References</strong><br><a href="https://material.angular.io/cdk/scrolling/overview">https://material.angular.io/cdk/scrolling/overview</a></p>



<p class="">If you like this post and are interested to learn more about MInimal API, please go through below links for other related posts</p>



<p class=""><a href="https://codingizfun.com/">https://codingizfun.com/</a></p>
<p>The post <a href="https://codingizfun.com/angular-material-virtual-scrolling/">Angular Material Virtual scrolling</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/angular-material-virtual-scrolling/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">142</post-id>	</item>
		<item>
		<title>Minimal API</title>
		<link>https://codingizfun.com/minimal-api/</link>
					<comments>https://codingizfun.com/minimal-api/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 19 Aug 2023 23:27:43 +0000</pubDate>
				<category><![CDATA[DotNet Core Mastery: Unraveling Basics to Advanced Techniques]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=126</guid>

					<description><![CDATA[<p>What is Minimal API? .NET Core Minimal API was introduced with .NET 6 to simplify creating focused APIs. These APIs reduce setup complexity by fluently declaring routes and actions, bypassing traditional scaffolding and controller overhead. While conventional API setup involves controllers, routes, and middleware, Minimal APIs use concise syntax. They accommodate scaling, handling complex routing,...</p>
<p>The post <a href="https://codingizfun.com/minimal-api/">Minimal API</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">What is Minimal API?</h2>



<p>.NET Core Minimal API was introduced with .NET 6 to simplify creating focused APIs. These APIs reduce setup complexity by fluently declaring routes and actions, bypassing traditional scaffolding and controller overhead.</p>



<p>While conventional API setup involves controllers, routes, and middleware, Minimal APIs use concise syntax. They accommodate scaling, handling complex routing, authorization, and content control.</p>



<p>Core features include:</p>



<ol class="wp-block-list">
<li><strong>Simplicity:</strong>&nbsp;Syntax is concise, reducing setup compared to MVC-based APIs.</li>



<li><strong>No Controllers:</strong>&nbsp;Avoid separate controllers; declare routes and handlers directly.</li>



<li><strong>Single File:</strong>&nbsp;Suitable for small APIs, fit the entire API within a single file.</li>



<li><strong>Inline Configuration:</strong>&nbsp;Define configuration inline for intuitive setup.</li>



<li><strong>Convention-Based:</strong>&nbsp;Reduce explicit configuration needs.</li>
</ol>



<h2 class="wp-block-heading">Advantages:</h2>



<ol class="wp-block-list">
<li><strong>Simplicity:</strong>&nbsp;Readable syntax aids understanding.</li>



<li><strong>Reduced Boilerplate:</strong>&nbsp;Less code, quicker development.</li>



<li><strong>Inline Configuration:</strong>&nbsp;Intuitive settings, simple scenarios.</li>



<li><strong>Single File:</strong>&nbsp;Manageable for small projects and prototypes.</li>



<li><strong>Quick Prototyping:</strong>&nbsp;Ideal for fast microservices development.</li>
</ol>



<h2 class="wp-block-heading">Disadvantages:</h2>



<ol class="wp-block-list">
<li><strong>Limited Flexibility:</strong>&nbsp;May not suit complex projects if not well designed.</li>



<li><strong>Scalability and Maintainability:</strong>&nbsp;Better for simple cases.</li>



<li><strong>Testing and Separation:</strong>&nbsp;Effort needed for concerns separation.</li>



<li><strong>Learning Curve:</strong>&nbsp;Adaptation for experienced developers.</li>
</ol>



<p>Now, let&#8217;s understand Minimal API with a practical TODO list example</p>



<h2 class="wp-block-heading">Building a Todo List API with .NET Core Minimal APIs: A Step-by-Step Guide</h2>



<p>Are you ready to dive into the world of API development using the power of .NET Core Minimal APIs? In this comprehensive guide, we&#8217;ll go through the process of building a Todo List API from scratch. By the end, you&#8217;ll have a clear understanding of each step and how Minimal APIs can streamline your development process.</p>



<h3 class="wp-block-heading">Step 1: Get Started with a New .NET Core Project</h3>



<h4 class="wp-block-heading">Creating a Minimal API using Command Prompt</h4>



<p>To kick things off, let&#8217;s create a new .NET Core project named &#8220;TodoApi&#8221; using the command-line interface:</p>



<p><code>dotnet new web -n TodoApi</code></p>



<p>This simple command sets up the foundation for our Todo List API project. </p>



<p>We can even create a new project using Visual Studio by following below steps.</p>



<h4 class="wp-block-heading">Creating a Minimal API with Visual Studio: Step-by-Step Guide</h4>



<ul class="wp-block-list">
<li>Open Visual Studio and click on &#8220;Create a New Project&#8221;  </li>
</ul>



<ul class="wp-block-list">
<li>Select &#8220;ASP.NET Core Web API&#8221; project templete as shown below and click on Next</li>
</ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="640" height="333" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=640%2C333&#038;ssl=1" alt="Minimal API" class="wp-image-129" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=1024%2C532&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=300%2C156&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=768%2C399&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=1536%2C798&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=850%2C441&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?w=1914&amp;ssl=1 1914w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<ul class="wp-block-list">
<li>Enter a project name, choose a location, and click &#8220;Create.&#8221;</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="339" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=640%2C339&#038;ssl=1" alt="Minimal API" class="wp-image-130" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=1024%2C542&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=300%2C159&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=768%2C407&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=1536%2C813&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=850%2C450&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?w=1894&amp;ssl=1 1894w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<ul class="wp-block-list">
<li>In the next screen, we configure the Minimal API. Choose options such as HTTPS, OpenAPI support. Make sure to uncheck &#8220;Use Controllers (uncheck ro use minimal APIs)&#8221;. Click on Create. </li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="334" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=640%2C334&#038;ssl=1" alt="Minimal API" class="wp-image-133" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=1024%2C534&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=300%2C156&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=768%2C400&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=1536%2C800&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=850%2C443&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?w=1900&amp;ssl=1 1900w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<h3 class="wp-block-heading">Step 2: Navigate to the Minimal API Project Directory</h3>



<p>Navigate to the project directory just created:</p>



<p><code>cd TodoApi</code></p>



<h3 class="wp-block-heading">Step 3: Define Your Todo Model</h3>



<p>Create <code>Models</code> folder within the project and create a file named <code>Todo.cs</code>. This is where you&#8217;ll define the structure of your todo items:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="306" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=640%2C306&#038;ssl=1" alt="Minimal API" class="wp-image-135" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=1024%2C489&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=300%2C143&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=768%2C367&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=850%2C406&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?w=1051&amp;ssl=1 1051w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<p><code>Todo</code> model will hold essential information about each todo task, including an <code>Id</code>, <code>Title</code>, and <code>IsCompleted</code> flag.</p>



<h3 class="wp-block-heading">Step 4: Create the Minimal API</h3>



<p>Open the <code>Program.cs</code> file and add the following code before app.Run():</p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p><strong>//Todo List Code</strong><br>var todos = new List();<br>int nextId = 1;</p>



<p><strong>// GET endpoint to retrieve the list of todos</strong><br>app.MapGet(&#8220;/todos&#8221;, () =&gt; todos);</p>



<p><strong>// POST endpoint to add a new todo</strong><br>app.MapPost(&#8220;/todos&#8221;, (Todo todo) =&gt; {<br>todo.Id = nextId++;<br>todos.Add(todo);<br>return todo;<br>});</p>



<p><strong>// PUT endpoint to update an existing todo</strong><br>app.MapPut(&#8220;/todos/{id}&#8221;, (int id, Todo updatedTodo) =&gt; {<br><strong>// Find the existing todo with the provided ID</strong><br>var existingTodo = todos.FirstOrDefault(t =&gt; t.Id == id);<br>if (existingTodo != null)<br>{<br><strong>// Update the title and completion status with the new values</strong><br>existingTodo.Title = updatedTodo.Title;<br>existingTodo.IsCompleted = updatedTodo.IsCompleted;<br>return Results.Ok(existingTodo);<br>}<br>return Results.NotFound();<strong>// Return &#8220;Not Found&#8221; if the todo doesn&#8217;t exist</strong><br>});</p>



<p><strong>// DELETE endpoint to remove a todo</strong><br>app.MapDelete(&#8220;/todos/{id}&#8221;, (int id) =&gt; {<br><strong>// Find the todo to remove based on the provided ID</strong><br>var todoToRemove = todos.FirstOrDefault(t =&gt; t.Id == id);</p>



<pre class="wp-block-code"><code>if (todoToRemove != null)
{
    todos.Remove(todoToRemove); <strong>// Remove the todo from the list</strong>
    return Results.Ok(); <strong>// Return "Ok" to indicate success</strong>
}

return Results.NotFound(); <strong>// Return "Not Found" if the todo doesn't exist</strong></code></pre>



<p>});</p>
</div></div>
</div></div>
</div></div>



<p>Let&#8217;s break it down:</p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<aside class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>using TodoApi.Models;</p>



<p>var builder = WebApplication.CreateBuilder(args);</p>



<p>var app = builder.Build();</p>



<p><strong>//Todo List Code</strong><br>var todos = new List();<br>int nextId = 1;</p>



<p><strong>// GET endpoint to retrieve the list of todos</strong><br>app.MapGet(&#8220;/todos&#8221;, () =&gt; todos);</p>
</div></div>
</div></div>
</div></div>
</div></aside>
</div></div>



<ul class="wp-block-list">
<li><code>WebApplication.CreateBuilder</code> initializes a builder for the web application.</li>



<li><code>builder.Build()</code> creates your application.</li>



<li>We set up an empty list named <code>todos</code> to hold your todo items.</li>



<li><code>nextId</code> helps manage the IDs for new todos.</li>



<li>We define a <code>GET</code> endpoint at <code>/todos</code> to retrieve your list of todos.</li>
</ul>



<p></p>



<p class="has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><strong>// POST endpoint to add a new todo</strong><br>app.MapPost(&#8220;/todos&#8221;, (Todo todo) =&gt; {<br>todo.Id = nextId++;<br>todos.Add(todo);<br>return todo;<br>});</p>



<p>In this block:</p>



<ul class="wp-block-list">
<li>We define a <code>POST</code> endpoint at <code>/todos</code> for adding new todos.</li>



<li>Each new todo is assigned a unique ID and added to the <code>todos</code> list.</li>



<li>The newly added todo is then returned as a response.</li>
</ul>



<p></p>



<p class="has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><strong>// PUT endpoint to update an existing todo</strong><br>app.MapPut(&#8220;/todos/{id}&#8221;, (int id, Todo updatedTodo) =&gt; {<br><strong>// Find the existing todo with the provided ID</strong><br>var existingTodo = todos.FirstOrDefault(t =&gt; t.Id == id);<br>if (existingTodo != null)<br>{<br><strong>// Update the title and completion status with the new values</strong><br>existingTodo.Title = updatedTodo.Title;<br>existingTodo.IsCompleted = updatedTodo.IsCompleted;<br>return Results.Ok(existingTodo);<br>}<br>return Results.NotFound();<strong>// Return &#8220;Not Found&#8221; if the todo doesn&#8217;t exist</strong><br>});</p>



<p>Now for the <code>PUT</code> endpoint:</p>



<ul class="wp-block-list">
<li>We define a <code>PUT</code> endpoint at <code>/todos/{id}</code> for updating existing todos.</li>



<li>We find the todo with the provided <code>id</code> in the <code>todos</code> list.</li>



<li>If the todo exists, we update its <code>Title</code> and <code>IsCompleted</code> properties based on the provided <code>updatedTodo</code> and return the updated todo.</li>



<li>If the todo doesn&#8217;t exist, a &#8220;Not Found&#8221; result is returned.</li>
</ul>



<p></p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p><strong>// DELETE endpoint to remove a todo</strong><br>app.MapDelete(&#8220;/todos/{id}&#8221;, (int id) =&gt; {<br><strong>// Find the todo to remove based on the provided ID</strong><br>var todoToRemove = todos.FirstOrDefault(t =&gt; t.Id == id);</p>



<pre class="wp-block-code"><code>if (todoToRemove != null)
{
    todos.Remove(todoToRemove); <strong>// Remove the todo from the list</strong>
    return Results.Ok(); <strong>// Return "Ok" to indicate success</strong>
}

return Results.NotFound(); <strong>// Return "Not Found" if the todo doesn't exist</strong></code></pre>



<p>});</p>
</div></div>
</div></div>



<p>And finally, the <code>DELETE</code> endpoint:</p>



<ul class="wp-block-list">
<li>We define a <code>DELETE</code> endpoint at <code>/todos/{id}</code> for removing todos.</li>



<li>We locate the todo to remove in the <code>todos</code> list based on the provided <code>id</code>.</li>



<li>If the todo exists, we remove it from the list and return an &#8220;Ok&#8221; result to indicate success.</li>



<li>If the todo doesn&#8217;t exist, a &#8220;Not Found&#8221; result is returned.</li>
</ul>



<h3 class="wp-block-heading">Step 5: Run Your Application</h3>



<p>Time to see your Todo List API in action! Run the application with:</p>



<p><code>Run dotnet run</code> in command prompt or click on TodoApi in Visual Studio as highlighted below.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="218" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=640%2C218&#038;ssl=1" alt="" class="wp-image-136" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=1024%2C349&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=300%2C102&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=768%2C262&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=1536%2C523&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=850%2C290&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?w=1887&amp;ssl=1 1887w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<h3 class="wp-block-heading">Step 6: Interact with Your Todo List API</h3>



<p>Here&#8217;s how you can interact with your Todo List API:</p>



<ul class="wp-block-list">
<li><strong>GET</strong> <code>/todos</code>: Retrieve the list of todos.</li>



<li><strong>POST</strong> <code>/todos</code>: Add a new todo.</li>



<li><strong>PUT</strong> <code>/todos/{id}</code>: Update an existing todo.</li>



<li><strong>DELETE</strong> <code>/todos/{id}</code>: Delete a todo.</li>
</ul>



<p>Congratulations! You&#8217;ve successfully built a Todo List API using .NET Core Minimal APIs. This guide took you through the process step by step and provided sample code for each stage.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>By following this comprehensive guide, you&#8217;ve unlocked the power of .NET Core Minimal APIs to create a functional Todo List API. This step-by-step journey, complete with detailed explanations and code samples, will equip you with the knowledge you need to craft your own APIs efficiently. This code can further be enhanced by adding Repositories and other functinalilties based on requirement.</p>



<p>If you like this post and are interested to learn more about MInimal API, please go through below links for other related posts</p>



<p><a href="https://codingizfun.com/category/dotnet-interview-questions/dotnet-core-interview-questions/minimal-api/">Minimal API Archives &#8211; Coding Tutorial (codingizfun.com)</a></p>



<h2 class="wp-block-heading">References</h2>



<p><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview?view=aspnetcore-7.0">https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview?view=aspnetcore-7.0</a></p>



<p><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0">https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0</a></p>



<p></p>
<p>The post <a href="https://codingizfun.com/minimal-api/">Minimal API</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/minimal-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">126</post-id>	</item>
		<item>
		<title>Monolithic vs Microservices</title>
		<link>https://codingizfun.com/monolithic-vs-microservices/</link>
					<comments>https://codingizfun.com/monolithic-vs-microservices/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 23 Jan 2023 23:49:27 +0000</pubDate>
				<category><![CDATA[Dotnet Interview Questions and Topics]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=104</guid>

					<description><![CDATA[<p>In this article, we will see the Monolithic and Microservices architecture differences. Monolith Monolith is an application deployed as a single unit in single or multiple servers behind a Load Balancer. You have a User Interface, Business Logic, and Data Access Layer interacting with a database. Advantages Disadvantages Microservices Microservices is an architecture pattern where...</p>
<p>The post <a href="https://codingizfun.com/monolithic-vs-microservices/">Monolithic vs Microservices</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this article, we will see the Monolithic and Microservices architecture differences.</p>



<h2 class="wp-block-heading"><strong>Monolith</strong></h2>



<p>Monolith is an application deployed as a single unit in single or multiple servers behind a Load Balancer. You have a User Interface, Business Logic, and Data Access Layer interacting with a database.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-2.png?resize=486%2C573&#038;ssl=1" alt="monolithic vs microservices" class="wp-image-114" style="width:486px;height:573px" width="486" height="573" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-2.png?w=486&amp;ssl=1 486w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-2.png?resize=254%2C300&amp;ssl=1 254w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-2.png?resize=300%2C354&amp;ssl=1 300w" sizes="(max-width: 486px) 100vw, 486px" data-recalc-dims="1" /><figcaption class="wp-element-caption">Monolith Architecture</figcaption></figure></div>


<h3 class="wp-block-heading"><strong>Advantages</strong></h3>



<ol class="wp-block-list">
<li>Easy to debug and deploy since there is only one application.</li>



<li>Easy to develop and maintain as we have a single application where UI calls the web service or API without worrying about API backward compatibility and version management. Also, there is only a single point of failure.</li>



<li>Only one repository or codebase is easy to maintain and test than integrating multiple services for testing.</li>



<li>Less latency as communication between layers in the application is local.</li>
</ol>



<h3 class="wp-block-heading"><strong>Disadvantages</strong></h3>



<ol class="wp-block-list">
<li>Tightly coupled code as an issue in one piece of code might affect other parts of code.</li>



<li>Hard to maintain as the application grows in size.</li>



<li>Scalability is a concern as the application as a whole is scaled irrespective of usage. For instance, if we have a Monolith application created with Login, Storage, Retrieval, and Polling functionalities in place. During peak time, if the Retrieval part of the application experiences high traffic, the entire application is scaled up even though other independent parts do not need scaling.</li>



<li>Irreversible choice of coding language as a rewrite is required to choose a different language.</li>
</ol>



<h2 class="wp-block-heading"><strong>Microservices</strong></h2>



<p>Microservices is an architecture pattern where an application consists of several small deployable services, which communicate to share data.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="369" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?resize=640%2C369&#038;ssl=1" alt="monolithic vs microservices" class="wp-image-113" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?resize=1024%2C590&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?resize=300%2C173&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?resize=768%2C443&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?resize=850%2C490&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/02/image-1.png?w=1027&amp;ssl=1 1027w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /><figcaption class="wp-element-caption">Microservices Architecture</figcaption></figure>



<h3 class="wp-block-heading">Advantages</h3>



<ol class="wp-block-list">
<li>Decoupled code and lightweight.</li>



<li>Easy to maintain when the application has a lot of reusable code.</li>



<li>Better scalability as there is an option to scale components individually.</li>



<li>Choice of using multiple programming languages for different services based on the requirement.</li>



<li>Better Fault tolerance as an issue in a microservice will only affect that part of the application.</li>
</ol>



<h3 class="wp-block-heading">Disadvantages</h3>



<ol class="wp-block-list">
<li>Deployment is bit tedious as it involves maintenance across different services.</li>



<li>Difficulties in maintaining the code dependencies and testing multiple codebases.</li>



<li>Latency often arises due to the communication calls made between services across the network.</li>
</ol>



<h3 class="wp-block-heading">What to opt for?</h3>



<h4 class="wp-block-heading">Monolith</h4>



<ol class="wp-block-list">
<li>When the application is simple with less release time to market.</li>



<li>Limited scaling with moderate application size.</li>
</ol>



<h4 class="wp-block-heading">Microservices</h4>



<ol class="wp-block-list">
<li>For largescale applications which involve CPU-intensive business logic or complex real-time data processing.</li>



<li>When the application has independent, reusable modules.</li>
</ol>



<h3 class="wp-block-heading">References</h3>



<p>For more details related to Monolithic vs Microservices, please refer links below</p>



<p><a href="https://www.tutorialspoint.com/microservice_architecture/microservice_architecture_introduction.htm">https://www.tutorialspoint.com/microservice_architecture/microservice_architecture_introduction.htm</a></p>



<p><a href="https://www.geeksforgeeks.org/monolithic-architecture/">https://www.geeksforgeeks.org/monolithic-architecture/</a></p>
<p>The post <a href="https://codingizfun.com/monolithic-vs-microservices/">Monolithic vs Microservices</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/monolithic-vs-microservices/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">104</post-id>	</item>
		<item>
		<title>Javascript Maps vs Objects</title>
		<link>https://codingizfun.com/javascript-maps/</link>
					<comments>https://codingizfun.com/javascript-maps/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 07 Sep 2022 12:48:32 +0000</pubDate>
				<category><![CDATA[Angular and Javascript Interview questions]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=29</guid>

					<description><![CDATA[<p>Initially, when I read about Maps, I had this question running in my mind. Why use Javascript Maps, when objects serve the same purpose? &#160; &#160; Unanimous answer found in most of the websites is the reduction of complexity. Let&#8217;s dive into this in detail. In a Nutshell, Maps hold key-value pairs and have below...</p>
<p>The post <a href="https://codingizfun.com/javascript-maps/">Javascript Maps vs Objects</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Initially, when I read about Maps, I had this question running in my mind. Why use Javascript Maps, when objects serve the same purpose?</p>



<p>&nbsp; &nbsp; Unanimous answer found in most of the websites is the reduction of complexity. Let&#8217;s dive into this in detail.</p>



<p>In a Nutshell, Maps hold key-value pairs and have below advantages over Objects</p>



<ul class="wp-block-list">
<li>&nbsp;&nbsp; &nbsp;First, we can use different data types like objects, functions and Primitive types as keys which is not possible with objects. Objects can only have strings as keys.</li>



<li>&nbsp; &nbsp; Second, Maps are iterable. Objects can be iterated by converting to an array or checking if a property belongs to it and not a prototype.</li>
</ul>



<p>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Confusing??? Let&#8217;s try iterating through a Javascript object.</p>



<h5 class="wp-block-heading">       Iterating through Javascript Object</h5>



<h6 class="wp-block-heading">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;a.&nbsp;Use &#8220;Object.keys&#8221; or &#8220;Object.getOwnPropertyNames&#8221; with &#8220;foreach&#8221;</h6>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-8ROSAkkLlTo/X0fcDGaB4iI/AAAAAAAAM84/pKkhrLahJiAfxOzR1jZy35IOrxKJqQJ0gCLcBGAsYHQ/s0/Img1.jpg?w=640&#038;ssl=1" alt="JS Object-iteration-Javascript Maps" title="JS Object-iteration-Javascript Maps" data-recalc-dims="1"/></a></figure></div>

<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-6bEnrsh0xHY/X0fdFgqc7HI/AAAAAAAAM9A/bCihOf4gtB0ecZ3zJRde79wlDgCNNUNlACLcBGAsYHQ/s0/Img2.PNG?w=640&#038;ssl=1" alt="JS Object-iteration1-Javascript Maps" title="JS Object-iteration1-Javascript Maps" data-recalc-dims="1"/></a></figure></div>


<h6 class="wp-block-heading">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b. Use &#8220;for..in&#8221; with &#8220;hasOwnProperty&#8221;</h6>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-TDyvm3Wdqz0/X0femwy9n1I/AAAAAAAAM9M/YuTDKCD9Z0YWQGRC5pLV_q5jQa1xeZf2gCLcBGAsYHQ/s0/Img3.PNG?w=640&#038;ssl=1" alt="JS Object-foriteration-Javascript Maps" title="JS Object-foriteration-Javascript Maps" data-recalc-dims="1"/></a></figure></div>


<h5 class="wp-block-heading">&nbsp; &nbsp;      Iterating through Maps in Javascript</h5>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-Xv3PD-IOslE/X0fgLGVXxyI/AAAAAAAAM9Y/LECDHGTxJc8nTMYCYohTbaAlNE4-BBAJACLcBGAsYHQ/s0/Img4.PNG?w=640&#038;ssl=1" alt="Javascript Maps-iteration" title="Javascript Maps-iteration" data-recalc-dims="1"/></a></figure></div>


<p>&nbsp; &nbsp;&nbsp;      It is simple compared to objects. Just use a for loop, that&#8217;s it!!!</p>



<p>&nbsp; &nbsp; 3. Retrieving size of a map is easy by using &#8220;size&#8221; property.&nbsp;</p>



<h5 class="wp-block-heading"><em><u><strong>Where to use</strong></u></em></h5>



<p>Let&#8217;s see where we can use Javascript Maps. Javascript Maps are useful to store &#8220;key-value&#8221; pairs. For instance, let&#8217;s consider &#8220;Two-sum problem&#8221;.&nbsp;</p>



<h6 class="wp-block-heading"><em><u><strong>Problem Definition</strong></u></em></h6>



<p>Given an array, return indices of two numbers such that they add up to the given sum</p>



<h6 class="wp-block-heading"><em><u><strong>Solution</strong></u></em></h6>



<figure class="wp-block-image"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-7JQjwclBowA/X0i2YcuGljI/AAAAAAAAM-U/kJHe3cdU8IQKYxVNVQ9BwNu0VKB8l-ThgCLcBGAsYHQ/s0/Img8.PNG?w=640&#038;ssl=1" alt="Javascript Maps-Two Sum" title="Javascript Maps-Two Sum" data-recalc-dims="1"/></a></figure>



<ol class="wp-block-list">
<li>Here, we are creating a Map with &#8220;Target-number&#8221;(difference of current number from required sum) as key and index as value. </li>



<li>From next index, we check if the &#8220;Target-number&#8221; exists in the array and return the Array indices if found. </li>



<li>If not found, we continue with step 1.</li>
</ol>



<p>Let&#8217;s debug the code for given input</p>



<p>i=0&nbsp; &nbsp; arrayMap[0] does not exist and it adds (7, 0) to arrayMap.</p>



<p>i=1&nbsp; &nbsp; arrayMap[7] =0 and we will return [0,1] which are the indices.</p>



<h5 class="wp-block-heading"><em><u>Javascript Maps &#8211; The Tricky Part</u></em></h5>



<p>&nbsp; &nbsp; We all know about &#8220;NaN&#8221; in Javascript. It does not have a real value and comparing it to itself doesn&#8217;t return true.&nbsp; &nbsp;&nbsp;</p>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-6sa3Bp2G_Ig/X0fh4TUR1AI/AAAAAAAAM9k/hhGCgxBxaEot3pskdsYHGj9M30aapcMJwCLcBGAsYHQ/s0/Img5.PNG?w=640&#038;ssl=1" alt="Javascript Maps-NaN" title="Javascript Maps-NaN" data-recalc-dims="1"/></a></figure></div>


<p>Now, here&#8217;s a tricky question. Guess the output of code below</p>



<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;let obj= new Map();</p>



<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;obj.set(&#8220;Name&#8221;,&#8221;Test&#8221;);</p>



<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;obj.set(NaN,&#8221;Test1&#8243;);</p>



<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;obj.get(Nan);</p>



<p>If you answer is &#8220;Test1&#8221;, you are right.</p>


<div class="wp-block-image">
<figure class="aligncenter"><a href="https://www.blogger.com/u/1/blog/post/edit/346563365482566825/1497032291603584919#"><img decoding="async" src="https://i0.wp.com/1.bp.blogspot.com/-54p6QgPqda4/X0fj_LAtPDI/AAAAAAAAM9w/F9CXEZdPvOI3mpQyqeMFi7yOJTwR6ohawCLcBGAsYHQ/s0/Img6.PNG?w=640&#038;ssl=1" alt="Javascript Maps-NaN Retrieve" title="Javascript Maps-NaN Retrieve" data-recalc-dims="1"/></a></figure></div>


<p>We can use &#8220;NaN&#8221; as key in Javascript Maps. Appropriate value rendered with &#8220;NaN&#8221; key.</p>



<p>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;That&#8217;s it, there ends my first post. Hope it was not boring and happy coding!!!</p>



<h5 class="wp-block-heading">References</h5>



<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map &#8211; JavaScript | MDN (mozilla.org)</a></p>



<p><a href="https://www.w3schools.com/js/js_maps.asp">JavaScript Maps (w3schools.com)</a></p>
<p>The post <a href="https://codingizfun.com/javascript-maps/">Javascript Maps vs Objects</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/javascript-maps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">29</post-id>	</item>
	</channel>
</rss>
