<?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: Rahul Yadav</title>
    <description>The latest articles on DEV Community by Rahul Yadav (@rahulyadav139).</description>
    <link>https://dev.to/rahulyadav139</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%2F767942%2F11166795-8943-409b-91b7-53f58fb05f39.jpeg</url>
      <title>DEV Community: Rahul Yadav</title>
      <link>https://dev.to/rahulyadav139</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahulyadav139"/>
    <language>en</language>
    <item>
      <title>My Experience</title>
      <dc:creator>Rahul Yadav</dc:creator>
      <pubDate>Thu, 13 Apr 2023 17:39:09 +0000</pubDate>
      <link>https://dev.to/rahulyadav139/my-experience-24cm</link>
      <guid>https://dev.to/rahulyadav139/my-experience-24cm</guid>
      <description>&lt;p&gt;When I began my web development journey 1.5 years ago, I was uncertain if it was the right path for me. Prior to this, I had left my job to prepare for the ESE, but after two unsuccessful attempts, I realized that the investment of my time was too great, especially at my age. I felt lost and unsure about what to do next with my future, until one day during a conversation with my younger brother, we began discussing potential career paths. Despite having no background in computer science, my brother suggested that I explore web development as a potential avenue. He based this suggestion on the fact that I had previously rooted some phones and updated firmware, as well as installed pirated Windows operating systems on my friend's laptop. Not kidding this was his only reasoning behind it.&lt;/p&gt;

&lt;p&gt;Now, looking back, I realize that pursuing web development was the best decision I could have made. Growing up in a farming family where higher education was not a priority, it was challenging to determine what would work for me. This post is about my journey and the process of connecting the dots backward to make sense of how I got to where I am today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logic building&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Looking back on my career, I remember the time when I was working at a service-based company. I had started there as an executive but had quickly risen through the ranks to become a team leader. At first, my job was simple - I was responsible for data cleaning. The company I worked for had been hired by a US-based e-commerce firm to list their products on their website, and my task was to ensure that the data was accurate and up-to-date.&lt;/p&gt;

&lt;p&gt;As I progressed in my role, my responsibilities grew. I had to send daily reports to my manager, which was a tedious task. Every morning, I would come into the office and spend 1-1.5 hours preparing these reports. The data I used for the reports came from my team members and other teams in the company.&lt;/p&gt;

&lt;p&gt;One day, I realized that this process could be automated. If I created a template and asked my team members to fill in the data before leaving the office, it would save me a lot of time. I called this template the "master file" because it served as a local data source for my team, and I could get reports at the end of each day. One section of the file was dedicated to monitoring my team's performance.&lt;/p&gt;

&lt;p&gt;I want to emphasize that I truly hated the process of preparing these reports. However, this hatred ultimately led me to find a solution. At the time, I had no experience using Microsoft Excel or any knowledge of the different formulas that could be used. But because of this repetitive and unnecessary task, I was motivated to find a way to streamline the process.&lt;/p&gt;

&lt;p&gt;It took me a whole month to create the master file, and I had to search on Google and ask my seniors for help with Excel formulas. But the time and effort paid off, and I was able to save a lot of time in the long run. Looking back, I realize that creating that file helped me develop my logical and problem-solving skills, even though I had no idea that I was doing so at the time.&lt;/p&gt;

&lt;p&gt;Personally, I found that exploring different Excel formulas and experimenting with logical solutions was an excellent way to sharpen my analytical thinking and enhance my ability to solve problems. Even though these exercises may seem small, it benefited me. To succeed in a career in development, I think it is crucial to cultivate robust problem-solving abilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patience&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was once an aspirant for the Union Public Service Commission (UPSC) exam, which taught me an invaluable lesson in patience. Let me share my story in more detail. It's really hard for mechanical engineers to get good jobs in India. It's like finding something very valuable in a place where you don't expect it. That's why I thought getting a government job is the only choice they have. During college, I had previously prepared for the GATE exam, but this time I choose UPSC ESE. The UPSC syllabus is vast and cannot be completed in a day, a month, or even a year. It requires consistent daily effort and patience to cover each chapter thoroughly. As one of my teachers once said, the UPSC exam is not a 200-meter sprint, it's a marathon. This meant that I had to cultivate patience and discipline to prepare consistently every day.&lt;/p&gt;

&lt;p&gt;The same traits of patience and discipline are required when you choose a new career path in your life. Often, it can be difficult to acquire the skills that the job market demands and it's easy to feel stuck and seek help. Sometimes you might even regret choosing a difficult career path and think that you should have opted for something easier. However, this is a common feeling for every newcomer in any field. I faced the same problem when I chose to pursue a new career path in web development.&lt;/p&gt;

&lt;p&gt;I started learning the basics of JavaScript, starting with how it works, what an event loop is, and other fundamentals. However, it was overwhelming, and even writing a simple function proved to be challenging. Sometimes, I would be stuck on a problem for two days straight. At that time, there was no ChatGPT to help me find solutions quickly. However, I learned that finding solutions on Google is a skill, and if I had not been patient enough while learning web development, I would not have made it this far.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Peer Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After my second failed attempt at the UPSC exam, I came to the realization that I needed to acquire a skill that would provide me with a stable livelihood. Having only data entry experience, I turned to my brother for advice on what skill to learn. After a lengthy discussion, we agreed that web development was a good option. With no prior knowledge of coding, I started by watching YouTube videos to learn the basics of JavaScript. While the videos were helpful, I realized I needed more structured learning, so I invested 2000 rupees in Udemy courses on the MERN tech stack.&lt;/p&gt;

&lt;p&gt;After two months of dedicated learning, I had a good grasp of the basics of JavaScript and was able to build a few projects. I continued to practice by learning React JS and building more projects. However, I knew I needed more guidance to really improve, so I joined a boot camp.&lt;/p&gt;

&lt;p&gt;This was a life-changing experience for me. The boot camp allowed me to meet people from different career backgrounds who were also learning to code. The six months of the boot camp were intense, with days filled with practice and nights spent reviewing 50+ git PRs.&lt;/p&gt;

&lt;p&gt;One of the most valuable aspects of the boot camp was learning from my peers. Seeing another person's coding style and asking them why they wrote the code in a particular way was enlightening. I learned new approaches and ways of thinking about problems that I had never considered before. Although the long nights of coding and the pressure to learn quickly were challenging, I embraced them, knowing that I was on a journey of growth and learning.&lt;/p&gt;

&lt;p&gt;As with any new skill, there were moments of frustration and downtime. But being surrounded by classmates who were also learning and growing made it easier to discuss these issues and find solutions together. In many ways, the boot camp felt like going back to school, but with the added benefit of being surrounded by like-minded individuals who were all striving to better themselves.&lt;/p&gt;

&lt;p&gt;—-&lt;/p&gt;

&lt;p&gt;I discussed the three characteristics that led me to pursue a career in web development. However, at that time if someone asked me why I chose to become a developer, I didn't have a clear answer. Nonetheless, I believe that these traits have been helpful for me, and I can easily empathize with anyone who has just embarked on their web development journey.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Beginner's Guide to OOP in JavaScript</title>
      <dc:creator>Rahul Yadav</dc:creator>
      <pubDate>Sun, 22 May 2022 18:12:42 +0000</pubDate>
      <link>https://dev.to/rahulyadav139/beginners-guide-to-oop-in-javascript-4f8h</link>
      <guid>https://dev.to/rahulyadav139/beginners-guide-to-oop-in-javascript-4f8h</guid>
      <description>&lt;h2&gt;
  
  
  Object-Oriented Programming (OOP)?
&lt;/h2&gt;

&lt;p&gt;Object-oriented programming is a type of paradigm based on an "object" in a  programming language that contains data known as attributes and code known as methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Philosophy
&lt;/h2&gt;

&lt;p&gt;Object-oriented programming is based on the 4 principles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To prevent some of the properties or methods of an object to access outside of its scope. It resists mutating these encapsulated properties or methods outside its scope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inheritance&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To inherit methods from a blueprint object. It features the reusability of a method from a blueprint object where it is defined originally.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Polymorphism is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. The word “poly” means many and “morphs” means forms, So it means many forms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation of OOP in JavaScript
&lt;/h2&gt;

&lt;p&gt;Javascript is an OOP-based programming language so it follows the same philosophy as a typical OOP language, but the implementation is slightly different.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inheritance and the Prototype Chain
&lt;/h3&gt;

&lt;p&gt;Prototypes are the mechanism by which JavaScript objects inherit features from one another. When it comes to inheritance, JavaScript only has one construct: &lt;em&gt;objects&lt;/em&gt;. Each object has a private property that holds a link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. By definition, null has no prototype and acts as the final link in this prototype chain.&lt;/p&gt;

&lt;p&gt;Nearly all objects in JavaScript are instances of Object, which has null as its prototype.&lt;/p&gt;

&lt;p&gt;The heart of an OOP programming language is the object. So let's discuss it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object
&lt;/h3&gt;

&lt;p&gt;An Object is a unique entity that contains property and methods. For example “car” is a real-life Object, which has some characteristics like color, type, model, and horsepower and performs certain actions like driving. &lt;/p&gt;

&lt;p&gt;In JavaScript, we can implement OOP in JavaScript in following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Construction Function Method&lt;/li&gt;
&lt;li&gt;Object.create Method&lt;/li&gt;
&lt;li&gt;ES6 Class Method&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;let's discuss them one by one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Construnction Function Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In JavaScript, you can create multiple objects from a constructor function. To create an object from a constructor function, we use the &lt;code&gt;new&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//here person is a construction function&lt;/span&gt;
&lt;span class="c1"&gt;//for creating construction function, function declaration or function expression is used. Arrow can not be used because it doesn't have "this" keyword&lt;/span&gt;

&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//using the prototype object, a new method is created to person function, which can be used for all the instances&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Student extends to Person&lt;/span&gt;

&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi, I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I study &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;computer science&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//new instance 'ram' is created&lt;/span&gt;

&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//Hi, I am Ram and I study computer science.&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here is a prototype chain created.&lt;/p&gt;

&lt;p&gt;ram -&amp;gt; Student -&amp;gt; Person -&amp;gt; Object&lt;/p&gt;

&lt;p&gt;we can check it using &lt;code&gt;__proto__&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;__proto__&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Object.create Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;Object.create()&lt;/code&gt; method creates a new object, using an existing object as the prototype of the newly created object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi, I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I study &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Computer Science&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//Age: 20&lt;/span&gt;
&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//Hi, I am Ram and I study computer science.&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ES6 Class Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi there, I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and I study &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;course&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Computer Science&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//Hi there, I am Ram and I study Computer Science.&lt;/span&gt;
&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//Age: 20&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Static Method and Property
&lt;/h2&gt;

&lt;p&gt;The static keyword defines a static method or property for a class. Neither static methods nor static properties can be called on instances of the class. Instead, they're called on the class itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 

  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this is a static method&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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//throws an error&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;//Age: 20&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;//throws an error&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Private Class Feature
&lt;/h2&gt;

&lt;p&gt;Class fields are public by default, but private class members can be created by using a hash &lt;code&gt;#&lt;/code&gt; prefix. The privacy encapsulation of these class features is enforced by JavaScript itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;birthYear&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ram&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ram&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;property&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//throws an error&lt;/span&gt;
&lt;span class="c1"&gt;//Error: Private field '#property' must be declared in an enclosing class&lt;/span&gt;

&lt;span class="nx"&gt;ram&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//Age: 20&lt;/span&gt;
&lt;span class="c1"&gt;//some value&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This blog is all about a brief introduction to OOP in JavaScript. For more details about this topic, read on &lt;a href="https://developer.mozilla.org/en-US/"&gt;MDN Web Docs&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>oop</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Beginner's Guide to NextJS</title>
      <dc:creator>Rahul Yadav</dc:creator>
      <pubDate>Thu, 19 May 2022 15:43:27 +0000</pubDate>
      <link>https://dev.to/rahulyadav139/beginners-guide-to-nextjs-2pcp</link>
      <guid>https://dev.to/rahulyadav139/beginners-guide-to-nextjs-2pcp</guid>
      <description>&lt;h2&gt;
  
  
  What is NextJS ?
&lt;/h2&gt;

&lt;p&gt;NextJS is an open-source web development framework built on top of Node.js enabling React-based web application functionalities.&lt;br&gt;
NextJS was first released as an open-source project on GitHub on October 25, 2016. Currently, NextJS is owned by Vercel, formerly ZEIT.&lt;/p&gt;

&lt;p&gt;NextJS is Full-stack because it facilitates writing client-side code and server-side code, and Production-ready because it provides features that are missing in react library like routing, etc. NextJS offers a ton of features for ease of a developer which we will discuss later in this blog.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to start a NextJs project?
&lt;/h2&gt;

&lt;p&gt;You can start a NextJs project with run following CLI commands which sets up everything automatically for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app my-app
&lt;span class="c"&gt;# or&lt;/span&gt;
yarn create next-app
&lt;span class="c"&gt;# or&lt;/span&gt;
pnpm create next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating a nextJs project you will get folders public, pages, and styles along with next.config.js file. let's explore them one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Config File
&lt;/h2&gt;

&lt;p&gt;next.config.js is a regular Node.js module, not a JSON file. It gets used by the NextJS server and build phases, and it's not included in the browser build.&lt;/p&gt;

&lt;p&gt;Take a look at the following next.config.js example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nextConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/* config options here */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nextConfig&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commented lines are the place where you can put the configs allowed by next.config.js, which are defined in this file.&lt;br&gt;
However, none of the configs are required, and it's not necessary to understand what each config does.&lt;/p&gt;

&lt;p&gt;Read more about next config at official documents &lt;a href="https://nextjs.org/docs/api-reference/next.config.js/introduction"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Static File Serving
&lt;/h2&gt;

&lt;p&gt;NextJS can serve static files, like images, under a folder called public in the root directory. Files inside the public can then be referenced by your code starting from the base URL (&lt;code&gt;/&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For example, if you add an image to &lt;code&gt;public/me.png&lt;/code&gt;, the following code will access the image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/me.png"&lt;/span&gt; &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"me"&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"64"&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"64"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Avatar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Routing
&lt;/h2&gt;

&lt;p&gt;In NextJS, a page is a React Component exported from a .js, .jsx, .ts, or .tsx file in the pages directory. Each page is associated with a route based on its file name.&lt;/p&gt;

&lt;p&gt;Example: If you create &lt;code&gt;pages/about.js&lt;/code&gt; that exports a React component like below, it will be accessible at &lt;code&gt;/about&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;About&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is another way to use routing in NextJS. You can create a folder with the name &lt;code&gt;about&lt;/code&gt; and create a file name &lt;code&gt;index&lt;/code&gt;. Then also you can access path &lt;code&gt;/about&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dynamic Routes
&lt;/h3&gt;

&lt;p&gt;NextJS supports pages with dynamic routes. For example, if you create a file called &lt;code&gt;pages/posts/[id].js&lt;/code&gt;, then it will be accessible at &lt;code&gt;posts/1&lt;/code&gt;, &lt;code&gt;posts/2&lt;/code&gt;, etc. square bracket provides a dynamic name.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nested Routes
&lt;/h3&gt;

&lt;p&gt;let's say there are 3 routes you want to access &lt;code&gt;/account&lt;/code&gt;, &lt;code&gt;/account/profile&lt;/code&gt;, and &lt;code&gt;/account/setting&lt;/code&gt; you can also achieve this in NextJS very easily.&lt;/p&gt;

&lt;p&gt;In the pages directory creates a folder name &lt;code&gt;account&lt;/code&gt; and then creates 3 files inside it with named viz. &lt;code&gt;index&lt;/code&gt;, &lt;code&gt;profile&lt;/code&gt;, and &lt;code&gt;setting&lt;/code&gt;. The index file will be accessible at &lt;code&gt;/account&lt;/code&gt; path, profile file will be accessible at &lt;code&gt;/account/profile&lt;/code&gt;, and the setting file will be accessible at &lt;code&gt;/account/setting&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can achieve this for deeply nested routes too. Isn't it amazing? This routing feature is my favorite in Next Js. &lt;/p&gt;

&lt;h3&gt;
  
  
  next/router
&lt;/h3&gt;

&lt;p&gt;This is the extension of nextJS routing features. NextJs provides a &lt;code&gt;useRouter&lt;/code&gt; hook to navigate conditionally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;useRouter&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;next/router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;ActiveLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRouter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;marginRight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;asPath&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&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="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ActiveLink&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Router Object
&lt;/h3&gt;

&lt;p&gt;The router object returned by both useRouter and withRouter. You can read more in-depth about this router object in NextJS official documentation. &lt;a href="https://nextjs.org/docs/api-reference/next/router#router-object"&gt;Read here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  next/link
&lt;/h3&gt;

&lt;p&gt;Client-side transitions between routes can be enabled via the Link component exported by next/link.&lt;/p&gt;

&lt;p&gt;For an example, consider a pages directory with the following files:&lt;br&gt;
&lt;code&gt;pages/index.js&lt;/code&gt;&lt;br&gt;
&lt;code&gt;pages/about.js&lt;/code&gt;&lt;br&gt;
&lt;code&gt;pages/blog/[slug].js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can have a link to each of these pages like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Link&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;next/link&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/about&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt; &lt;span class="nx"&gt;Us&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/blog/hello-world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Blog&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&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="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Styling
&lt;/h2&gt;

&lt;p&gt;To add a global stylesheet to your application, import the CSS file within &lt;code&gt;pages/_app.js&lt;/code&gt;.&lt;br&gt;
For example, consider the following stylesheet named &lt;code&gt;styles.css&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt; &lt;span class="m"&gt;60px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;680px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&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;Create a &lt;code&gt;pages/_app.js&lt;/code&gt; file if not already present. Then, import the &lt;code&gt;styles.css&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../styles.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// This default export is required in a new `pages/_app.js` file.&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't want to use CSS styling globally. You can use CSS Modules which is in-built in nextJS and helps you to keep CSS styling locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Client-side and Server-side Rendering
&lt;/h2&gt;

&lt;p&gt;Client-side rendering allows developers to make their websites entirely rendered in the browser with JavaScript. Instead of having a different HTML page per route, a client-side rendered website creates each route dynamically directly in the browser. This approach spread once JS frameworks made it easy to take.&lt;/p&gt;

&lt;p&gt;Client-side rendering manages the routing dynamically without refreshing the page every time a user requests a different route. But server-side rendering can display a fully populated page on the first load for any route of the website, whereas client-side rendering displays a blank page first.&lt;/p&gt;

&lt;p&gt;Though NextJS is based on react library it facilitates client-side rendering but it offers server-side rendering too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Server Side Rendering:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A server-side rendered application enables pages to load faster, improving the user experience.&lt;/li&gt;
&lt;li&gt;When rendering server-side, search engines can easily index and crawl content because the content can be rendered before the page is loaded, which is ideal for SEO. &lt;/li&gt;
&lt;li&gt;Webpages are correctly indexed because web browsers prioritize web pages with faster load times.&lt;/li&gt;
&lt;li&gt;Rendering server-side helps efficiently load webpages for users with a slow internet connection or outdated devices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Server-Side Rendering in NextJS
&lt;/h2&gt;

&lt;p&gt;There are two ways to use server-side rendering in nextJS. Either page can be served static generated way or generated on the fly. For these features it offers two functions: &lt;em&gt;getServerSideProps&lt;/em&gt; and &lt;em&gt;getStaticProps&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  getServerSideProps Function
&lt;/h3&gt;

&lt;p&gt;If you export a function called getServerSideProps (Server-Side Rendering) from a page, Next.js will pre-render this page on each request using the data returned by getServerSideProps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getServerSideProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="c1"&gt;// will be passed to the page component as props&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 returns props which you can in react component.&lt;br&gt;
You should use getServerSideProps only if you need to render a page whose data must be fetched at the requested time. &lt;/p&gt;
&lt;h3&gt;
  
  
  getStaticProps Function
&lt;/h3&gt;

&lt;p&gt;If you export a function called getStaticProps (Static Site Generation) from a page, NextJS will pre-render this page at build time using the props returned by getStaticProps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="c1"&gt;// will be passed to the page component as props&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;You should use getStaticProps if The data required to render the page is available at build time ahead of a user’s request.&lt;/p&gt;

&lt;h3&gt;
  
  
  getStaticPaths Function
&lt;/h3&gt;

&lt;p&gt;If a page has Dynamic Routes and uses &lt;em&gt;getStaticProps&lt;/em&gt;, it needs to define a list of paths to be statically generated during build time.&lt;/p&gt;

&lt;p&gt;When you export a function called getStaticPaths (Static Site Generation) from a page that uses dynamic routes, NextJS will statically pre-render all the paths specified by &lt;em&gt;getStaticPaths&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getStaticPaths&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;fallback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// false or 'blocking'&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;This is the overview of these special functions which nextJS provides. For in-depth information read at NextJS official documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next API
&lt;/h2&gt;

&lt;p&gt;We have seen client-side routing and server-side rendering functionality with NextJS. If you want to create RestFul API then you don't need to create it separately. NextJs provides this functionality as an in-built feature. There is an API folder available inside the pages folder where you can create RESTFul API. Every file you create with &lt;code&gt;.js/.jsx/.ts/.tsx&lt;/code&gt; extension works as an endpoint to which you can send API calls and connect to the backend. Node environment is available in the API folder so you use the environmental variable with using the process object.&lt;/p&gt;

&lt;p&gt;For example, the following API route &lt;code&gt;pages/api/user.js&lt;/code&gt; returns a json response with a status code of 200:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though so many features left like next/Image, next/head, eslint and typescript support, optimization etc. which NextJS offers for website development but this blog is about NextJS basics. You can explore more about NextJS in their official document.&lt;/p&gt;




</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>nextjs</category>
      <category>react</category>
    </item>
    <item>
      <title>Beginner's Guide to Regex</title>
      <dc:creator>Rahul Yadav</dc:creator>
      <pubDate>Wed, 18 May 2022 19:11:14 +0000</pubDate>
      <link>https://dev.to/rahulyadav139/beginners-guide-to-regex-37ho</link>
      <guid>https://dev.to/rahulyadav139/beginners-guide-to-regex-37ho</guid>
      <description>&lt;h2&gt;
  
  
  Regex or Regexp ?
&lt;/h2&gt;

&lt;p&gt;It stands for &lt;em&gt;Regular Expression&lt;/em&gt;. It is a character matching mechanism. In other words, regular expressions are the pattern to match standalone character or a combination of characters in a string. It was coined in the beginning of 1950s, when the American mathematician Stephen Cole Kleene formalized the concept of a regular language. Most general-purpose programming languages support regex capabilities either natively or via libraries, including example Python, C, C++, Java, and JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does it work ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are the following rules a regex engine follows to find the match:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It reads the whole input string and attempts to match the characters against the instructions one at a time.&lt;/li&gt;
&lt;li&gt;It reads the string from left to right&lt;/li&gt;
&lt;li&gt;If a character matches according to the instruction that we have imposed, it returns true and goes for the next character to match. if a character doesn't match it returns false and goes for matching the next character from start. 
4.If all the instructions matched it returns success indicating regex matched successfully.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Basic matching
&lt;/h2&gt;

&lt;p&gt;A regular expression is just a pattern of characters that we use to perform a search in a text.&lt;br&gt;
For example, the regular expression &lt;code&gt;the&lt;/code&gt; means letter &lt;code&gt;t&lt;/code&gt;, followed by the letter &lt;code&gt;h&lt;/code&gt;, followed by the letter &lt;code&gt;e&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;"the" =&amp;gt; The fat cat sat on &lt;span&gt;the&lt;/span&gt; mat.
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;
  
  
  Meta-characters ?
&lt;/h2&gt;

&lt;p&gt;Meta-characters are reserved characters to set a specific rule for matching.&lt;br&gt;
The meta characters are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;^&lt;/code&gt; : It specifies the starting of the string. This metacharacter helps us to match a string starting with a specific substring.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;^The =&amp;gt; &lt;span&gt;The&lt;/span&gt; car is parked in the garage.
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$&lt;/code&gt; : Matches the end of the string. If a string ends with a specific character then we can use the &lt;code&gt;$&lt;/code&gt; to find the match.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wihtout &lt;code&gt;$&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;at\. =&amp;gt; The fat c&lt;span&gt;at.&lt;/span&gt; s&lt;span&gt;at.&lt;/span&gt; on the m&lt;span&gt;at.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With &lt;code&gt;$&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;at\.$ =&amp;gt; The fat cat. sat. on the m&lt;span&gt;at.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; : It matches a single character without a line break. This is the simplest meta character. It helps us to match the next single character, if we put &lt;code&gt;.&lt;/code&gt; after the matching pattern or the previous single character, if we put before the matching pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;.at =&amp;gt; The &lt;span&gt;fat&lt;/span&gt; &lt;span&gt;cat&lt;/span&gt; &lt;span&gt;sat&lt;/span&gt; on the &lt;span&gt;mat&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;ca. =&amp;gt; The fat &lt;span&gt;cat&lt;/span&gt; sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[]&lt;/code&gt; : Character Class. It matches any character written inside a square bracket. If we want to match a specific character then we can use character class and write a matching pattern between the square bracket.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[0-9] =&amp;gt; &lt;span&gt;3&lt;/span&gt; fat cats sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[^]&lt;/code&gt; : Neglected Character Class. It does not match any character written inside in a square bracket. it is similar to character class but in this case, we don't want to match specific characters we can use neglected character class. If caret (&lt;code&gt;^&lt;/code&gt;) is available before a matching pattern wrapped inside the square bracket then expect the matching pattern it matches all other characters available in the string.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[^a-b] =&amp;gt; &lt;span&gt;3&lt;/span&gt; fat cats sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;*&lt;/code&gt; : It is used with another rule like &lt;code&gt;[a-z]*&lt;/code&gt;. It matches &lt;u&gt;zero or more than zero the occurrence&lt;/u&gt; of preceding characters. If &lt;code&gt;*&lt;/code&gt; is written after the matching pattern then it matches zero or more than zero repetition of the matching pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[0-9] =&amp;gt; &lt;span&gt;5&lt;/span&gt;25 fat cats sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;[0-9]* =&amp;gt; &lt;span&gt;525&lt;/span&gt; fat cats sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is generally used with whitespace character (&lt;code&gt;\s&lt;/code&gt;) when we want to match a substring followed by zero or more than zero whitespaces available.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;The\s*fat =&amp;gt; &lt;span&gt;The fat&lt;/span&gt; cat sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; : This works the same as &lt;code&gt;*&lt;/code&gt; works but instead of matching zero or more than zero occurrences, it matches &lt;u&gt;one or more than one occurrence&lt;/u&gt; of preceding characters. If plus is written after the matching pattern then it matches one or more than one repetition of the matching pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[0-9]+ =&amp;gt; &lt;span&gt;525&lt;/span&gt; fat cats sat on the mat.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The difference ?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;hel* =&amp;gt; &lt;span&gt;he&lt;/span&gt;o.&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;hel+ =&amp;gt; heo. //no match&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;?&lt;/code&gt; : Makes the preceding symbol optional. This symbol matches zero or one instance of the preceding character.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[t]?he=&amp;gt; &lt;span&gt;the&lt;/span&gt; fat cat sat on &lt;span&gt;the&lt;/span&gt; mat &lt;span&gt;he&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{n, m}&lt;/code&gt; : It specifies the range of the preceding string. In this case, the string should not be less than n characters and more than m characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;[0-9]{2, 3}=&amp;gt; the value of pi is 3.&lt;span&gt;141&lt;/span&gt;5.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, if we omit the second parameter (3) then it finds a match with 2 or more digits.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[0-9]{2,}=&amp;gt; the value of pi is 3.&lt;span&gt;14159&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we omit the comma too then it finds a match with exactly 2 digits.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[0-9]{2}=&amp;gt; the value of pi is 3.&lt;span&gt;14&lt;/span&gt;1.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;(xyz)&lt;/code&gt; : Character Group. Matches substring written inside parentheses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;|&lt;/code&gt; : Alternation. It is similar to the OR operator. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code&gt;(T|t)he|car =&amp;gt; &lt;span&gt;The car&lt;/span&gt; is parked in &lt;span&gt;the&lt;/span&gt; garage.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\&lt;/code&gt; : Escape. This allows you to match reserved characters &lt;a href=""&gt; &lt;/a&gt; { } . * + ? ^ $ \ |. For example, if we want to find &lt;code&gt;.&lt;/code&gt; character then we need to write &lt;code&gt;\.&lt;/code&gt; as for the rule.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Assertions
&lt;/h2&gt;

&lt;p&gt;Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lookahead Assertion:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;x(?=y)&lt;/code&gt; matches &lt;code&gt;x&lt;/code&gt; if it is followed by &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;monica(?=\sgeller) =&amp;gt; my name is &lt;span&gt;monica&lt;/span&gt; geller.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Negative Lookahead Assertion&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;x(?!y)&lt;/code&gt; matches &lt;code&gt;x&lt;/code&gt; if it is not followed by &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;geller(?!\sfamily) =&amp;gt; monica geller belongs to the &lt;span&gt;geller&lt;/span&gt; family.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Look Behind Assertion&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;(?&amp;lt;=x)y&lt;/code&gt; matches &lt;code&gt;y&lt;/code&gt; if it is preceded by &lt;code&gt;x&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(?&amp;lt;=monica\s)geller=&amp;gt; monica &lt;span&gt;geller&lt;/span&gt; belongs to the geller family.&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Negative Look Behind Assertion&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;(?&amp;lt;!x)y&lt;/code&gt; matches &lt;code&gt;y&lt;/code&gt; if it is not preceded by &lt;code&gt;x&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(? monica geller belongs to the &lt;span&gt;geller&lt;/span&gt; family.&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;
  
  
  Lazy vs Greedy matching
&lt;/h2&gt;

&lt;p&gt;By default, a regex will perform a greedy match, which means the match will be as long as possible. We can use ? to match in a lazy way, which means the match should be as short as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Matching&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;he.*l=&amp;gt; say &lt;span&gt;hello to hell&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Greedy matching&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;he.*?l=&amp;gt; say &lt;span&gt;hell&lt;/span&gt;o to &lt;span&gt;hell&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;
  
  
  Flags
&lt;/h2&gt;

&lt;p&gt;Flags are also called modifiers because they modify the output of a regular expression. These flags can be used in any order or combination, and are an integral part of the RegExp.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;i&lt;/code&gt; : Case insensitive: Match will be case-insensitive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;g&lt;/code&gt; : Global Search: Match all instances, not just the first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;m&lt;/code&gt; : Multiline: Anchor meta characters work on each line.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Regex in JavaScript
&lt;/h2&gt;

&lt;p&gt;There are two ways to create a RegExp object: a literal notation and a constructor.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The literal notation's parameters are enclosed between slashes and do not use quotation marks.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The constructor function's parameters are not enclosed between slashes but do use quotation marks.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[0-9]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These patterns are used with the &lt;code&gt;exec()&lt;/code&gt; and &lt;code&gt;test()&lt;/code&gt; methods of RegExp, and with the &lt;code&gt;match()&lt;/code&gt;, &lt;code&gt;matchAll()&lt;/code&gt;, &lt;code&gt;replace()&lt;/code&gt;, &lt;code&gt;replaceAll()&lt;/code&gt;, &lt;code&gt;search()&lt;/code&gt;, and &lt;code&gt;split()&lt;/code&gt; methods of String.&lt;/p&gt;




&lt;p&gt;I hope this beginner's guide helps you to understand the basics of regex.&lt;/p&gt;

&lt;p&gt;Practice regex with &lt;a href="https://regex101.com/"&gt;Regex 101&lt;/a&gt;&lt;/p&gt;







</description>
      <category>javascript</category>
      <category>regex</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
