<?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>Angular and Javascript Interview questions Archives - Coding Tutorial</title>
	<atom:link href="https://codingizfun.com/category/angular-js-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>https://codingizfun.com/category/angular-js-interview-questions/</link>
	<description>Software Architecture and javascript concepts explained in detail with examples</description>
	<lastBuildDate>Fri, 23 Feb 2024 22:20:49 +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>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>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>
