<?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>Forem: Sapinder Singh</title>
    <description>The latest articles on Forem by Sapinder Singh (@sapinder-singh).</description>
    <link>https://forem.com/sapinder-singh</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%2F664691%2F2ceb6291-02db-47b3-bbbc-d3b9d2cc1193.png</url>
      <title>Forem: Sapinder Singh</title>
      <link>https://forem.com/sapinder-singh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sapinder-singh"/>
    <language>en</language>
    <item>
      <title>The Easiest Introduction To CSS</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Wed, 17 Aug 2022 10:07:00 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/cascading-style-sheets-1od1</link>
      <guid>https://forem.com/sapinder-singh/cascading-style-sheets-1od1</guid>
      <description>&lt;p&gt;Here I'm back with the next topic in my &lt;a href="https://dev.to/sapinder_dev/web-development-the-static-fundamentals-6do"&gt;Web Development Intro&lt;/a&gt; series, where I introduce to you the fundamentals of web development; and clarify some of the core concepts that ain't easy enough for beginners to grasp.&lt;/p&gt;

&lt;p&gt;So in this post, we're going to learn about CSS, which stands for &lt;b&gt;&lt;em&gt;Cascading Style Sheets&lt;/em&gt;&lt;/b&gt;. Cascading Style Sheets (CSS) is a &lt;a href="https://www.w3.org/TR/html401/present/styles.html" rel="noopener noreferrer"&gt;stylesheet&lt;/a&gt; language used to describe the presentation of a document &lt;br&gt;
written in HTML or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction" rel="noopener noreferrer"&gt;XML&lt;/a&gt;. Basically, it describes the styling properties of elements inside a document.&lt;/p&gt;

&lt;p&gt;Think of a web page like a room in your house. If you never painted the walls, windows and doors of that room, you would find it to be too boring to sit in. However, if you paint and decorate the room, the same room will attract you much more than before. This is true for web pages too. A web page without CSS is too boring (or even hard) to be able to convey information to the reader. &lt;strong&gt;And it's &lt;em&gt;not&lt;/em&gt; just about colors;&lt;/strong&gt; it also defines the &lt;em&gt;layouts&lt;/em&gt;, &lt;em&gt;positions&lt;/em&gt;, &lt;em&gt;transitions&lt;/em&gt;, &lt;em&gt;animations&lt;/em&gt;, and &lt;em&gt;much more&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Way CSS Works
&lt;/h2&gt;

&lt;p&gt;The name &lt;em&gt;Cascading Style Sheets&lt;/em&gt; alone describes itself really well. The styles here are applied from top to bottom &lt;b&gt;&lt;em&gt;in the order they are defined&lt;/em&gt;&lt;/b&gt;, just like a cascading waterfall. &lt;strong&gt;Any repeated style would override its previous corresponding values&lt;/strong&gt;, as in the following example.&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;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* The the style below will override the value 'white' for property 'color' */&lt;/span&gt;
&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&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;These styles come from different origins, also known as &lt;em&gt;stylesheets&lt;/em&gt;. There're mainly two types of stylesheets that are applied to a web page- &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade#user-agent_stylesheets" rel="noopener noreferrer"&gt;User Agent Stylesheets&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade#author_stylesheets" rel="noopener noreferrer"&gt;Author Stylesheets&lt;/a&gt;. Let's discuss them individually:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Agent Stylesheets&lt;/strong&gt; - These stylesheets are applied by the browsers to give default styles to a document. The styles often differ slightly across different browsers. For example, the button below has no custom styles, and uses the default styles from user agent stylesheets used by your current browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/sapinder_dev/embed/RwMqzJZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Try opening this page in a different browser, and you would see this button with slightly different styles.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Author Stylesheets&lt;/strong&gt; - These are the stylesheets that are used by web developers to apply custom styles to a document. The author stylesheets have higher preference over user agent stylesheets. For example, the following button uses the custom styles that I provided, which overrode the styles from user agent stylesheet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/sapinder_dev/embed/dyWXLoL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How Do We Actually Use CSS In A Web Page?
&lt;/h2&gt;

&lt;p&gt;We have 3 ways to use CSS in a web page. Let's take a look at each of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Internal CSS&lt;/strong&gt; - We can declare the styles using the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag anywhere inside the HTML document but the thing to note is that these styles are not applied to elements that come  before the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag because those elements will get parsed before this tag while rendering the web page. For this reason, this tag is often declared before any other element inside the body.
&lt;/li&gt;
&lt;/ul&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;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inline CSS&lt;/strong&gt; - We can also declare style for an element by providing the &lt;code&gt;style&lt;/code&gt; attribute to it. Inline styles have the highest preference over any other styles. We'll actually discuss about something known as &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity" rel="noopener noreferrer"&gt;specificity&lt;/a&gt; in the next article. Here's an example of inline style:
&lt;/li&gt;
&lt;/ul&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;body&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"background-color: aliceblue;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Hi! I'm a button
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;External CSS&lt;/strong&gt; - The last and most efficient way to declare CSS in large projects is using external &lt;em&gt;.css&lt;/em&gt; files. We declare the styles in different &lt;em&gt;.css&lt;/em&gt; files, and link them in the HTML document using &lt;code&gt;link&lt;/code&gt; tag. Below is an example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* index.css */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;aliceblue&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- index.html --&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"./css/index.css"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The text between &lt;code&gt;/&lt;em&gt;&lt;/em&gt;&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt; is called a &lt;b&gt;&lt;em&gt;comment&lt;/em&gt;&lt;/b&gt; in css. The same goes for &lt;code&gt;&amp;lt;!--&lt;/code&gt; and &lt;code&gt;--&amp;gt;&lt;/code&gt; in html. A comment is made just for the reader to understand the code better, and it is ignored by the compiler. Here're some of the &lt;a href="https://stackoverflow.blog/2021/12/23/best-practices-for-writing-code-comments/" rel="noopener noreferrer"&gt;best practices&lt;/a&gt; that you should adopt while writing comments in any language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Elements of Style Declaration
&lt;/h2&gt;

&lt;p&gt;So, now that we can link our stylesheets to HTML document, it's time to know how to actually write these stylesheets. Any style declaration consists of 2 parts- selector(s) and property-value pairs. &lt;strong&gt;Each pair of property and value must be separated by a semicolon at the end of the line.&lt;/strong&gt; You've already seen property-value pairs; hence, I want you to focus on just the &lt;br&gt;
selectors for now.&lt;/p&gt;
&lt;h3&gt;
  
  
  Selectors
&lt;/h3&gt;

&lt;p&gt;In order to apply any styles to an HTML element, we need to use a &lt;b&gt;&lt;em&gt;selector&lt;/em&gt;&lt;/b&gt; that would select the target element. A &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors" rel="noopener noreferrer"&gt;selector&lt;/a&gt; is kind of an identifier that tells the browser what HTML element are the styles for. The simplest type of selector is the &lt;b&gt;&lt;em&gt;type selector&lt;/em&gt;&lt;/b&gt;, i.e., the name of the element itself. We can, in fact, use a list of selectors if we want to declare the same styles for multiple elements.&lt;br&gt;
An example could be-&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="c"&gt;/* The font-size will 16px for each of button, a, input and small elements  */&lt;/span&gt;
&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;small&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&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;h4&gt;
  
  
  Classes And IDs
&lt;/h4&gt;

&lt;p&gt;Then we have &lt;b&gt;&lt;em&gt;class&lt;/em&gt;&lt;/b&gt; and &lt;b&gt;&lt;em&gt;id&lt;/em&gt;&lt;/b&gt; selectors. If you're unfamiliar with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class" rel="noopener noreferrer"&gt;class&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id" rel="noopener noreferrer"&gt;id&lt;/a&gt; attributes in HTML- the values given to &lt;code&gt;class&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; attributes provide us a way to identify an HTML element when making a JavaScript query, or specifying CSS styles for that element.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The only major difference between &lt;code&gt;class&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; attributes is that an id is &lt;b&gt;&lt;em&gt;unique&lt;/em&gt;&lt;/b&gt; to an element, whereas multiple classes can be assigned to multiple elements; you can think of it as a many-to-many relationship. 😅 For more details, you can read this &lt;a href="https://css-tricks.com/the-difference-between-id-and-class/" rel="noopener noreferrer"&gt;article&lt;/a&gt; by &lt;a href="https://css-tricks.com" rel="noopener noreferrer"&gt;css-tricks&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;In most cases, using class selectors is preferred than using id selectors&lt;/strong&gt; for a reason that we would discuss in the next article. A class selector must begin with a &lt;code&gt;.&lt;/code&gt; character; for example-&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="c"&gt;/* This style would be applied to any elements that have the `txt` class assigned to them. */&lt;/span&gt;
&lt;span class="nc"&gt;.txt&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;An id selector must begin with a &lt;code&gt;#&lt;/code&gt; character; for example-&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="c"&gt;/* This style would be applied the element that has the `btn` id assigned to it. */&lt;/span&gt;
&lt;span class="nf"&gt;#btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;h4&gt;
  
  
  Attribute Selectors And Combinators
&lt;/h4&gt;

&lt;p&gt;Now come the attribute selectors, which basically select the elements that have the specified attributes in their HTML. HTML attributes can be in the form &lt;code&gt;key="value"&lt;/code&gt; or just &lt;code&gt;key&lt;/code&gt; depending on the type of attribute. For example:&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="c"&gt;/* this style will apply to anchors pointing to "https://developer.mozilla.org" */&lt;/span&gt;
&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"https://developer.mozilla.org"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;underline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* this style will apply to only those buttons that have the `btn` class and have the `disabled` attribute. */&lt;/span&gt;
&lt;span class="nc"&gt;.btn&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;disabled&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grey&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;Next, we have &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators" rel="noopener noreferrer"&gt;combinators&lt;/a&gt;, which are used to target specific elements based on their relationship to the surrounding elements. Take a look at the following snippet:&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="c"&gt;/* 1. Descendant Combinator */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="c"&gt;/* 2. Child Combinator */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="c"&gt;/* 3. Adjacent Sibling Combinator */&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="c"&gt;/* 4. General Sibling Combinator */&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the only four combinators available in CSS. Here's what each of the selectors are supposed to do in the snippet above:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Descendant Combinator&lt;/strong&gt; - selects the any &lt;code&gt;p&lt;/code&gt; element found inside the &lt;code&gt;body&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Child Combinator&lt;/strong&gt; - selects only those &lt;code&gt;p&lt;/code&gt; elements that are &lt;b&gt;&lt;em&gt;direct&lt;/em&gt;&lt;/b&gt; children of &lt;code&gt;body&lt;/code&gt;. It doesn't select any
other descendant &lt;code&gt;p&lt;/code&gt; elements in the heirarchy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adjacent Sibling Combinator&lt;/strong&gt; - selects a &lt;code&gt;p&lt;/code&gt; element that is a sibling of &lt;code&gt;h1&lt;/code&gt; element, and comes right next to it, i.e., is an adjacent sibling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;General Sibling Combinator&lt;/strong&gt; - selects any &lt;code&gt;p&lt;/code&gt; element that is a sibling of an &lt;code&gt;h1&lt;/code&gt;; it doesn't matter if it's adjacent to &lt;code&gt;h1&lt;/code&gt;, or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Alright, so we now know how CSS works, how we can use stylesheets in HTML, and the type of selectors that we have in CSS. But there's a lot more to CSS than what we have just learned. Stay tuned to learn more!&lt;/p&gt;

&lt;p&gt;If you enjoyed this post, feel free to &lt;strong&gt;&lt;em&gt;follow me&lt;/em&gt;&lt;/strong&gt; so you never miss any of my future posts!&lt;/p&gt;

&lt;p&gt;See you in the next one! 😉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The HTML And The Web Pages</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Fri, 05 Aug 2022 00:01:00 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/the-html-and-the-web-pages-395j</link>
      <guid>https://forem.com/sapinder-singh/the-html-and-the-web-pages-395j</guid>
      <description>&lt;p&gt;In my earlier posts, &lt;a href="https://dev.to/sapinder_dev/web-development-the-static-fundamentals-6do"&gt;The Static Fundamentals&lt;/a&gt; and &lt;a href="https://dev.to/sapinder_dev/the-dynamic-web-40kk"&gt;The Dynamic Web&lt;/a&gt;, I made a overall introduction to the field of web development but in this post, we'll take a foundational but deeper look at HTML and web pages. So are you ready for the ride? Here we go! 🚀&lt;/p&gt;

&lt;p&gt;To start off, let me say it straight- &lt;em&gt;HTML stands for &lt;strong&gt;HyperText Markup Langauge&lt;/strong&gt;, and it's &lt;b&gt;not&lt;/b&gt; a programming language. (Oops... debate triggered 🤦.)&lt;/em&gt; We should, first of all, understand what exactly a markup language is.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;a href="https://en.wikipedia.org/wiki/Markup_language" rel="noopener noreferrer"&gt;markup language&lt;/a&gt; is a way of encoding a document that, along with the text, incorporates labels or marks that contain &lt;b&gt;&lt;em&gt;additional information about the structure of the text or its presentation.&lt;/em&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Simply put, a markup language is used to present a certain piece of data in a specific structure; may it be text, images, tables, etc. It can't be used to &lt;em&gt;program&lt;/em&gt; any task, as opposed to what a programming language must be capable of. HTML, XML, SVG are all examples of a markup language.&lt;/p&gt;

&lt;p&gt;Now getting back to HTML, the text you read on webpages isn't just plain text but a whole lot of information about that text is contained within itself, which tells about the structure of the text, and how it shall be presented. Consider the following sentence as an example- &lt;br&gt;&lt;b&gt;My Name is &lt;em&gt;Sapinder Singh&lt;/em&gt;. I'm a &lt;em&gt;content creator&lt;/em&gt;.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The HTML code for the sentence above is-&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;b&amp;gt;&lt;/span&gt;My Name is &lt;span class="nt"&gt;&amp;lt;i&amp;gt;&lt;/span&gt;Sapinder Singh&lt;span class="nt"&gt;&amp;lt;/i&amp;gt;&lt;/span&gt;. I'm a &lt;span class="nt"&gt;&amp;lt;i&amp;gt;&lt;/span&gt;content creator&lt;span class="nt"&gt;&amp;lt;/i&amp;gt;&lt;/span&gt;.&lt;span class="nt"&gt;&amp;lt;/b&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the tags &lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt;(for Bold) and &lt;code&gt;&amp;lt;i&amp;gt;&lt;/code&gt;(for Italic) have their own way of presenting the data that they hold. Consider another example- &lt;br&gt;&lt;strong&gt;"I use &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; for coding."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This text contains a &lt;b&gt;&lt;em&gt;link&lt;/em&gt;&lt;/b&gt; to another web page that you can navigate to by clicking on the highlighted text. And, this is basically what the "Hypertext" in HTML means. 🫢 &lt;a href="https://en.wikipedia.org/wiki/Hypertext" rel="noopener noreferrer"&gt;Hypertext&lt;/a&gt; is any text that contains reference to some other text, which can be accessed by interacting with the &lt;a href="https://en.wikipedia.org/wiki/Hyperlink" rel="noopener noreferrer"&gt;Hyperlink&lt;/a&gt;&lt;br&gt;
(which in this case is "VS Code"). So essentially, that's how we jump from one webpage to another.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Syntactical Overview Of HTML
&lt;/h2&gt;

&lt;p&gt;HTML is the building block of a webpage. It identifies different types of text and media with different tags, where each tag is in a pair of &lt;b&gt;&lt;em&gt;opening&lt;/em&gt;&lt;/b&gt; and &lt;b&gt;&lt;em&gt;closing&lt;/em&gt;&lt;/b&gt; tag. For example, if we want to write a paragraph of text, we would open the &lt;code&gt;p&lt;/code&gt; tag as in &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;; insert the text; and then close the tag as in &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt;. Then we have the &lt;b&gt;&lt;em&gt;attributes&lt;/em&gt;&lt;/b&gt; for each tag.&lt;/p&gt;

&lt;p&gt;An &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Attribute" rel="noopener noreferrer"&gt;attribute&lt;/a&gt; is just a property of a tag that holds a certain type of value. We define an attribute in the form &lt;code&gt;name="value"&lt;/code&gt;; for example, look at the following snippet that defines a hyperlink named "VS Code". The &lt;code&gt;a&lt;/code&gt; (anchor) tag is used define a hyperlink, and it requires the attribute &lt;code&gt;href&lt;/code&gt; that&lt;br&gt;
should point to a URL.&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;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://code.visualstudio.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;VS Code&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, there are some tags that don't need to be closed, and these are called &lt;b&gt;&lt;em&gt;self-closing&lt;/em&gt;&lt;/b&gt; tags. We don't provide any value but just the &lt;b&gt;&lt;em&gt;attributes&lt;/em&gt;&lt;/b&gt; &lt;br&gt;
to these tags. The most basic example of a self-closing tag is &lt;code&gt;&amp;lt;!Doctype html&amp;gt;&lt;/code&gt; that all HTML5 documents must begin with. It tells browsers to follow the most relevant specifications for rendering the page. You can find a brief &amp;amp; really nice explanation of Doctype on &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Doctype" rel="noopener noreferrer"&gt;this&lt;/a&gt; page by MDN. Nonetheless, everything else in an HTML document goes inside the &lt;code&gt;html&lt;/code&gt; tag; which is why it is called &lt;strong&gt;the root element of a webpage&lt;/strong&gt;. This &lt;code&gt;html&lt;/code&gt; tag comprises of two parts- &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt;.&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;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;h3&gt;
  
  
  head
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;head&lt;/code&gt; of a webpage is not directly visible to the user because it contains information not to be read by the user but the browser instead. It contains information such as: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;title of the page that is used in browser's title bar and for search engine optimizations.&lt;/li&gt;
&lt;li&gt;styles for styling the web page. These styles are written in CSS.&lt;/li&gt;
&lt;li&gt;scripts for adding executable code to the web page. The sole purpose of scripts is to handle user interaction on web pages.&lt;/li&gt;
&lt;li&gt;other &lt;code&gt;meta&lt;/code&gt; tags for additional information such as &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/character_set" rel="noopener noreferrer"&gt;character set&lt;/a&gt;, 
&lt;a href="https://www.seoptimer.com/blog/what-is-a-favicon/" rel="noopener noreferrer"&gt;favicons&lt;/a&gt;, and other types of &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Metadata" rel="noopener noreferrer"&gt;metadata&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's an example of what we usually see inside the &lt;code&gt;head&lt;/code&gt; tag-&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="c"&gt;&amp;lt;!-- defines the character set of the web page --&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;"charset"&lt;/span&gt; &lt;span class="na"&gt;content=&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="c"&gt;&amp;lt;!-- defines the title of the web page --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;The Theory Of HTML&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- links the styles.css file to the web page --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"./styles.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- links the fonts from Google Fonts --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; 
        &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,600;0,700;0,800;1,600&amp;amp;display=swap"&lt;/span&gt; 
        &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet preload"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- links the script.js file to the web page --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  body
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;body&lt;/code&gt; tag represents the visible portion of a web page. Anything that you read, see or interact with on a web page is&lt;br&gt;
placed inside the body of that page. Each type of content is represented by a specific tag; some of the common tags are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;p&lt;/strong&gt; - represents a paragraph of text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;img&lt;/strong&gt; - represents an image. It requires the &lt;code&gt;src&lt;/code&gt; attribute that should contain the path to the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;section&lt;/strong&gt; - represents a section of a page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;h1 to h6&lt;/strong&gt; - represent the &lt;strong&gt;Heading-level&lt;/strong&gt; for a section. The smallest acceptable heading level is &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;button&lt;/strong&gt; - represents a button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;form&lt;/strong&gt; - represents a form for submitting some information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;input&lt;/strong&gt; - represents an input field. It can accept different types of input depending the value of the &lt;code&gt;type&lt;/code&gt; attribute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can read more about the different kinds of HTML elements on MDN's &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" rel="noopener noreferrer"&gt;HTML reference page&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;strong&gt;Fun Fact&lt;/strong&gt;
&lt;p&gt;If you omit, misspell, or misplace any of the tags in HTML, the browser would, silently, just render the page with incorrect or broken layout. Unlike a programming language, &lt;b&gt;&lt;em&gt;HTML won't throw any error&lt;/em&gt;&lt;/b&gt;; hence the proof of it being just a markup language. 😉&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How A Web Page Is Rendered
&lt;/h2&gt;

&lt;p&gt;Alright, now you know how we write HTML; but you must also know how a web page is actually rendered along with the sources that are linked to the HTML file. So, as soon as the HTML file is received by the client's browser, it starts creating what is called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model" rel="noopener noreferrer"&gt;Document Object Model&lt;/a&gt;. &lt;strong&gt;The DOM is an inverted-tree like object model, the sole purpose of which is to represent the HTML document in memory and make it understandable to the browser's JavaScript engine.&lt;/strong&gt; The root of this tree is the &lt;code&gt;html&lt;/code&gt; element, which branches out into &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt;, which further branch out into their children, and so on and so forth.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree. With them, you can change the document's structure, style, or content.&lt;br&gt;
&lt;cite&gt;&lt;b&gt;MDN&lt;/b&gt;&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While building the DOM tree, the browser encounters several linked resources that were defined in the &lt;code&gt;head&lt;/code&gt; of the document. Considering the snippet I provided in the head section, here's what happens next:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When it encounters the &lt;code&gt;link&lt;/code&gt; for &lt;b&gt;&lt;em&gt;./styles.css&lt;/em&gt;&lt;/b&gt; file, it pauses parsing the document; requests the the file from the server; parses the styles; and resumes the process.&lt;/li&gt;
&lt;li&gt;Then it encounters a &lt;code&gt;link&lt;/code&gt; for fonts; again, it requests the fonts first; parses them; and resumes the process.&lt;/li&gt;
&lt;li&gt;Finally, it encounters the &lt;code&gt;script&lt;/code&gt; tag that it downloads and executes depending on the attributes provided. (Read more 
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attributes" rel="noopener noreferrer"&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the browser finishes parsing the document and styles, it combines them into a &lt;b&gt;&lt;em&gt;Render Tree&lt;/em&gt;&lt;/b&gt;, and it figures out the layout of web page. Then it finally &lt;b&gt;&lt;em&gt;paints&lt;/em&gt;&lt;/b&gt; the document, and we're able to see the web page in the browser window. All of this process is known as the &lt;strong&gt;Critical Rendering Path&lt;/strong&gt;. If you want to learn more about it, you can read &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Critical_rendering_path" rel="noopener noreferrer"&gt;this guide&lt;/a&gt;&lt;br&gt;
by MDN.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Alright, I hope you found this guide helpful to deepen your knowledge about HTML and web pages! If you liked it, be sure to &lt;strong&gt;&lt;em&gt;follow me&lt;/em&gt;&lt;/strong&gt; so you never miss any of my future posts!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>html</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Common Loops In JavaScript</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Wed, 20 Oct 2021 13:57:10 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/the-common-loops-in-javascript-20mf</link>
      <guid>https://forem.com/sapinder-singh/the-common-loops-in-javascript-20mf</guid>
      <description>&lt;p&gt;Looping is one of my favourite programming concepts that I learned as a beginner. It's simple; yet an effective way to avoid code repetition. If you are struggling to grasp the various kinds of loops that we see in JavaScript, this article is made for you indeed. 😉 Also, I've tried to keep it as general as possible so that anyone could understand even if they don't know JavaScript. So, let's jump right into it!&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the need for loops?
&lt;/h2&gt;

&lt;p&gt;Loops help us avoid &lt;em&gt;code repetition&lt;/em&gt;. In other words, they allow us to execute the same set of instructions for a specified number of times. Usually, we have to deal with large sets of data for which, we have to perform same tasks over and over again. Loops are made for this job because we can just avoid typing the same statements again and again with our lazy hands 🥱. But there are many kinds of loops in JavaScript; how would you know which one to use in what case? &lt;strong&gt;I'm going to discuss the three common loops in this post- do...while, while and for.&lt;/strong&gt; So, let's see what these are, and when to use each of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Different Kinds of Loops
&lt;/h2&gt;

&lt;h3&gt;
  
  
  do...while
&lt;/h3&gt;

&lt;p&gt;I chose this loop to be discussed first because it seems closer to the way I want you to start thinking about loops. Its &lt;a href="https://en.wikipedia.org/wiki/Syntax_(programming_languages)" rel="noopener noreferrer"&gt;syntax&lt;/a&gt; is simple enough to comprehend-&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;do&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="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The instructions to be performed go inside curly braces &lt;code&gt;{}&lt;/code&gt; after the &lt;code&gt;do&lt;/code&gt; keyword, whereas, parentheses &lt;code&gt;()&lt;/code&gt; hold the condition that will be checked before repeating those instructions each time. Unless if we were talking to a human, we can't just say &lt;code&gt;"Print 'hello' 5 times"&lt;/code&gt;. The way loops work is that they check some condition before repeating the task each time. If the condition evaluates to &lt;code&gt;true&lt;/code&gt;, the &lt;br&gt;
task is performed again; otherwise it exits the loop. Consider this example that prints &lt;code&gt;Hello!&lt;/code&gt; 5 times to the console/terminal-&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; 
&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;4&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="nf"&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;Hello!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;   &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the use of &lt;code&gt;index&lt;/code&gt; variable in the snippet above. Firstly, we declare this variable and assign the integer value &lt;code&gt;1&lt;/code&gt; to it. Then we tell the computer to run the statements inside &lt;code&gt;do{}&lt;/code&gt; block; then evaluate the condition &lt;code&gt;index &amp;lt;= 5&lt;/code&gt;; and run those statements again if it's true; or exit the loop if not.&lt;/p&gt;

&lt;p&gt;If we forget to include the line number 5 in our code, the loop will become infinite because the value of &lt;code&gt;index&lt;/code&gt; will always be 1; hence the condition will be true forever. Therefore, it is necessary to increment the value each time the loop is run. When the value of &lt;code&gt;index&lt;/code&gt; equals 5, the condition will turn to false; hence, it will exit the loop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment" rel="noopener noreferrer"&gt;increment operator&lt;/a&gt;) (++) is a shorthand operator that allows us to write &lt;code&gt;index++&lt;/code&gt; instead of &lt;code&gt;index = index + 1&lt;/code&gt;. There's also a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Decrement" rel="noopener noreferrer"&gt;decrement operator&lt;/a&gt; (--) as its counterpart. Look them up! 👍&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  while
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;while&lt;/code&gt; loop is exactly the same as &lt;code&gt;do...while&lt;/code&gt;. Just have a look at the syntax of both loops-&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="c1"&gt;// do...while loop&lt;/span&gt;
&lt;span class="k"&gt;do&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="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;

&lt;span class="c1"&gt;// while loop&lt;/span&gt;
&lt;span class="k"&gt;while &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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you spot the difference? The &lt;code&gt;do...while&lt;/code&gt; loop runs the statement first, then checks for the condition; whereas &lt;code&gt;while&lt;/code&gt; loop checks the condition first, then runs the statement. In short, the former checks condition for the next iteration, while the latter checks condition for the current iteration.&lt;/p&gt;

&lt;p&gt;The answer to the question "Which of these loops should we use?" is quite opinionated. I personally don't remember the time that I used &lt;code&gt;do...while&lt;/code&gt; loop, except while I was learning it. &lt;code&gt;while&lt;/code&gt; loop is used much often in such cases. But there's another type of loop that is the most common among all others- the &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;Before introducing &lt;code&gt;for&lt;/code&gt; loop, I want you to understand the concept of &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Scope" rel="noopener noreferrer"&gt;scope&lt;/a&gt; in programming. &lt;strong&gt;The scope of a variable can be defined as the range of statements in which that variable can be accessed.&lt;/strong&gt; Consider the following snippet for 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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sapinder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; 
&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Singh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;5&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; 
&lt;span class="mi"&gt;8&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think line number 5 and 8 would print to the console? The first &lt;code&gt;console.log&lt;/code&gt; statement will print &lt;code&gt;Singh&lt;/code&gt; but the second one will print &lt;code&gt;Sapinder&lt;/code&gt; because the scope of variable holding the value &lt;code&gt;Singh&lt;/code&gt; is limited to the inner block. It can't be accessed out of the those curly braces. Hence, when the compiler reaches line number 8, it only knows of the variable &lt;code&gt;name&lt;/code&gt; that holds the value &lt;code&gt;Sapinder&lt;/code&gt;. Also, notice that I used &lt;code&gt;let&lt;/code&gt; keyword instead &lt;code&gt;var&lt;/code&gt; because a variable declared with &lt;code&gt;var&lt;/code&gt; is always &lt;em&gt;globally scoped&lt;/em&gt; regardless of where it is declared. Now that you know what scoping is, let's learn about the &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  for
&lt;/h2&gt;

&lt;p&gt;I like to think of the &lt;code&gt;for&lt;/code&gt; loop as a more concise version of &lt;code&gt;while&lt;/code&gt; loop. Both of these are almost the same except for a few things that we'll see later. First, take a look at an example of &lt;code&gt;for&lt;/code&gt; loop-&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&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="nf"&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;Hello!&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;Yes! It's just the same as the following &lt;code&gt;while&lt;/code&gt; loop-&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;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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="nf"&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;Hello!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&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;The &lt;strong&gt;initialization of variable&lt;/strong&gt;, &lt;strong&gt;the condition&lt;/strong&gt; and &lt;strong&gt;the upgrading of value&lt;/strong&gt;, all of these things can be achieved in single line of code in a &lt;code&gt;for&lt;/code&gt; loop. Moreover, the variable &lt;code&gt;index&lt;/code&gt; is initialized as &lt;em&gt;block-scoped&lt;/em&gt;, unlike as in the example of &lt;code&gt;while&lt;/code&gt; loop. This is major benefit of using a &lt;code&gt;for&lt;/code&gt; loop because it avoids any chance of conflicting names at the global level. To understand another difference between both the loops, I would like to introduce two keywords-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;break&lt;/strong&gt; - The keyword &lt;code&gt;break&lt;/code&gt; is used to terminate/exit a loop. The compiler will terminate the loop as soon as this keyword is encountered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;continue&lt;/strong&gt; - The keyword &lt;code&gt;continue&lt;/code&gt; is used to skip the rest of statements left in the current iteration, and start the next iteration
in the loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, consider the following example where I want to print the numbers from 1 to 5 excluding the number 3-&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;continue&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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;Here, I'm saying, "If index is equal to 3, don't run rest of the statements; and just skip to the next iteration." Hence, it will not print the number &lt;code&gt;3&lt;/code&gt; to the console. It will &lt;em&gt;continue&lt;/em&gt; the loop with upgraded value of &lt;code&gt;index&lt;/code&gt;, i.e. &lt;code&gt;4&lt;/code&gt;. Now, let's go for the same approach using &lt;code&gt;while&lt;/code&gt; loop-&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;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;continue&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// upgrading needs to be done here in the end, unlike in `for` loop&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you think this solution will work out? Can you spot the bug? Well, it is an &lt;em&gt;infinite loop&lt;/em&gt; because once the value of &lt;code&gt;index&lt;/code&gt; reaches &lt;code&gt;3&lt;/code&gt;, it skips the rest of the statements including &lt;code&gt;index++&lt;/code&gt;. Hence, its value is never upgraded beyond &lt;code&gt;3&lt;/code&gt;; and the loop keeps running infinitely. &lt;/p&gt;

&lt;p&gt;Such a case can easily be handled using a &lt;code&gt;for&lt;/code&gt; loop because the upgrading expression of the loop is specified at the very beginning; and it is always executed at the end of each iteration. But if we move this upgrading expression from the first line of loop to just before the end of loop, as in the following example, we will again get the infinite loop problem.&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;continue&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="cm"&gt;/* This will cause the same issue of infinite loop */&lt;/span&gt;
  &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&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;So, to conclude, I would say that both the &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loops can be used interchangeably except for some cases, where we're more likely to cause bugs using &lt;code&gt;while&lt;/code&gt; loop, as compared to the other one. There're other kinds of loops too in JavaScript, such as- &lt;code&gt;for in&lt;/code&gt;, &lt;code&gt;for of&lt;/code&gt;, etc., but they are literally dead simpler than the ones discussed above; and don't need to be included in this post. &lt;/p&gt;

&lt;p&gt;Ending it all, If you like my writing style, you can follow me to never miss any of my future posts. See you in the next post! 😉&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why do we have APIs in JavaScript?</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Fri, 01 Oct 2021 13:56:42 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/why-do-we-have-apis-in-javascript-5ee4</link>
      <guid>https://forem.com/sapinder-singh/why-do-we-have-apis-in-javascript-5ee4</guid>
      <description>&lt;p&gt;You've most likely heard of the term API if you have ever worked with JavaScript. There're a ton of them such as- DOM, Storage, Fetch, Canvas, History, and so forth. But have you ever wondered, &lt;em&gt;"Can't we have JavaScript without APIs? Why do we even need them?"&lt;/em&gt;. Well, I heard you!&lt;/p&gt;

&lt;p&gt;Let's first of all understand what an API is. The term &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/API" rel="noopener noreferrer"&gt;API&lt;/a&gt; stands for Application Programming Interface, which basically refers to an interface that different programs use in order to communicate with each other; in short, to send &amp;amp; receive data. APIs are like the fictional cars, which can carry the same passengers (data) by different means- land, air and water. They know exactly what medium to use when commuting to different places (programs).&lt;/p&gt;

&lt;p&gt;The use of the term API can &lt;em&gt;slightly&lt;/em&gt; vary across different programming areas. A server-side API is just another web server; but in place of a web page, it serves a certain piece of data when we make a request to its server. For example, if you visit &lt;a href="https://api.thecatapi.com/v1/images/search" rel="noopener noreferrer"&gt;this endpoint&lt;/a&gt; of &lt;a href="https://docs.thecatapi.com/" rel="noopener noreferrer"&gt;TheCatApi&lt;/a&gt;, you shall receive an object that consists of a URL for some random cat's image, along with other data. We can utilize this API in a project to get random cat images. Such APIs play a crucial role in apps like weather, music, shopping, news, etc., because they provide data that these apps can utilize.&lt;/p&gt;

&lt;p&gt;Client-side APIs (or APIs in JavaScript) are similar to server-side APIs. The difference is that these APIs are not publically available endpoints, but &lt;em&gt;internally available data&lt;/em&gt; to JavaScript. Let me ask you- &lt;em&gt;"What could you do with JavaScript if there was no DOM API, Fetch API, Storage API, Event API or any other kind of API? Can you think of any use-case of JavaScript in such scenerio?"&lt;/em&gt; Ya, you could just create your own variables and play with them until you realize that it won't help in interacting with the HTML page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript is just the language we speak when communicating to browsers, whereas the various APIs provided by browsers help us communicate with different things like HTML, CSS, Storage available on client's system, Events captured by client's system, etc.&lt;/strong&gt; For example, DOM API is a JavaScript Object that gives us information about what is there in the HTML document. CSSOM API is another JavaScript Object that gives us information about the styles that are present in CSS form. &lt;/p&gt;

&lt;p&gt;Each of these APIs present their data to us in the language we speak, JavaScript. Hence, as you see, APIs help different pieces of software to communicate with each other by providing data in their &lt;em&gt;native&lt;/em&gt; forms. All of these APIs are provided by JavaScript Runtime Environment to the JavaScript Engine present in browsers that interprets and executes our code. Without these APIs, we could just play around with our manually created data, but we won't be able to cause any effect outside of JavaScript's reach; i.e. &lt;em&gt;everything else&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Ending it all, If you like my writing style, you can follow me to never miss any of my future posts. See you in the next post! 😉&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Dynamic Web</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Fri, 30 Jul 2021 04:46:33 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/the-dynamic-web-40kk</link>
      <guid>https://forem.com/sapinder-singh/the-dynamic-web-40kk</guid>
      <description>&lt;p&gt;In my previous post, I introduced to you the &lt;a href="https://dev.to/sapinder_dev/web-development-the-static-fundamentals-6do"&gt;basics of how websites work&lt;/a&gt;. But that was just the &lt;em&gt;static&lt;/em&gt; form of websites. In this post, we'll learn what that "static" actually means as well as other important concepts that are used in modern web development. And you'll also get the answer to that question I left you with in the previous post. 😎&lt;/p&gt;

&lt;p&gt;We learned previously that a website is a collection of web pages, which are just plain HTML files. When we visit a website, we receive an HTML file that is rendered inside the browser. These are &lt;em&gt;static pages;&lt;/em&gt; meaning that the same pages are served to a client each time. Those pages are present on the server in their entire form. They never change no matter what request is received from a client. But this is not desirable at all times.&lt;/p&gt;

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

&lt;p&gt;Suppose that I have a page where I ask you to enter your name in a form. After you submit the form, I want to render your name on the page with a message, for example- "Hello &amp;lt;your-name&amp;gt;". If you remember from the previous post, we (mostly) make a &lt;code&gt;POST&lt;/code&gt; request to the server when any form is submitted. The server is supposed to do something with the submitted data (your name), and send a new page to you with updated information.&lt;/p&gt;

&lt;p&gt;We can't do that with static pages, because the new page is supposed to be different each time we submit a different name. We have no fully pre-coded page on the server, because the data to be rendered is not static. This is why we need to &lt;strong&gt;render/generate our page on the server each time a request is received along with necessary data&lt;/strong&gt;, and then send it to the client. This is called &lt;strong&gt;server-side rendering&lt;/strong&gt; where the pages are &lt;em&gt;dynamic&lt;/em&gt;. Here is a &lt;a href="https://apipaginator.herokuapp.com" rel="noopener noreferrer"&gt;live example of a dynamic page&lt;/a&gt; if you want to check out, where you have to submit an API endpoint to receive some response, (or just enter anything to receive an error response).&lt;/p&gt;

&lt;p&gt;The concept is pretty simple- wherever some data is not pre-defined, we use &lt;em&gt;template&lt;/em&gt; values as placeholders; wait until a request is received along with the data; and then inject it into the page before sending to the client. There are &lt;a href="https://www.pabbly.com/tutorials/template-engine-in-expressjs/" rel="noopener noreferrer"&gt;template engines&lt;/a&gt; like &lt;a href="https://ejs.co" rel="noopener noreferrer"&gt;EJS&lt;/a&gt; and &lt;a href="https://pugjs.org/" rel="noopener noreferrer"&gt;Pug&lt;/a&gt; that ease our job to generate HTML via template pages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drawbacks Of SSR
&lt;/h3&gt;

&lt;p&gt;There are two major limitations of SSR as listed below-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Slow Navigation&lt;/strong&gt; - You know that when we navigate through different routes (&lt;b&gt;/home&lt;/b&gt; to &lt;b&gt;/about-me&lt;/b&gt;), 
the browser makes a new &lt;code&gt;GET&lt;/code&gt; request to server asking for associated page. This makes navigation really slow because a whole 
new request is initiated for each page transition. This happens for both static and server-side rendered pages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Server-Load&lt;/strong&gt; - Because the required page is rendered on server for each request, the load on server increases with significant traffic; 
resulting in high &lt;a href="https://en.wikipedia.org/wiki/Latency_(engineering)" rel="noopener noreferrer"&gt;latency rate&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But wait a minute... if we can generate pages on server-side, why not try doing that on client-side instead? 🤔 Yes, meet CSR!&lt;/p&gt;

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

&lt;p&gt;If you notice, this site doesn't refresh when you navigate from one route to another, and the pages load instantly; meaning that it doesn't ask the server for any other page once the website loads &lt;em&gt;initially&lt;/em&gt;. This is called &lt;strong&gt;client-side rendering&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this technique, the client receives a single HTML file only, with a bunch of JavaScript code. Based on what page/route was requested, the content for that page is injected into HTML via JavaScript. Hence, if you navigate to a different route later, only the &lt;em&gt;necessary&lt;/em&gt; page content is re-rendered. No request is made to the server, and &lt;strong&gt;all of the routing stuff is handled on client-side&lt;/strong&gt; that makes navigation super fast! 🚀&lt;/p&gt;

&lt;p&gt;Websites using this approach are categorized as &lt;a href="https://en.wikipedia.org/wiki/Single-page_application" rel="noopener noreferrer"&gt;Single Page Applications&lt;/a&gt;. &lt;br&gt;
But we need not be too happy with this approach because it has its own downsides.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drawbacks Of CSR
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Poor Search Ranks&lt;/strong&gt; - Because the client receives just an empty page initially, there's nothing to read on the page.
And hence, search engines aren't aware of our content. Even though Google claims that they do crawl pages generated using JavaScript,
the search ranking can be really poor for these websites.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slow Initial Load&lt;/strong&gt; - Because there's a lot of JavaScript code coming along with HTML, the initial load time increases significantly. Furthermore, the time for the page to be interactive also increases as it is being generated by the browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript Mandatory&lt;/strong&gt; - Many of the users keep JavaScript disabled in browser settings for security reasons. But this also
blocks JavaScript from generating page content, and therefore, their browser renders nothing but blank page. 🥴&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, you guessed it; we have another approach to take over! 🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-Rendering
&lt;/h2&gt;

&lt;p&gt;This approach is simply a blend of both static and client-side rendered sites. Before we go further, let's first recall a few points-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the simplest approach, that is Static Sites, we have manually coded HTML pages on server. One of the page is served when a request is received for that page.&lt;/li&gt;
&lt;li&gt;In server-side rendering, we have template pages. When a client requests a certain page, we first render it on server by injecting 
the received data into page content; and then send it to the client.&lt;/li&gt;
&lt;li&gt;In client-side rendering though, we serve just a single template page. All of the routing &amp;amp; page rendering stuff is handled on client-side.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now coming to Pre-rendering or &lt;em&gt;Static Site Generation&lt;/em&gt;, the development process is similar to CSR. The only difference is that &lt;strong&gt;we pre-render/pre-generate all of the static pages on server&lt;/strong&gt;. This is done during &lt;a href="https://en.wikipedia.org/wiki/Compile_time" rel="noopener noreferrer"&gt;build/compile time&lt;/a&gt;. So we have the entire site pre-rendered on the server. &lt;/p&gt;

&lt;p&gt;Unless it reaches client-side, it behaves just like a static site where a certain page is served on request. Now in order to understand what happens on client-side, you should first know about the term &lt;strong&gt;hydration&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Hydration_(web_development)" rel="noopener noreferrer"&gt;Hydration&lt;/a&gt; or rehydration is a technique in which client-side JavaScript converts a static HTML web page into a dynamic web page by attaching event handlers to the HTML elements.&lt;br&gt;
&lt;cite&gt;Wikipedia&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once that static page is rendered inside browser, the only job left is to transform it again into a dynamic SPA page so that all further navigation events are handled on client-side. So we &lt;em&gt;hydrate&lt;/em&gt; the page by attaching event handlers. This is really powerful as it takes benefits from both Static Sites and CSR approaches in order to remove/minimize their drawbacks.&lt;/p&gt;

&lt;p&gt;But there are two huge limitations of Pre-rendering-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unsuitable For Highly Large Websites&lt;/strong&gt; - The reason for this limitation is that because all of the pages are pre-built on server-side, the build time goes on increasing with the number of pages added. A few hundred pages are fine for this approach based on server resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unefficient For Too Frequently Changing Content&lt;/strong&gt; - In addition to large build time, every change in these sites, even if it's a minor one, requires to re-build/re-compile the entire site! This consumes more time and resources. Thus this approach is not suitable for websites where the content changes too frequently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, this was all about the approaches adopted for dynamic websites. The use of each of these methods depends on the scale and requirement of a website, and therefore, a thorough comparison should be made before choosing any of these approaches. &lt;/p&gt;

&lt;p&gt;Now let me shed some light 🧙 on a few other important concepts used in modern websites. &lt;/p&gt;

&lt;h2&gt;
  
  
  Frameworks
&lt;/h2&gt;

&lt;p&gt;We all know that humans are compelled by their nature to combine simple things to make crazy stuff; then take that crazy stuff to make even crazier stuff, and so on. This is how we got things around us that we see today. The same is with &lt;em&gt;libraries&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;There's a large number of brains in every programming community that work together to create re-usable and life-saving libraries for the benefit of their community. In Node.js world, these are interchangably referred to as &lt;em&gt;packages&lt;/em&gt; because they are hosted by package managers like &lt;a href="https://npmjs.com/" rel="noopener noreferrer"&gt;NPM&lt;/a&gt; and &lt;a href="https://yarnpkg.com/" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Frameworks use multiple libraries to take the game to the next level. &lt;strong&gt;A framework is an extra layer of abstraction that makes building applications easier in a certain way&lt;/strong&gt;. For example, &lt;a href="https://blog.sapinder.dev" rel="noopener noreferrer"&gt;my blog&lt;/a&gt; is built with &lt;a href="https://gatsby.dev/" rel="noopener noreferrer"&gt;Gatsby.js&lt;/a&gt; framework instead of plain JavaScript, which follows SSG approach. Then there's Next.js, Angular, Vue, Svelte, and many other frameworks that follow one or another approach.&lt;/p&gt;

&lt;p&gt;You don't need to rush toward these frameworks unless you get comfortable at building websites with plain JavaScript, because foundational understanding does matter before stepping up a layer of abstraction. Frameworks have their own place in today's world, but they are &lt;em&gt;not mandatory&lt;/em&gt;. With this, let's head toward the last section of this post!&lt;/p&gt;

&lt;h2&gt;
  
  
  Progressive Web Apps
&lt;/h2&gt;

&lt;p&gt;I have nothing much to say on this topic except, "They are an attempt to make websites act like a native app on your phone". Try visiting &lt;a href="https://twitter.com" rel="noopener noreferrer"&gt;twitter.com&lt;/a&gt; in your browser; close the tab; disconnect from internet; visit the site again; and boom 💥, the &lt;em&gt;web app&lt;/em&gt; loads without an internet connection! Twitter.com is an example of a Progressive Web App.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/web/updates/2015/12/getting-started-pwa" rel="noopener noreferrer"&gt;Progressive Web Apps&lt;/a&gt; focus on things like- &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caching pages for offline availability.&lt;/li&gt;
&lt;li&gt;Caching other resources like images, etc., for faster loading from the server.&lt;/li&gt;
&lt;li&gt;Handling things like "Add To Home Screen" by providing necessary amount of information about the website.&lt;/li&gt;
&lt;li&gt;Utilizing APIs like Push Notifications, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PWAs are getting much popular nowadays because they provide an app-like experience to websites; hence, justifying the title &lt;strong&gt;"web applications"&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;So that's all I wanted to include in this post. If you like my writing style, feel free to follow me for more posts like this!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>ssr</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Web Development: The Static Fundamentals</title>
      <dc:creator>Sapinder Singh</dc:creator>
      <pubDate>Sat, 10 Jul 2021 11:47:00 +0000</pubDate>
      <link>https://forem.com/sapinder-singh/web-development-the-static-fundamentals-6do</link>
      <guid>https://forem.com/sapinder-singh/web-development-the-static-fundamentals-6do</guid>
      <description>&lt;p&gt;This is the first part in the series where I will provide a foundational understanding of the websites that you see around, and use daily. In the first part, we'll get to know &lt;strong&gt;the fundamentals of &lt;em&gt;static&lt;/em&gt; web development&lt;/strong&gt;. I won't focus much on implementation, because this is to get an idea about the kind of things that exist in this field. So, I think we're ready to begin now! 👨‍🏫&lt;/p&gt;

&lt;p&gt;In the most basic sense, a website is no different from a native app, e.g. android/ios app; except that it can only do things that a web browser allows it to. It can't run on the client's system like other apps do, because it is &lt;strong&gt;&lt;em&gt;rendered&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;inside a web browser&lt;/em&gt;; and it is the thing that only a web browser understands.&lt;/p&gt;

&lt;p&gt;There are two major parts of web development- &lt;strong&gt;frontend&lt;/strong&gt; (client-side) and &lt;strong&gt;backend&lt;/strong&gt; (server-side). Let's discuss the front end first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Web
&lt;/h2&gt;

&lt;p&gt;A website is a collection of web pages, which are just plain HTML files. When you make a request to a website's server, your browser receives a ton of data in response; but one thing that is never going to be missing is HTML.&lt;/p&gt;

&lt;p&gt;Each web page is an individual HTML file. Every time we navigate to a different route, the browser makes a new request to get the HTML file for that page. For example, if you navigate from &lt;strong&gt;&lt;em&gt;/home&lt;/em&gt;&lt;/strong&gt; to &lt;strong&gt;&lt;em&gt;/about-me&lt;/em&gt;&lt;/strong&gt; route, it would make another request to the server to get HTML file for &lt;strong&gt;&lt;em&gt;/about-me&lt;/em&gt;&lt;/strong&gt; page.&lt;/p&gt;

&lt;p&gt;The best way to check is to notice the loading indicator in your browser. If it indicates that it's loading, you have essentially made a request to the server; and it's waiting for the response. In case you wonder why it doesn't happen on this site, you'll get to know the reason in the &lt;a href="https://dev.to/sapinder_dev/the-dynamic-web-40kk"&gt;next part&lt;/a&gt; of this series. 😉&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;HTML stands for HyperText Markup Language, where  &lt;a href="https://en.wikipedia.org/wiki/Hypertext" rel="noopener noreferrer"&gt;HyperText &lt;/a&gt; refers to text that contains references to some other text. So essentially, that's how you jump from one web page to another.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, do you like the way this button looks?&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/sapinder_dev/embed/wvdWZBG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Most likely not! But what about this one?&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/sapinder_dev/embed/dyWXLoL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The first one is a plain HTML button with default styles, but the second one utilizes CSS to apply custom styles. Below is a sample code for this fancy button-&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="c"&gt;&amp;lt;!-- HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;I'm a Fancy Button!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* CSS */&lt;/span&gt;
&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* consider 'value' as a placeholder */&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&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="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&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;CSS stands for &lt;em&gt;Cascading&lt;/em&gt; Style Sheets, which actually states what it does. The styles are applied from top to bottom &lt;em&gt;in the order they are defined&lt;/em&gt;, just like a cascading waterfall. &lt;strong&gt;Any repeated style would override its previous corresponding values&lt;/strong&gt;, as in the following example.&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;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* This will override the previous value for 'color' */&lt;/span&gt;
&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&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;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;p&gt;Now, just HTML &amp;amp; CSS ain't enough for a modern website. For example, that &lt;em&gt;Fancy Button&lt;/em&gt; above does nothing when you click on it. But a button is really meant to trigger some action. Now click on the button below to see what happens.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/sapinder_dev/embed/wvdWZMW?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You guessed it- it's &lt;em&gt;JavaScript&lt;/em&gt;! 😄 It adds functionality to these showpieces. Just like HTML &amp;amp; CSS, &lt;strong&gt;JavaScript is a client-side language&lt;/strong&gt;; meaning that it is interpreted and executed by a web browser. It can't run natively outside a web browser, unlike C++, Java, Python, and other commonly used &lt;em&gt;server-side&lt;/em&gt; languages.&lt;/p&gt;

&lt;p&gt;Working in JavaScript is similar to many other languages, for example, the following statement declares a variable named &lt;code&gt;myName&lt;/code&gt; that we can do anything with.&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;var&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sapinder Singh&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;We can use and manipulate this variable as and when needed. But in JavaScript, we don't want to work with these variables only; we instead want to operate on &lt;em&gt;HTML elements present on the page&lt;/em&gt;! So how do we operate on HTML elements in JavaScript?&lt;/p&gt;

&lt;p&gt;You must have at least heard of the term &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/API" rel="noopener noreferrer"&gt;&lt;strong&gt;API&lt;/strong&gt;&lt;/a&gt; (Application Programming Interface). As the name suggests, an API serves as an interface for different pieces of software to communicate with and provide data to each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When it comes to interacting with HTML, JavaScript needs &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model#html_dom" rel="noopener noreferrer"&gt;DOM API&lt;/a&gt; &lt;br&gt;
that stands for Document Object Model&lt;/strong&gt;. It provides the HTML document to JavaScript in the form of an Object Model. The root of this &lt;em&gt;inverted tree-like&lt;/em&gt; object is the document itself. Each element in the document gets its own node that goes as deep as the number of children elements it holds.&lt;/p&gt;

&lt;p&gt;So if I want to select that "Fancy Button" in JavaScript using DOM API, I would do this-&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="c1"&gt;// assuming the button does have an id&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;fancyButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fancy-button&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;Instead of assigning a regular value to some variable, I would have to assign it a DOM element. I can then treat this variable like an actual element on the page. The following statement implements a part of that 'click' thing on the button.&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="cm"&gt;/* Don't worry if you don't understand the syntax, 
  you're here just to understand what it does. */&lt;/span&gt;
&lt;span class="nx"&gt;fancyButton&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I've been clicked! :)&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;So in essence, &lt;strong&gt;HTML, CSS and JavaScript form the basis of front end of a &lt;em&gt;modern&lt;/em&gt; website&lt;/strong&gt;. We can-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;have one or more HTML files (and other &lt;em&gt;optional&lt;/em&gt; files such as &lt;em&gt;.css&lt;/em&gt;, &lt;em&gt;.js&lt;/em&gt;, etc., linked from within HTML)&lt;/li&gt;
&lt;li&gt;open the &lt;em&gt;root&lt;/em&gt; HTML file in any web browser&lt;/li&gt;
&lt;li&gt;and see it render in the form of a web page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But as you may guess, it's totally useless as long as only we can see the web pages. That's why we now need to head to the next section. 😛&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Web
&lt;/h2&gt;

&lt;p&gt;A web server is needed in order to &lt;em&gt;serve&lt;/em&gt; our web pages to the world. For this task, we have a lot of server-side languages such as Java, PHP, Ruby, Python, C++, etc. I mentioned earlier that JavaScript is a &lt;em&gt;client-side&lt;/em&gt; language, because it can not be run outside a web browser to act like a web server. Now I'm ready to admit- &lt;strong&gt;that was kind of a lie!&lt;/strong&gt; 😅&lt;/p&gt;

&lt;h3&gt;
  
  
  Meet Node.js
&lt;/h3&gt;

&lt;p&gt;We have &lt;a href="https://nodejs.dev/learn" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; that is a &lt;a href="https://olinations.medium.com/the-javascript-runtime-environment-d58fa2e60dd0" rel="noopener noreferrer"&gt;JavaScript runtime environment&lt;/a&gt;. A runtime environment combines different tools and technologies to provide a suitable environment that enables it to run a certain program or application. &lt;/p&gt;

&lt;p&gt;Your web browser too provides a runtime environment for JavaScript that supplies various APIs to the core JavaScript engine like DOM for parsing HTML, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage" rel="noopener noreferrer"&gt;Storage API&lt;/a&gt; for storing website's data on client's system, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model" rel="noopener noreferrer"&gt;CSSOM&lt;/a&gt; for manipulating styles using JavaScript, etc. But &lt;strong&gt;the core part of a JavaScript runtime environment is the JavaScript engine&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Google Chrome and other Chromium-based web browsers use Google's V8 engine for running JavaScript, which is written in C++. Interestingly enough, Node.js also uses the same engine. But instead of providing APIs like DOM or so, it uses other tools that allow access to Operating System, File System, Networking, etc. This, as a result, enables us to use JavaScript as a server-side language.&lt;/p&gt;

&lt;p&gt;Node.js is a popular choice among other backend languages nowadays. A major advantage for those coming from frontend part&lt;br&gt;
is that &lt;em&gt;you don't have to learn another language to setup a server&lt;/em&gt;! You're all set if you know JavaScript well enough.&lt;/p&gt;
&lt;h3&gt;
  
  
  Working of a Server
&lt;/h3&gt;

&lt;p&gt;A server is always up and running (if not crashed! 🙄), listening to requests and sending appropriate responses to its clients. The type of response depends on what type of request a user makes. These are called &lt;em&gt;methods&lt;/em&gt;. Following are the two most commonly known request methods used over &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP" rel="noopener noreferrer"&gt;HTTP&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt; - This method should be used for &lt;em&gt;retrieving&lt;/em&gt; a resource from the server. As an example, when you visit any 
website, the browser makes a &lt;code&gt;GET&lt;/code&gt; request to the server asking for a web page present on that route.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;POST&lt;/strong&gt; - This method should be used for &lt;em&gt;posting/submitting&lt;/em&gt; data to the server, usually when &lt;em&gt;creating a new resource&lt;/em&gt;. When you fill up a web form, that form mostly uses &lt;code&gt;POST&lt;/code&gt; method as shown in the snippet below.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- The form fields go here --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I can't show you the actual implementation of how a server handles requests and responses in Node.js because it might be a little complex for beginners; but here's a &lt;a href="https://en.wikipedia.org/wiki/Pseudocode" rel="noopener noreferrer"&gt;Pseudo code&lt;/a&gt; for this job-&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;CREATE&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nx"&gt;CALL&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;activate&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;

&lt;span class="c1"&gt;// Now handle requests from different routes, e.g. '/home' or any route&lt;/span&gt;
&lt;span class="nx"&gt;IF&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="nx"&gt;EQUALS&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="nx"&gt;SEND&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;ELSE&lt;/span&gt; &lt;span class="nx"&gt;IF&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="nx"&gt;EQUALS&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/create-user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="c1"&gt;// the user wants to visit the page where it can create a new account&lt;/span&gt;
  &lt;span class="nx"&gt;IF&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="nx"&gt;EQUALS&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="nx"&gt;SEND&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/create-user.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

  &lt;span class="c1"&gt;// if the method is POST, it means the user submitted a form on '/create-user' route&lt;/span&gt;
  &lt;span class="nx"&gt;ELSE&lt;/span&gt; &lt;span class="nx"&gt;IF&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="nx"&gt;EQUALS&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="nx"&gt;SEND&lt;/span&gt; &lt;span class="nx"&gt;newlyCreatedAccount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was to give you a brief idea of a server. If you notice the handler for &lt;code&gt;POST&lt;/code&gt; method on &lt;strong&gt;&lt;em&gt;/create-user&lt;/em&gt;&lt;/strong&gt; route, we're trying to create a new user based on the data received via &lt;code&gt;request&lt;/code&gt; object; and then provide that &lt;code&gt;newlyCreateAccount&lt;/code&gt; to the user. But we actually need to store that account to remember it in the future. So, it's time to head to the next section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Databases
&lt;/h3&gt;

&lt;p&gt;You may already have an idea of what a database is. A Database is like a store with a certain way of organizing and working with data. A common term you would hear relating to databases is &lt;strong&gt;CRUD&lt;/strong&gt;; an abbreviation for &lt;em&gt;Create&lt;/em&gt;, &lt;em&gt;Read&lt;/em&gt;, &lt;em&gt;Update&lt;/em&gt; and &lt;em&gt;Delete&lt;/em&gt;. These four are the most basic operations that a database performs. &lt;/p&gt;

&lt;p&gt;There are many types of databases, but the &lt;a href="https://www.logianalytics.com/relational-vs-non-relational-databases/" rel="noopener noreferrer"&gt;two major categories&lt;/a&gt; are &lt;strong&gt;Relational&lt;/strong&gt; and &lt;strong&gt;Non-Relational&lt;/strong&gt;. Sometimes they are also referred to as SQL (Structured Query Language) and &lt;br&gt;
NoSQL respectively. Let's take a look at each of them-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relational/SQL Databases&lt;/strong&gt; - These types of databases store data in a table-like format, where each row represents an entity while each column holds certain data about that entity such as Name, Address, etc. MySQL and PostgreSQL are two popular relational databases to consider when working with Node.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Relational/NoSQL Databases&lt;/strong&gt; - The 'No' in NoSQL means &lt;em&gt;Not only&lt;/em&gt;, meaning that it can be of any form. These are more flexible than their SQL counterparts. The most popular NoSQL choices with Node.js are MongoDB and Redis.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choosing a database depends on the type of data you're going to store, and it is advised to research about different options before making a choice to get optimal performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server-side APIs
&lt;/h3&gt;

&lt;p&gt;Ever wondered how the weather app on your cell phone collects so much amount of weather info? And how does google maps know what place is where? And where does this little &lt;a href="https://sapinder-pal.github.io/IP-Address-Tracker-Vanilla-JS-CSS/" rel="noopener noreferrer"&gt;ip-address-tracker-app&lt;/a&gt; get all the data from? &lt;/p&gt;

&lt;p&gt;It's all done via APIs. A server-side API is similar to a web server, but instead of serving a web app, it serves &lt;em&gt;data&lt;/em&gt; to other apps so they could make use of it. That ip-address-tracker-app utilizes &lt;a href="https://geo.ipify.org/" rel="noopener noreferrer"&gt;IP Geolocation API by IPify&lt;/a&gt; to collect data about different IP addresses.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;endpoint&lt;/strong&gt; can be thought of a final destination that we can visit to get data or perform some other action related to that data. Endpoint may be considered a fancy name for URL. Visiting any of the endpoint of an API should return some data rather than a web page. For example, if you visit &lt;a href="https://api.thecatapi.com/v1/images/search" rel="noopener noreferrer"&gt;this endpoint&lt;/a&gt; of &lt;a href="https://docs.thecatapi.com/" rel="noopener noreferrer"&gt;TheCatApi&lt;/a&gt;, you shall receive an object consisting of a URL of some random image, along with other details about the it.&lt;/p&gt;

&lt;p&gt;We can have any number of endpoints in a server-side API, but the API has to follow some well-thought architecture to be accessible and maintained in a large scale project. The standard protocol for web APIs is to use a &lt;strong&gt;RESTful architecture&lt;/strong&gt;. If you wish to learn more, refer to this &lt;a href="https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/" rel="noopener noreferrer"&gt;post about RESTful API&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To summarize so far-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We have HTML, CSS &amp;amp; JavaScript working together on client-side&lt;/li&gt;
&lt;li&gt;We have a Server handling client's requests/responses, using Node.js&lt;/li&gt;
&lt;li&gt;We can also use Databases to store data&lt;/li&gt;
&lt;li&gt;We can also serve an API instead of an application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let's head to the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosting Providers And Domains
&lt;/h2&gt;

&lt;p&gt;The so-called &lt;em&gt;web server&lt;/em&gt; that we know about so far yet is on our local machine only. We can run the server in background, and open, for example &lt;em&gt;localhost:8000&lt;/em&gt;, in the browser to see our website. &lt;code&gt;8000&lt;/code&gt; is a &lt;a href="https://computersciencewiki.org/index.php/Ports" rel="noopener noreferrer"&gt;port&lt;/a&gt; number. But instead of hosting our server &lt;em&gt;locally&lt;/em&gt;, we now need to &lt;strong&gt;host it somewhere else&lt;/strong&gt; to make it available to the world. We want to &lt;em&gt;deploy&lt;/em&gt; our app to a hosting &lt;br&gt;
provider that would run our server 24*7 on its huge machines.&lt;/p&gt;

&lt;p&gt;There you would also need a &lt;a href="https://en.wikipedia.org/wiki/Domain_name" rel="noopener noreferrer"&gt;&lt;strong&gt;domain&lt;/strong&gt;&lt;/a&gt; name for people to be able to access your server on the internet, because now it can't be reached via localhost. A domain name is the &lt;em&gt;*.com&lt;/em&gt; part of a url. For&lt;br&gt;
example, in my website's url &lt;a href="https://blog.sapinder.dev" rel="noopener noreferrer"&gt;https://blog.sapinder.dev&lt;/a&gt;, the domain name is &lt;em&gt;sapinder.dev&lt;/em&gt; where &lt;em&gt;dev&lt;/em&gt; is a top-level domain just like &lt;em&gt;com&lt;/em&gt;, &lt;em&gt;org&lt;/em&gt;, etc. If you wonder, the &lt;em&gt;blog&lt;/em&gt; part is a sub-domain.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Fun Fact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can have any number of subdomains once you own the domain name. Also, www is a subdomain too!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Apart from buying a domain name, we also have to pay regular charges to our hosting providers because they run our server 24*7. But most of the hosting providers offer free tier services with limited resources, and we can upgrade our accounts as our requirements grow. Meanwhile, free tier services are mostly more than enough for beginners, and they also provide a free domain! The main caveat is that it ends with their default domain names. For example, &lt;em&gt;*.herokuapp.com&lt;/em&gt; for Heroku, &lt;em&gt;*.netlify.app&lt;/em&gt; for Netlify, and so on. If you want your own domain name, to look &lt;em&gt;actually&lt;/em&gt; professional, you will have to buy one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version Controlling
&lt;/h2&gt;

&lt;p&gt;Maintaining the code is also really important, as it's the only way to identify &amp;amp; fix currently present bugs, as well as to bring new features to an app. &lt;a href="https://careerfoundry.com/en/blog/web-development/whats-version-control-and-why-do-i-need-it/" rel="noopener noreferrer"&gt;Version Control Systems&lt;/a&gt; allow us to track &amp;amp; add changes, and even &lt;strong&gt;revert the whole app back to a previous version!&lt;/strong&gt; Now you know how powerful these systems can be.&lt;/p&gt;

&lt;p&gt;The most widely used VSC is &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt;. There are a few terms that you should know when using Git, a few of which are-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Branch&lt;/strong&gt; - Branching allows developers to keep their &lt;em&gt;code repositories&lt;/em&gt; into separate branches, each for a specific purpose. For example, I usually maintain two different branches for my code, namely &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;development&lt;/code&gt;. &lt;code&gt;main&lt;/code&gt; is the default branch when git is implemented, whereas I keep a separate &lt;code&gt;development&lt;/code&gt; branch for development purposes. The number and purpose of branches may increase in large scale projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stage&lt;/strong&gt; - There is a &lt;a href="https://git-scm.com/about/staging-area" rel="noopener noreferrer"&gt;staging area&lt;/a&gt; in git that holds all the &lt;em&gt;ready-to-be-made&lt;/em&gt; changes in our code. We add the changed files in our code to staging area via &lt;code&gt;git add &amp;lt;file-name&amp;gt;&lt;/code&gt; command in order to 
be able to review the changes before making a final &lt;em&gt;commit&lt;/em&gt;, which leads us to the next point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commit&lt;/strong&gt; - After we have reviewed the changes, we're ready to run &lt;code&gt;git commit&lt;/code&gt; command that finally creates a new version in the git history for our code repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt; - We can &lt;em&gt;merge the changes&lt;/em&gt; made to any branch into another branch. Say I made changes to &lt;code&gt;development&lt;/code&gt; branch, and I've tested them as well, now I can &lt;code&gt;merge&lt;/code&gt; them into my &lt;code&gt;main&lt;/code&gt; branch to publish changes to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can also &lt;code&gt;revert&lt;/code&gt; our current version to any of the earlier commits by using that commit's ID. There are many other things that version control systems allow us to do that you would get to know as you use them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote Repositories
&lt;/h3&gt;

&lt;p&gt;What is the probability that your app code, saved in some location on your local system, is going to be safe forever? What if it gets deleted, or accessed by someone else? You get it- we need to store it online so that only we could access it anytime and on any system. &lt;br&gt;
&lt;strong&gt;If somehow we loose the local repository, we can &lt;em&gt;clone&lt;/em&gt; it from our remote respository along with all of the git history!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remote repositories are not always &lt;em&gt;private&lt;/em&gt;, but &lt;em&gt;public&lt;/em&gt; too. They are known as &lt;a href="https://en.wikipedia.org/wiki/Open_source" rel="noopener noreferrer"&gt;Open Source&lt;/a&gt; projects that anyone can contribute to because their &lt;em&gt;source code&lt;/em&gt; (or just code) is openly available to other developers in the community. For example, Firefox, Node.js, VLC Player, Linux, etc., are all open-source projects that anyone can contribute to.&lt;/p&gt;

&lt;p&gt;Speaking of cloud-based/remote repository platforms, two of the most popular ones are &lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and &lt;a href="https://about.gitlab.com/" rel="noopener noreferrer"&gt;Gitlab&lt;/a&gt;, the former being the leading solution. These are like Facebook for developers and programmers to showcase their projects, as well as to maintain them. If you want to take a look, here's &lt;a href="https://github.com/sapinder-pal" rel="noopener noreferrer"&gt;my Github profile&lt;/a&gt; (&lt;em&gt;No, I don't mean it!&lt;/em&gt; 😅).&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;So, this was my attempt to give you the best overview of fundamentals of web technologies. In the next part of this series, we will learn about &lt;a href="https://dev.to/sapinder_dev/the-dynamic-web-40kk"&gt;the dynamic part of web&lt;/a&gt; that powers modern websites we see around. So stick around if you like my writing style! &lt;br&gt;
You can &lt;b&gt;&lt;em&gt;follow me&lt;/em&gt;&lt;/b&gt; if you want to never miss any of my future content!&lt;/p&gt;

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