<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shreya Prasad</title>
    <description>The latest articles on DEV Community by Shreya Prasad (@shreyapd06).</description>
    <link>https://dev.to/shreyapd06</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F276091%2Fc583f128-5360-4497-a8d3-ffdd664ed4d0.jpeg</url>
      <title>DEV Community: Shreya Prasad</title>
      <link>https://dev.to/shreyapd06</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shreyapd06"/>
    <language>en</language>
    <item>
      <title>Understand "this" in JavaScript</title>
      <dc:creator>Shreya Prasad</dc:creator>
      <pubDate>Sun, 01 May 2022 10:42:35 +0000</pubDate>
      <link>https://dev.to/shreyapd06/this-keyword-in-js-4g7b</link>
      <guid>https://dev.to/shreyapd06/this-keyword-in-js-4g7b</guid>
      <description>&lt;p&gt;&lt;em&gt;"&lt;strong&gt;This&lt;/strong&gt; keyword refers to the object it belongs to."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You must have heard this line almost everywhere, but never fully understood what it actually means? Let's understand &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;this&lt;/strong&gt;&lt;/em&gt; is nothing more than a reserved keyword in JavaScript that points to the object it is present inside.&lt;/p&gt;

&lt;h2&gt;
  
  
  Global Context:
&lt;/h2&gt;

&lt;p&gt;Alone, this refers to the global object. Global object is nothing but the window object created by the JavaScript engine in the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz498rhifpx2t88alup7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz498rhifpx2t88alup7q.png" alt="Console with "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I learn better when I visualise concepts. That's why I've created few illustrations to simplify &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famqmoof2vdprx0uge6eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famqmoof2vdprx0uge6eb.png" alt="this inside window object"&gt;&lt;/a&gt;&lt;br&gt;
                   &lt;em&gt;&lt;strong&gt;this&lt;/strong&gt; in a global context.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Functional context:
&lt;/h2&gt;

&lt;p&gt;Now what happens if &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; is used inside a function?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2l1swkj7hr9ruizv24s5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2l1swkj7hr9ruizv24s5.png" alt="this inside a function"&gt;&lt;/a&gt;&lt;br&gt;
                     &lt;em&gt;&lt;strong&gt;this&lt;/strong&gt; inside a function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It still point to window object! But why?&lt;/p&gt;

&lt;p&gt;Because that function is present globally, so technically it is present inside window object. So, this refers to the global object, i.e. window.&lt;/p&gt;

&lt;p&gt;So far this has been pointing to window object only. Nothing has changed. So when does it return a different value that we all have been reading about? &lt;/p&gt;

&lt;h2&gt;
  
  
  Custom Object Context:
&lt;/h2&gt;

&lt;p&gt;Let's see what happens if &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; is used inside an object that we create?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ehk7ojhjw22kdh4jq5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ehk7ojhjw22kdh4jq5b.png" alt="this inside a custom object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a method, this refers to the person object. It means that this will point to the object inside which we are using "this" keyword.&lt;/p&gt;

&lt;h2&gt;
  
  
  To summarise:
&lt;/h2&gt;

&lt;p&gt;Globally, &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; will point to window object because &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; is being used inside window object. But if we create an object of our own and use &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; inside that object, then it will point to that particular object. &lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Info:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We will talk about the behaviour of &lt;strong&gt;&lt;em&gt;this&lt;/em&gt;&lt;/strong&gt; inside an arrow function in another blog.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dmitripavlutin.com/javascript-this-interview-questions/" rel="noopener noreferrer"&gt;Tricky questions around this keyword&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Introducing Angular Mini Blog Series - Part 1</title>
      <dc:creator>Shreya Prasad</dc:creator>
      <pubDate>Sat, 17 Jul 2021 12:27:22 +0000</pubDate>
      <link>https://dev.to/shreyapd06/introducing-angular-mini-blog-series-part-1-4hdg</link>
      <guid>https://dev.to/shreyapd06/introducing-angular-mini-blog-series-part-1-4hdg</guid>
      <description>&lt;p&gt;In this series of blog posts, we are going to learn about Angular from beginning. I will try to keep the blogs very short, crisp and easy to understand.&lt;br&gt;
Go to &lt;a href="https://angular.io/" rel="noopener noreferrer"&gt;Angular's official website&lt;/a&gt; if you want to learn basic stuff like: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Angular is &lt;/li&gt;
&lt;li&gt;How to create a basic application&lt;/li&gt;
&lt;li&gt;Generate Components&lt;/li&gt;
&lt;li&gt;Start Angular Live Server&lt;/li&gt;
&lt;li&gt;Basic Directory Structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, we will get started with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;li&gt;Modules &lt;/li&gt;
&lt;li&gt;How Angular Apps loads&lt;/li&gt;
&lt;li&gt;AppModule&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;You know about &lt;code&gt;&amp;lt;html&amp;gt;, &amp;lt;head&amp;gt; and &amp;lt;body&amp;gt;&lt;/code&gt; tags and so on right? These are native HTML elements that are provided to us. But what if we could create our own HTML elements?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodvpb2y8m0ctttbx3oc6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodvpb2y8m0ctttbx3oc6.gif" alt="surprised-gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, this is where components come in! Components are typically custom built HTML elements, and each of these elements can instantiate only one component. &lt;br&gt;
The best part is - they are reusable, which means that one you create a component, you can utilize it multiple times in your application! Also, if you need to modify it, simply change one file and those changes will be reflected wherever you have used this component! Some popular examples of components are Navigation Bar, Footer, Side Menu etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgeeksarray.com%2Fimages%2Fblog%2FAngular-Component-example.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgeeksarray.com%2Fimages%2Fblog%2FAngular-Component-example.png" alt="component"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Modules
&lt;/h2&gt;

&lt;p&gt;Angular is not present as one monolithic code base. Instead, it is divided into modules which are present in different locations and their utility is independent of each other. Modules provide the highest level of abstraction available within the Angular framework. Everything in your app is ultimately structured around modules. This is powerful! It means that you can easily encapsulate code within a module and share or reuse it throughout your app.&lt;/p&gt;

&lt;p&gt;We use &lt;strong&gt;@NgModule&lt;/strong&gt; decorator to declare a class as module.&lt;br&gt;
&lt;strong&gt;@NgModule&lt;/strong&gt; decorator contains below properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;declarations&lt;/strong&gt;: It includes component, directives, pipes that belongs to this module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;exports&lt;/strong&gt;: It include component, directives, pipes which can be accessible to other NgModule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;imports&lt;/strong&gt;: Contains Modules whose exported classes needed by this module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;providers&lt;/strong&gt;: Contains the services generated by this module.
bootstrap: Initialize root component
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;AppComponent&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;BrowserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;AppRoutingModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;FormsModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;CoreModule&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  How Angular App loads?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5b3999l9ojj0b7h124sf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5b3999l9ojj0b7h124sf.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you see this index.html? This is the page that's mainly rendered by Angular. It consists of only 1 component - &lt;code&gt;&amp;lt;app-root&amp;gt;&lt;/code&gt;. This &lt;code&gt;&amp;lt;app-root&amp;gt;&lt;/code&gt; is the root component which encapsulates all the child components, i.e the components you create and bootstraps them to render everything inside it on index.html.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Demo Angular App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;app-root&amp;gt;&amp;lt;/app-root&amp;gt;&lt;/span&gt; //only this component will be present 
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  AppModule
&lt;/h2&gt;

&lt;p&gt;When looking at the Angular module system, all things must begin with the app module. The root app module is a necessary portion of every Angular app. By default, this module is named AppModule, although it is possible to rename this module. The AppModule is the entry point to your app.&lt;/p&gt;

&lt;p&gt;A newly generated AppModule would look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/platform-browser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NgModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;AppComponent&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;BrowserModule&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is a good practice to keep this file as minimal as possible. This can be done by importing only those modules that are absolutely necessary for your app to load initially. Or only declare Angular components, directives, or pipes that you want globally available.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✋ Hey! Before you go 🏃‍
&lt;/h2&gt;

&lt;p&gt;If you enjoyed this article, I recommend you to stay tuned to my &lt;a href="https://twitter.com/shreyacasmalert" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my first time on Dev.to so I would really appreciate if you would like my blog or share constructive feedback!&lt;/em&gt;💖&lt;/p&gt;

&lt;p&gt;In the next blog, we will cover data binding and it's various types so stay tuned! ✨&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
