<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saksham</title>
    <description>The latest articles on DEV Community by Saksham (@sakshamak).</description>
    <link>https://dev.to/sakshamak</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%2F539631%2F2f597ced-b5c1-4c0f-bc49-ab4ba733e57c.jpg</url>
      <title>DEV Community: Saksham</title>
      <link>https://dev.to/sakshamak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sakshamak"/>
    <language>en</language>
    <item>
      <title>What is HTTP?</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Sat, 30 Jul 2022 20:49:00 +0000</pubDate>
      <link>https://dev.to/sakshamak/what-is-http-3hkn</link>
      <guid>https://dev.to/sakshamak/what-is-http-3hkn</guid>
      <description>&lt;p&gt;We all use HTTP when we surf on the web.&lt;br&gt;
And without HTTP it's generally not possible to search the web.&lt;/p&gt;

&lt;p&gt;Even if we try not to write "http" before our links, browser sets it to http by default.&lt;/p&gt;

&lt;p&gt;Let's see what is HTTP?&lt;/p&gt;

&lt;h2&gt;
  
  
  What is HTTP?
&lt;/h2&gt;

&lt;p&gt;We all know it is a transfer protocol used to send data over the web.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;According to web&lt;/strong&gt; - HTTP is an application level protocol used for fetching resources such as HTML document.&lt;/p&gt;

&lt;p&gt;Application level means that it works on the top layer of the OSI model. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We won't go deep in the OSI model but for an overview:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An OSI model is a conceptual model which provides a standard of communication between computers.&lt;/p&gt;

&lt;p&gt;And the application layer is where applications can access network services and can interacts with the users. &lt;/p&gt;

&lt;p&gt;HTTP is the foundation of data exchange on web and is also known as a &lt;strong&gt;client-server protocol&lt;/strong&gt; as it allows the browser to communicate with the server.&lt;/p&gt;

&lt;p&gt;(here the client is the browser and hence the name client-server protocol).&lt;/p&gt;

&lt;p&gt;Apart from being a simple data transfer protocol, it can be used as a generic protocol for user agents (such as browsers), proxies/gateways including those supported by protocols like SMTP and FTP and hence it can access resources from different apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  History of HTTP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The first version of HTTP formed was &lt;code&gt;HTTP/0.9&lt;/code&gt; that was used to transfer raw data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HTTP/1.0&lt;/code&gt; was introduced later that allowed us to transfer MIME-like messages such as media files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HTTP/1.0&lt;/code&gt; was doing great but there was a problem, it was not reliable, so to overcome that &lt;code&gt;HTTP/1.1&lt;/code&gt; was introduced that works on a &lt;strong&gt;TCP&lt;/strong&gt; connection to ensure reliable implementations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;BUT HTTP doesn't just depends on TCP. It can even send data over a TLS/SSL protocol or any other reliable transport protocol.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Just to understand&lt;/strong&gt; - A Transport Layer Security (TLS) also known as Secure Socket Layer (SSL) is a protocol to communicate securely ensuring privacy through cryptographic protocols.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP versioning
&lt;/h2&gt;

&lt;p&gt;HTTP uses structure as &amp;lt;major&amp;gt;.&amp;lt;minor&amp;gt; to indicate versions.&lt;/p&gt;

&lt;p&gt;&amp;lt;minor&amp;gt; is incremented when a version change do not affect the communication behavior and is an addition of message components.&lt;/p&gt;

&lt;p&gt;&amp;lt;major&amp;gt; is incremented when format of a message within the protocol is changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working of HTTP
&lt;/h2&gt;

&lt;p&gt;So now we know what is http? And it's history. Let's see how it works.&lt;/p&gt;

&lt;p&gt;As we know it is a client-server protocol, it's follows a request-response method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Request
&lt;/h3&gt;

&lt;p&gt;A client sends a message to server (request) in the form of a request method, URI, and protocol version followed by a MIME-like message containing request modifiers, client information, and content body.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Request method: GET, POST, PUT, DELETE&lt;/li&gt;
&lt;li&gt;Protocol version: such as &lt;code&gt;HTTP/1.0&lt;/code&gt; &lt;code&gt;HTTP/1.1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Client information: your browser identity&lt;/li&gt;
&lt;li&gt;Content body: what you want from server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The request sender can be a proxy or browser know as a user agent or a robot crawling the web to populate and maintain the search engine index.&lt;/p&gt;

&lt;h4&gt;
  
  
  Proxy
&lt;/h4&gt;

&lt;p&gt;A Proxy is a computer or program used when navigating through the network. It lies between the client and the server (these can be modems and routers as well).&lt;/p&gt;

&lt;p&gt;It can access the web and can intercepts the request and respond back and can manipulate the request received before sending it further.&lt;/p&gt;

&lt;p&gt;Most of the proxy machines lies in the last four layers of the OSI model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Response
&lt;/h3&gt;

&lt;p&gt;When the request is received by the server, it responds back with a status code, status message, MIME-like message containing server information, metainformation, and entity body content&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Status codes: A code to if its a success or fail&lt;/li&gt;
&lt;li&gt;Status message: human readable form of the success/fail message&lt;/li&gt;
&lt;li&gt;Body content: expected result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although most communications are initiated by the clients to the origin server but nowadays servers can initiate a communication too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components of HTTP-based Systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Client (The User Agent)
&lt;/h3&gt;

&lt;p&gt;A user agent is anything that works on behalf of the user, generally this role is performed by the browsers. Browsers sends the request to the server and receives an HTML page and then requests for other files as specified in the HTML page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Proxies
&lt;/h3&gt;

&lt;p&gt;As we have covered proxies above, it's the same old same old.&lt;/p&gt;

&lt;p&gt;Proxies can manipulate a request coming from the client and can translate it to different HTTP versions and to the server understandable form.&lt;/p&gt;

&lt;h3&gt;
  
  
  Servers
&lt;/h3&gt;

&lt;p&gt;A server is a computer that serves the documents to the client.&lt;br&gt;
It is called as a computer but actually it is collection of computers sharing the load or communicating with other computers.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP Flow:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open a TCP connection: A connection is established between client and server. Client sends a message to the server and server responds back with acknowledgement, this is how it is made sure that the connection is reliable and the packets are not being sent to nothing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Send HTTP message: A request is formed and sent to the server. &lt;br&gt;
Example: &lt;code&gt;GET / HTTP/1.1&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server responds back: Server sends a response back to the cliend&lt;br&gt;
Example: &lt;code&gt;HTTP/1.1 200 OK&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connection is closed or reused.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connection and HTTP
&lt;/h2&gt;

&lt;p&gt;A connection can be established between two devices in any form.&lt;br&gt;
It's not necessary whether the connection is secured or not.&lt;/p&gt;

&lt;p&gt;A connection is formed at the transport layer with or without reliability.&lt;/p&gt;

&lt;p&gt;But for an HTTP connection, it must be reliable, protocols like TCP are used here.&lt;/p&gt;

&lt;p&gt;For a simple connection between a client and a server it's not much of a story.&lt;/p&gt;

&lt;p&gt;But when proxies, gateways, and tunnels come in, it gets complicated and request is rewritten a few time.&lt;/p&gt;

&lt;p&gt;A proxy is a forwarding agent rewriting all or part of message and send it to the server identified by the URI.&lt;/p&gt;

&lt;p&gt;A gateway is a receiving agent, lies above server layer and can translate request to server protocol.&lt;/p&gt;

&lt;p&gt;A Tunnel acts as a relay point between two connections without changing the message, used to pass messages through firewall generally&lt;/p&gt;

&lt;p&gt;Request ------&amp;gt; UA --------&amp;gt; P --------&amp;gt; V ------&amp;gt; G --------&amp;gt; V --------&amp;gt; S&lt;/p&gt;

&lt;p&gt;UA - user-agent&lt;br&gt;
P - proxy&lt;br&gt;
V - single connection&lt;br&gt;
G - gateway&lt;br&gt;
S - server&lt;/p&gt;

&lt;p&gt;Proxy and gateways must be careful while forwarding the messages in different version of protocol, as they must not send a request with higher version of protocol than the actual version.&lt;br&gt;
If that happens then they must downgrade it or respond with error or use a tunnel.&lt;/p&gt;

&lt;p&gt;That's all about HTTP. Thank you for reading.&lt;br&gt;
Feedbacks are appreciated.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The story behind JS: how async works</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Fri, 14 Jan 2022 19:18:16 +0000</pubDate>
      <link>https://dev.to/sakshamak/the-story-behind-js-how-async-works-2jea</link>
      <guid>https://dev.to/sakshamak/the-story-behind-js-how-async-works-2jea</guid>
      <description>&lt;p&gt;We all know that JS is a single-threaded non-blocking asynchronous concurrent language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what does this actually mean?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s find out: &lt;/p&gt;

&lt;p&gt;Suppose we have a function that calls another function that calls one more function, such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;finalFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addDigits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addDigits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;finalFunc&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We all know that &lt;code&gt;finalFunc&lt;/code&gt; will call &lt;code&gt;callAdd&lt;/code&gt;, callAdd will call &lt;code&gt;add&lt;/code&gt;, and add will return the sum of these two numbers and we will get &lt;code&gt;7&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;But what’s happening behind the scenes?&lt;br&gt;
&lt;a href="https://i.giphy.com/media/xT0xemn9kAM4F52NFK/giphy-downsized.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xT0xemn9kAM4F52NFK/giphy-downsized.gif" alt="gif" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, there is a thing called &lt;strong&gt;call stack&lt;/strong&gt; in JavaScript which is a type of data structure that records basically where we are currently in our program. &lt;/p&gt;

&lt;p&gt;It looks something like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qiDyLXBL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186131751/yzMLLABof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qiDyLXBL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186131751/yzMLLABof.png" alt="image.png" width="283" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in here, this is how our program runs:&lt;/p&gt;

&lt;p&gt;lets take a look at our code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;finalFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addDigits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addDigits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;finalFunc&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here when we called the &lt;code&gt;finalFunc&lt;/code&gt; function, it was recorded in the call stack, and inside that we called another function which was then called and got recorded in the call stack again, which called the &lt;code&gt;add&lt;/code&gt; function and it gets recorded as we can see in our diagram. &lt;/p&gt;

&lt;p&gt;The return statement then gets executed and the function is removed from the call stack. &lt;br&gt;
then the return statement of &lt;code&gt;callAdd&lt;/code&gt; function gets executed and it gets removed from the stack and then the &lt;code&gt;finalFunc&lt;/code&gt; then calls the &lt;code&gt;console.log&lt;/code&gt; function and it gets executed and then the &lt;code&gt;finalFunc&lt;/code&gt; is removed from the call stack and the program ends.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vBYKZP4v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186480797/CCUSBkmil.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vBYKZP4v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186480797/CCUSBkmil.gif" alt="ezgif.com-gif-maker (1).gif" width="600" height="330"&gt;&lt;/a&gt;&lt;br&gt;
So this is how our program actually runs inside JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Correction: The code in this video is a bit incorrect, the actual code is the one written above.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Waiting for Callbacks and SetTimeout
&lt;/h3&gt;

&lt;p&gt;Let us assume that callbacks and setTimeout are synchronous and we call them in our program. Then what do you think will happen? &lt;br&gt;
The call stack waits until the processing of the current is done. So, yes, the call stack will have to wait till the timeout ends. Till then we won't be able to do any task. &lt;/p&gt;

&lt;p&gt;And suppose there is one callback that never returns. Then what?&lt;br&gt;
Your code will be stuck forever. That’s why being asynchronous is important.&lt;/p&gt;

&lt;p&gt;We did the normal function call in JS. But now let's try setTimeout in our program. FYI setTimeout and callbacks are not part of the JS engine. They are part of browser API.&lt;/p&gt;

&lt;p&gt;And now setTimeouts are something that waits to perform a particular action. But as we said JavaScript is a non-blocking language. Then where does this waiting go?&lt;/p&gt;

&lt;p&gt;So what happens behind the scenes, in the case of timeouts, is that when a timeout is called it is shifted to a special place called &lt;strong&gt;callback queue&lt;/strong&gt; or &lt;strong&gt;task queue.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The role of the callback queue is to hold the timeouts when they are complete and send it to the call stack when it's empty.&lt;/p&gt;

&lt;p&gt;But who checks if the call stack is empty or not?&lt;/p&gt;

&lt;p&gt;This is where the event loop comes into play. The event loop keeps on checking if the queue and call stack are empty or not, if the task queue is not empty it checks if the call stack is empty or not, if the call stack is empty then it sends the timeouts to call stack one by one.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;callAdd&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;callAdd&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Output: &lt;/span&gt;
&lt;span class="c1"&gt;//5&lt;/span&gt;
&lt;span class="c1"&gt;// callAdd&lt;/span&gt;
&lt;span class="c1"&gt;//hello world&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how a browser looks and as we can see that JS engine is not the only thing that is present in the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ae5L1sI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186905759/dMOJi-w-7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ae5L1sI6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186905759/dMOJi-w-7.png" alt="image.png" width="490" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we look at the above code, initially the call stack is empty, when the code starts running, first the console.log() function will come in the call stack and it will call the add function. The add function will execute and is removed from the stack, then console.log is executed and removed from the stack.&lt;/p&gt;

&lt;p&gt;Next comes the settimeout, function that comes to the call stack but then it is moved to the browserAPI section and waits till the timer is up, and is moved to the task queue, till then callAdd function is called to the call stack, and is executed, then console.log function is called inside the call stack and is executed and removed and then callAdd function is removed.&lt;/p&gt;

&lt;p&gt;And in between that the event loop keeps on checking if the call stack is empty or not, now as our call stack is empty, the event loop sends the setTimeout function from the task queue to the call stack which then calls the console.log() function which executes and removed from the call stack and finally setTimeout is removed from the stack and the program ends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iuBaMVDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186965937/q3XU5KFX4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iuBaMVDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642186965937/q3XU5KFX4.gif" alt="ezgif.com-gif-maker.gif" width="600" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you must be wondering what this microtask queue is?&lt;br&gt;
Well, it's exactly the same as a callback queue except that all the callbacks functions are stored here and the Microtask queue has a &lt;strong&gt;higher priority&lt;/strong&gt; over the callback queue. which means that if there is anything inside the microtask queue it doesn't matter if the callback queue is full. &lt;/p&gt;

&lt;p&gt;Until the microtask queue is not empty callback queue will not run.&lt;/p&gt;

&lt;p&gt;If we made a callback function, then that is stored in the browser api till it gets resolved, it is then sent to the microtask queue and the event loop waits till the call stack is empty and then sends the callback function to the call stack and it executes.&lt;/p&gt;

&lt;p&gt;So this was all about how async JS works. And yes, JS doesn’t like to wait so thanks to the event loop and the queues for the hard work.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Nullish Coalescing??</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Thu, 13 Jan 2022 11:40:21 +0000</pubDate>
      <link>https://dev.to/sakshamak/nullish-coalescing-4m6j</link>
      <guid>https://dev.to/sakshamak/nullish-coalescing-4m6j</guid>
      <description>&lt;p&gt;Nullish coalescing? &lt;/p&gt;

&lt;p&gt;what is that word. Hmm... koala...sing? &lt;br&gt;
&lt;a href="https://i.giphy.com/media/l3vQWWQtYTr3ItcFG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l3vQWWQtYTr3ItcFG/giphy.gif" alt="koala sining" width="480" height="480"&gt;&lt;/a&gt;bad joke alert!!!&lt;/p&gt;

&lt;p&gt;Hello everyone, I’m Saksham and I am back again with a new blog about an es6 feature which I personally found really cool and is pronounced as &lt;strong&gt;Null-ish koh-uh-les-ing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yeah, it took me some time too, to get the spelling right haha.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/xT1XGyjDty7M0CaO2I/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xT1XGyjDty7M0CaO2I/giphy.gif" alt="relax" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is it?
&lt;/h2&gt;

&lt;p&gt;Nullish coalescing is a short circuiting operator denoted by '&lt;strong&gt;??&lt;/strong&gt;'&lt;/p&gt;

&lt;p&gt;Purpose of this operator is very simple. Do you know about short circuiting OR operator? Its the same but with some precision, we can say.&lt;/p&gt;

&lt;p&gt;lets first discuss about short circuiting OR operator in short.&lt;/p&gt;

&lt;p&gt;OR operator, other that using it in getting boolean values, can be used directly if we want to evaluate something from left to right and get the result&lt;br&gt;
&lt;a href="https://i.giphy.com/media/WRQBXSCnEFJIuxktnw/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/WRQBXSCnEFJIuxktnw/giphy.gif" alt="image" width="504" height="322"&gt;&lt;/a&gt;&lt;br&gt;
Lets take an exampe to understand it much better&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&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="s2"&gt;Saksham&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt; &lt;span class="o"&gt;=&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="s2"&gt;New User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;My name is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//My name is Saksham&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anotherName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;anotherName&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//Welcome New User&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see in the above example, When there was a value in the right hand side it returned that but when the string was empty it returned the left hand side value. &lt;/p&gt;

&lt;p&gt;That’s because OR operator check for the right hand side value and if its a &lt;em&gt;falsy&lt;/em&gt; value (0, “”, [], null, undefined, NaN) then it returns the left side (no matter what value is there). &lt;/p&gt;

&lt;p&gt;This is how OR operator works. &lt;/p&gt;

&lt;p&gt;Similar is the case of nullish coalescing operator, the difference is that it will return the right hand side only when the left side give &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Lets take another example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;setHeight&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Height is set to &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Height is set to 100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;strong&gt;setHeight&lt;/strong&gt; was 0 but as it is a falsy value &lt;strong&gt;100&lt;/strong&gt; was printed. But as we know heights can be 0, This is where nullish coalescing operator is used.&lt;/p&gt;

&lt;p&gt;In case of nullish coalescing operator, when the left hand side is &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined,&lt;/strong&gt; only then it will return the right hand side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getHeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;setHeight&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Height is set to &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Height is set to 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Chaining operators
&lt;/h3&gt;

&lt;p&gt;We can add multiple statements while using nullish coalescing operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;lastname&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anonymous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;//My name is Anonymous&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we chained 2 operators, the first one returned null due to which it moves to the second one, but as I said that it will return it without checking and hence returns lastname (which is undefined) but we can see that there is another operator right next to it and hence it becomes a left hand side for the second operator and it is again checked and as its undefined the answer comes out to be &lt;strong&gt;Anonymous.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is how chaining works. But you know we cannot use chaining with OR and AND operators like above, if we try, it will give an error as it is not able to decide whom to give more precedence.&lt;/p&gt;

&lt;p&gt;So to remove that error we put one of the condition in parenthesis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;lastname&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anonymous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;//Uncaught SyntaxError&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstname&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anonymous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;//My name is Anonymous&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is how ‘&lt;strong&gt;??’&lt;/strong&gt; works. That’s all about this operator. &lt;br&gt;
Thank you for reading this blog ❤️&lt;br&gt;
&lt;a href="https://i.giphy.com/media/9Y6n9TR7U07ew/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/9Y6n9TR7U07ew/giphy.gif" alt="happy" width="150" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Some CSS theories and declarations I didn't knew before</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Wed, 05 Jan 2022 11:35:22 +0000</pubDate>
      <link>https://dev.to/sakshamak/some-css-theories-and-declarations-i-didnt-knew-before-elk</link>
      <guid>https://dev.to/sakshamak/some-css-theories-and-declarations-i-didnt-knew-before-elk</guid>
      <description>&lt;p&gt;Hello folks! &lt;br&gt;
A very happy new year to all of you! 🎉🎉 &lt;br&gt;
I hope you’re all doing great!&lt;br&gt;
&lt;a href="https://i.giphy.com/media/IwAZ6dvvvaTtdI8SD5/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/IwAZ6dvvvaTtdI8SD5/giphy.gif" alt="enjoy"&gt;&lt;/a&gt;&lt;br&gt;
I am Saksham and today I am writing a blog about some CSS declarations, theories and keywords that I was unaware of.&lt;br&gt;
(These are some minor concepts which are independent of each other)&lt;/p&gt;

&lt;p&gt;I hope you might learn something new after reading this blog too.&lt;/p&gt;
&lt;h3&gt;
  
  
  Lets begin with our part ONE
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/gGldiUgAUOJ04g1Ves/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/gGldiUgAUOJ04g1Ves/giphy.gif" alt="start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most of us have faced a common problem of our content getting overflowed inside a box and we start to adjust the width/height of that content to adjust it and if the webapp is responsive, sometimes we tend to adjust the height and width of the box at every point which seems a bit weird.... and actually it is.&lt;/p&gt;

&lt;p&gt;Now here CSS comes with a concept of &lt;strong&gt;intrinsic&lt;/strong&gt; and &lt;strong&gt;extrinsic sizing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When we &lt;strong&gt;define height and width of a container&lt;/strong&gt;, it is called &lt;strong&gt;extrinsic sizing&lt;/strong&gt; and this is the one that makes the content go out of the box&lt;br&gt;
&lt;a href="https://i.giphy.com/media/AFX2Z6A6rSRG14gXWm/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/AFX2Z6A6rSRG14gXWm/giphy.gif" alt="go out"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But &lt;strong&gt;intrinsic sizing allows you to wrap the box around the text.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  This can be done in two ways:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Unsetting the height and width of the container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using &lt;strong&gt;min-content&lt;/strong&gt; and &lt;strong&gt;max-content&lt;/strong&gt; as values of height and width&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Hmmm… What are those??
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/PoImGf3Takz1BtpNSG/giphy-downsized.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/PoImGf3Takz1BtpNSG/giphy-downsized.gif" alt="think"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When value of width is set to &lt;u&gt;min-content&lt;/u&gt;, the content and box is set to the &lt;u&gt;minimum width&lt;/u&gt; it can acquire which is the &lt;u&gt;width of the largest word in the content.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;And for &lt;strong&gt;max-content&lt;/strong&gt;, the width is set to the &lt;strong&gt;max width it can go or till the sentence ends.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a urna luctus,euismod diam eu, pulvinar neque.
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;max-content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;max-content&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="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&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;justify&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&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;18px&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx84yhakts8zqxtblq8xu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx84yhakts8zqxtblq8xu.png" alt="Output"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  when height and width are constants
&lt;/h3&gt;
&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&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="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&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;p&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;18px&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flyo2o65iynbmug2zveqr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flyo2o65iynbmug2zveqr.png" alt="yay"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay! I hope this was something new for you.&lt;/p&gt;

&lt;p&gt;So, I guess we all are familiar with the CSS box model, But do you know what each of them actually includes inside them?&lt;/p&gt;

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

&lt;p&gt;Lets see!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content box:&lt;/strong&gt; it includes the main visible content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Padding box:&lt;/strong&gt; It surrounds the content box and includes the padding of the box, when overflow is set to scroll, &lt;u&gt;the scroll bars are also included here.&lt;/u&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;border box:&lt;/strong&gt; Surrounding the padding box, border box includes the borders and &lt;u&gt;properties like border radius.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Margin box:&lt;/strong&gt; It surrounds the border box and &lt;u&gt;includes the outlines and box-shadows.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;The default behaviour of a box is content box, that can be changed using &lt;code&gt;box-sizing&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Including here means that these properties wont take extra space instead the will take the space from their respective boxes&lt;br&gt;
&lt;a href="https://i.giphy.com/media/kaCGwUDpLm03HoinDv/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/kaCGwUDpLm03HoinDv/giphy.gif" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to CSS, without selectors we cannot do anything. Yes, we all use classes, ids, complex selectors like combinators, pseudo-classes, pseudo-elements.&lt;/p&gt;

&lt;p&gt;But have you ever tried going a bit specific in selecting a tag? &lt;/p&gt;

&lt;p&gt;Let's try that.&lt;br&gt;
if you want to select an element that contains a specific class and that class is acquired by some other elements too, we can select that element by doing this:&lt;/p&gt;
&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;tag-name&lt;/span&gt;&lt;span class="nc"&gt;.class-name&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Your code */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's look at an example:&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is a paragraph1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is paragraph2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.class2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="nc"&gt;.class1&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nc"&gt;.class2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f0f8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="nc"&gt;.class2&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f00a&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;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Here as we can see that &lt;code&gt;class2&lt;/code&gt; was taken by two of our elements  and &lt;code&gt;class1&lt;/code&gt; by three and to style a specific element we used the above selector type.&lt;/p&gt;

&lt;p&gt;Let's be a little &lt;strong&gt;specific.&lt;/strong&gt; Because you know, balancing is an art. More the selector is specific, more the job is hard. Less the score, more vulnerable it becomes. How?&lt;br&gt;
&lt;a href="https://i.giphy.com/media/1YGXw8iYAqwZLi3Amn/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1YGXw8iYAqwZLi3Amn/giphy.gif" alt="sppecific"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well let's say I want to select &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; which is right after &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; with class para1 under &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; of class div1 so I will write it like this:&lt;br&gt;
&lt;code&gt;div.div1 p.para1+span&lt;/code&gt;&lt;br&gt;
This will be so specific that if you want any other &lt;strong&gt;span&lt;/strong&gt; to have the same property, it wont work.&lt;/p&gt;

&lt;p&gt;Similar is the case for being less specific, if we do this, then all the elements that we don't want to get targeted will get updated. &lt;/p&gt;

&lt;p&gt;Now, we all use pseudo-classes and elements, (yes, both are different)&lt;/p&gt;

&lt;p&gt;A pseudo-class is represented by &lt;code&gt;:&lt;/code&gt; single colon and a pseudo-element is represented by &lt;code&gt;::&lt;/code&gt; double colon.&lt;/p&gt;

&lt;p&gt;And I found two of the pseudo-classes really interesting that were new to me.&lt;br&gt;
&lt;code&gt;:not&lt;/code&gt; and &lt;code&gt;:empty&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We all know the &lt;code&gt;!&lt;/code&gt; NOT operator in JavaScript right?&lt;br&gt;
this &lt;code&gt;:not&lt;/code&gt; works the same in CSS. This pseudo-class selects all the other tag which doesn't include the mentioned selector.&lt;/p&gt;

&lt;p&gt;Let's take a look at the example code:&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;this is div3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is a paragraph1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"class1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is paragraph2&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.class1&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&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;steelblue&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="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt; &lt;span class="s1"&gt;"calibri"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyuh58mfcw6gin5xx2xel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyuh58mfcw6gin5xx2xel.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must be wondering why I added html and body tag in &lt;code&gt;:not()&lt;/code&gt;, as I explained that &lt;code&gt;:not&lt;/code&gt; selects everything other than the mentioned, so if I had just added &lt;code&gt;class1&lt;/code&gt; then everything would have become red and it would be difficult to understand its working.&lt;br&gt;
Let's take another example:&lt;/p&gt;
&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.class1&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&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;steelblue&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="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt; &lt;span class="s1"&gt;"calibri"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;p&gt;Now let's talk about &lt;code&gt;:empty&lt;/code&gt;. &lt;br&gt;
&lt;code&gt;:empty&lt;/code&gt; is the pseudo-class used for elements with empty children. These children can be elements or text nodes. &lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is a paragraph inside div1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  Div with some text.
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:empty&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orangered&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Output:&lt;/p&gt;

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

&lt;p&gt;As we can see that the div with nothing inside was triggered.&lt;/p&gt;

&lt;p&gt;Similar to that there is a property for tables which hides the table cells which are empty.&lt;br&gt;
&lt;code&gt;empty-cells&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;table&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Head1&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Head2&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;Head3&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc1&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc3&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc4&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc5&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc8&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;desc9&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;th&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;td&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;tr&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="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;table&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;empty-cells&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;hide&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uentl4r1ohcv2d8wxug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uentl4r1ohcv2d8wxug.png" alt="outptu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Isn't this so cool!!&lt;br&gt;
&lt;a href="https://i.giphy.com/media/xT0xeJpnrWC4XWblEk/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xT0xeJpnrWC4XWblEk/giphy-downsized-large.gif" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, moving on, Have you ever seen something like this?&lt;/p&gt;
&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;steelblue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightblue&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;We all know the result will be the later one, CSS respects the order of declarations.&lt;br&gt;
But do you know there is a reason for doing this too.&lt;/p&gt;

&lt;p&gt;Sometimes different browsers are unable to process a particular property and CSS is a language that never breaks if something is not acceptable, instead, it ignores that to keep things working.&lt;/p&gt;

&lt;p&gt;So, when a browser doesn't understand one value it will switch to the other property value. &lt;br&gt;
&lt;a href="https://i.giphy.com/media/BSUmKgZar1biBjTzvo/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/BSUmKgZar1biBjTzvo/giphy.gif" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we all know the order of declarations but do we know about the importance of origins in CSS?&lt;/p&gt;

&lt;p&gt;It really matters if there exists any other style sheet other than our own.&lt;/p&gt;

&lt;p&gt;Following are the styles in the order of least important to the most important.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User agent base styles:&lt;/strong&gt; This is what browser applies by default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local user styles:&lt;/strong&gt; An operating system level style such as base font or preferred custom CSS by extensions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authored CSS:&lt;/strong&gt; The CSS that we create.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authored !important:&lt;/strong&gt; Same as authored CSS but with &lt;code&gt;!important&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local user styles !important:&lt;/strong&gt; Same as local user styles but with &lt;code&gt;!important&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User agent !important:&lt;/strong&gt; Same as user agent but with &lt;code&gt;!important&lt;/code&gt; keyword&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also this order applies on the properties:&lt;br&gt;
This is the order from least important to the most important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic rule types: font size background color&lt;/li&gt;
&lt;li&gt;Animation&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!important&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Transition&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Animation and transitions may have low importance but when the go active they run the highest importance.&lt;/p&gt;
&lt;h4&gt;
  
  
  Okay guys so the final topic of this blog (Thankyou so much for your time, if you made it this far)
&lt;/h4&gt;

&lt;p&gt;Finally comes the concept of &lt;strong&gt;inheritance&lt;/strong&gt; , which I always thought is not needed much but actually is really important to know.&lt;/p&gt;

&lt;p&gt;Inheritance, as the word defines itself, is a concept were the child elements inherits the properties of their parent element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://web.dev/learn/css/inheritance/#which-properties-are-inheritable" rel="noopener noreferrer"&gt;List of elements which allows inheritance.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not all elements allows inheritance by default. Some of them needs to be done explicitly which is also known as explicit inheritance.&lt;/p&gt;

&lt;p&gt;The keyword used for inheriting explicitly is &lt;strong&gt;inherit&lt;/strong&gt; which is best for some exceptions like &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML:
&lt;/h3&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;div&amp;gt;&lt;/span&gt;
  Hello world in div.
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&lt;/span&gt;Hello world in paragraph.&lt;span class="nt"&gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calibri&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;30px&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ate40td5uyq1m63k9pj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ate40td5uyq1m63k9pj.png" alt="output"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As we can see that the &lt;code&gt;font-family&lt;/code&gt; and &lt;code&gt;font-size&lt;/code&gt; is inherited by default but the &lt;code&gt;font-weight&lt;/code&gt; was not applied here. So here we will use &lt;code&gt;inherit&lt;/code&gt; as value to the &lt;code&gt;font-weight&lt;/code&gt; in &lt;code&gt;strong&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  CSS:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="nt"&gt;strong&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzcpyq9zuj6apzbr23n4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzcpyq9zuj6apzbr23n4.png" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was all about &lt;code&gt;inherit&lt;/code&gt;, but what if we want an inheritable property not to inherit the parent's value? &lt;/p&gt;

&lt;p&gt;Such as color, if we set color of parent box to red then all of it's children will have color red.&lt;br&gt;
But what if we don't want that?&lt;/p&gt;

&lt;p&gt;In that case we call &lt;code&gt;initial&lt;/code&gt; to help us.&lt;br&gt;
initial is used to set the value to the default one.&lt;/p&gt;

&lt;p&gt;So, if we look at this example code:&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;div&amp;gt;&lt;/span&gt;
  Hello world in div.
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello world in paragraph.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&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="nt"&gt;div&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;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calibri&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;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nt"&gt;p&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;initial&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweq7kz3oda198zne6rsy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweq7kz3oda198zne6rsy.png" alt="outptu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The color was supposed to be red but as we set that to initial value which is black, we were able to set the color of text to its initial value.&lt;/p&gt;

&lt;p&gt;But what if we don't know if in a browser a particular property is inheritable or not? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/lKXEBR8m1jWso/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/lKXEBR8m1jWso/giphy.gif" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, no worries, we have a solution or that too.&lt;/p&gt;

&lt;p&gt;We can use &lt;code&gt;unset&lt;/code&gt; keyword in that case. If the property is inheritable &lt;code&gt;unset&lt;/code&gt; keyword is set to &lt;code&gt;inherit&lt;/code&gt; and if its not, then &lt;code&gt;unset&lt;/code&gt; is set to &lt;code&gt;initial&lt;/code&gt;.&lt;/p&gt;

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

</description>
    </item>
    <item>
      <title>Managing Protocols with NodeJS
</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Tue, 15 Jun 2021 13:52:06 +0000</pubDate>
      <link>https://dev.to/sakshamak/managing-protocols-with-nodejs-22b3</link>
      <guid>https://dev.to/sakshamak/managing-protocols-with-nodejs-22b3</guid>
      <description>&lt;p&gt;So, I was reading about decentralized apps with a peer-to-peer protocol and while searching deep inside Dapps and P2PP, it struck in my mind, "How can we manage to control the type of protocol we use in our web apps?", so I searched about it and decided to write about it.&lt;/p&gt;

&lt;p&gt;There are different protocols on which different things run such as TCP, IP, UDP, P2P, FTP, ICMP, etc. And each one of them has a different purpose. But when we create our backend using MERN how do we control these protocols? &lt;/p&gt;

&lt;p&gt;For this purpose, we use NodeJS. We can install different packages using NPM to set our protocols and here I will be showing how to set TCP and UDP protocols.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are TCP and UDP protocols?
&lt;/h2&gt;

&lt;p&gt;Transmission Control Protocol (TCP) is used to make reliable network communications. Let's say you are transferring money to another place, when you click on send button there comes a message saying the transaction is successful. Hence, in TCP a message is received everytime a request is sent making sure it reached the destination&lt;/p&gt;

&lt;p&gt;Whereas a User Datagram Protocol (UDP) is used to make unreliable network communications. This protocol is used in real-time communications like video/voice calls, real-time gaming, etc. Here we don't need to make sure if the message reached the destination or not. &lt;/p&gt;

&lt;p&gt;Let's take an example here if you are talking on a video call and you said "I am going to the market" and the message reached was "I going to the market" and the word "am" is dropped then we don't want our app to send us a message that the word "am" is not delivered. So in these cases, UDP is used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up TCP connection
&lt;/h2&gt;

&lt;p&gt;Following is the code to set up a TCP connection.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wXOBtuOf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759051086/499bdsn18.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wXOBtuOf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759051086/499bdsn18.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Press F5 and select nodeJS as debugger and this will be shown in the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YaRdLRQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759070443/_WTiiq3i0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YaRdLRQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759070443/_WTiiq3i0.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have to enable telnet first, go to control panel and search for "Turn on and off windows features" and enable telnet and write the following command in command prompt and press enter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J1SfPvZD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759134816/1wY-t1BEH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J1SfPvZD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759134816/1wY-t1BEH.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should appear on your command prompt screen : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PFWa2sf6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759161556/ebDQZOX02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PFWa2sf6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759161556/ebDQZOX02.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now as this is a TCP connection when you make a request you receive the message back, as we can see in the following image when I typed "hi" the same message was printed on my console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lfCvA1NY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759184306/lTJk7tZ_S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lfCvA1NY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623759184306/lTJk7tZ_S.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up UDP connection
&lt;/h2&gt;

&lt;p&gt;Following is the code to set up a UDP connection and add a stopper to line 5.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bBibk2TI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760840332/j6smAb6bg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bBibk2TI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760840332/j6smAb6bg.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the debugger as before but this time you must install Netcat in your machine.&lt;/p&gt;

&lt;p&gt;You can download Netcat from &lt;a href="https://eternallybored.org/misc/netcat/"&gt;here&lt;/a&gt; but you need to turn off your windows defender first, but don't worry it's safe and I downloaded it from the same site.&lt;/p&gt;

&lt;p&gt;After downloading, add its path to the command prompt and write this command in the command prompt, and press Enter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LaY92qtX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760896623/V1B7BgUWh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LaY92qtX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760896623/V1B7BgUWh.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hover on the word "msg" and you will see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BxG-rXTM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760946434/uSkgXvF07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BxG-rXTM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1623760946434/uSkgXvF07.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here as you can see we didn't receive any message and the command closed itself after sending the message unlike TCP and as we hover on "msg" we can see those numbers, those are the ASCII characters of &lt;em&gt;h&lt;/em&gt;, &lt;em&gt;i&lt;/em&gt;, &lt;em&gt;space&lt;/em&gt;, &lt;em&gt;carriage return&lt;/em&gt;, and &lt;em&gt;line feed&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And this is my friends, how we set up our protocols using NodeJS. I hope you found it useful. Thank you very much for giving me your precious time, I hope you learned something new today 😀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Model View Controller: What is it?</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Fri, 14 May 2021 15:00:11 +0000</pubDate>
      <link>https://dev.to/sakshamak/model-view-controller-what-is-it-1p57</link>
      <guid>https://dev.to/sakshamak/model-view-controller-what-is-it-1p57</guid>
      <description>&lt;p&gt;Hey there, I am using dev.to.&lt;/p&gt;

&lt;p&gt;And this time it is about MVC architectural design pattern. I saw a lot of videos and pages to understand what is model view controller or MVC as I was not satisfied with just a single source so I will try my best that this won't happen to you guys.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is MVC?
&lt;/h1&gt;

&lt;p&gt;MVC is actually an architectural pattern and if you don't know what is an architectural pattern you can go through &lt;a href="https://thefearofblogs.hashnode.dev/software-architecture-architectural-patterns"&gt;my blog&lt;/a&gt;. But for the sake of this article, an architectural pattern is a type of structure on which an application/software is built, and MVC also a structure and it is not language-specific (as you must have or will see in different sites that show it's working in ASP.NET). There are a lot of frameworks that use the MVC concept such as Ruby on Rails, ExpressJS, BackboneJS, AngularJS, Django, and Flask.&lt;/p&gt;

&lt;p&gt;You can compare an MVC model with a real-life example of weddings. Suppose you are at a wedding and you want to eat a particular dish that is available there, so you ask a waiter to get you that dish and the waiter go to the chef and asks for that particular dish and the chef creates the dish from raw materials and give it back to the waiter and the waiter serves the dish to you. &lt;/p&gt;

&lt;p&gt;Now there are three main characters in this story: you, the waiter, and the chef which is also the three main components of the MVC pattern.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zoCfLAK9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1620450647914/PRsGmi-Gw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zoCfLAK9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1620450647914/PRsGmi-Gw.png" alt="Group 10 (2).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  MVC Components
&lt;/h2&gt;

&lt;p&gt;MVC consists of MODEL, VIEW, and CONTROLLER (as the name suggests). Now I will not go in a sequence as mentioned above but rather would like to follow the story. So, the role played by you is &lt;strong&gt;View&lt;/strong&gt; here, the waiter is the &lt;strong&gt;Controller&lt;/strong&gt;, and the chef is the &lt;strong&gt;Model&lt;/strong&gt; with all the raw ingredients is the &lt;em&gt;Data&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  View
&lt;/h3&gt;

&lt;p&gt;The view is everything that is displayed on the screen, the UI part is the view. The controller takes the responses from the user through the view. View also displays the output when the requested data is brought to it by the controller. It is the part of MVC that interacts with the user.&lt;/p&gt;

&lt;h3&gt;
  
  
  Controller
&lt;/h3&gt;

&lt;p&gt;The controller is the waiter which means that it takes the order (requests) from the user through view and takes it to the chef (Model) and then takes the prepared food (data) back to the view and view presents it to the user. The controller also processes the requests like DELETE, PUT, GET, POST and takes appropriate decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Model
&lt;/h3&gt;

&lt;p&gt;Finally, at last, the chef is at work. The &lt;strong&gt;model&lt;/strong&gt; is simply the brain of the application. It is responsible for getting and manipulating the data. It takes the data from the database or a simple JSON file. It can perform operations like SELECT, INSERT, UPDATE, DELETE. &lt;/p&gt;

&lt;p&gt;Model doesn't really care about how to present the data it just takes the data and gives it to the controller and the view beautifies it (not exactly what a chef does though haha). In some cases, the model directly creates contacts with the view without connecting to the controller which also says that MVC can be represented in a  triangular pattern.&lt;/p&gt;

&lt;p&gt;So, ending this blog with a summary, the &lt;strong&gt;View interacts with the user&lt;/strong&gt;, the user clicks on a button, the button makes a request, &lt;strong&gt;the controller takes the request to the model&lt;/strong&gt;, &lt;strong&gt;model fetches the data&lt;/strong&gt; from the database or a JSON file, &lt;strong&gt;gives the raw data back to the controller&lt;/strong&gt;, the &lt;strong&gt;controller takes the data to the view&lt;/strong&gt;, and &lt;strong&gt;the view represents the data in a beautiful manner&lt;/strong&gt; to the user.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Software Architecture: Architectural patterns</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Thu, 29 Apr 2021 16:16:59 +0000</pubDate>
      <link>https://dev.to/sakshamak/software-architecture-architectural-patterns-36b</link>
      <guid>https://dev.to/sakshamak/software-architecture-architectural-patterns-36b</guid>
      <description>&lt;p&gt;Okay so as being a react developer that has always focused on coding while not giving much preference to the theory part, I decided to learn some stuff which led me here to &lt;strong&gt;Architectural Patterns&lt;/strong&gt;, so I decided to write something on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Software Architecture?
&lt;/h2&gt;

&lt;p&gt;Creating software doesn't always mean just code code and code and your software is ready (well that may work for small apps but doesn't applies to large-scale software). You have to think about various stages to create software which are: &lt;/p&gt;

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

&lt;p&gt;*&lt;em&gt;Software architecture is how the components that define the software are organized and assembled, how they communicate with each other, and also the constraints or rules with which the whole system will run.&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's have a closer look at the definition. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The organizing and assembling of the components is what architectural patterns do.&lt;/li&gt;
&lt;li&gt;The communication part is done through the API's.&lt;/li&gt;
&lt;li&gt;The rules or constraints are scalability, resilience, adaptability, resolve, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And all these points together form the architecture of the software.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is architecture?
&lt;/h3&gt;

&lt;p&gt;Architecture is a set of software structures, and a structure is simply a set of elements held together by a relation. There are three types of architectural structures, which play an important role in designing, documentation, and analysis of architectures.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First plays a role in dividing the units to work on the database, business rules, and user interface.&lt;/li&gt;
&lt;li&gt;Second is dynamic and carries out the system functions and runtime elements.&lt;/li&gt;
&lt;li&gt;Third kind connects the software structure to organization, development, and installation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Architecture specifically omits certain information about elements that are not useful for reasoning about the system. Architecture is an abstraction that focuses on certain information. Modern softwares are divided into two parts, public and private and architecture focuses on the public part as the private section deals with the internal implementations and hence not architectural.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Patterns
&lt;/h2&gt;

&lt;p&gt;In some cases, architectural elements are composed in such a way that it solves a particular problem and those compositions have been found useful in future and have been used over time to time in different situations, these compositions are known as architectural patterns.&lt;/p&gt;

&lt;p&gt;Architectural patterns are just like templates (not exactly a template) or wireframes which makes it easy to build an application. There are different types of patterns present and I will be discussing a few of them here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layered Pattern
&lt;/h3&gt;

&lt;p&gt;Layered pattern also known as n-tier pattern, as the name suggests, consists of different layers. Generally, we take four layers in this pattern which are presentation, business, persistence, and database. The most common example of this pattern is the OSI model and the web architecture model.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feo7nvj6hfv6k7nmvqy4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feo7nvj6hfv6k7nmvqy4z.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And this is how a layered pattern looks like with arrows showing the default behavior of this pattern:&lt;/p&gt;

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

&lt;p&gt;A layer is an independent piece of the module in which several components are interconnected with each other. If there is any problem in one layer then we can fix it within the layer without affecting the other layers.&lt;/p&gt;

&lt;p&gt;Each layer of the pattern has a specific responsibility in the application. The presentation layer does all the User Interface related stuff and defines how the application will look. The business layer takes the business decisions such as an email is sent to the user if this action is done. The persistence layer contains all the code definitions, main programs, and basic functions of the applications. The database layer contains the databases.&lt;/p&gt;

&lt;p&gt;One of the great features of this pattern is the &lt;strong&gt;separation of concern&lt;/strong&gt; within the layers i.e. each layer focuses on doing its task and nothing else like if a layer is managing the databases then it is none of its business what other layers are doing or what to do other than handling databases, it only focuses on managing the databases.&lt;/p&gt;

&lt;p&gt;Now, as I told earlier that the default behavior of this pattern is moving down the layers step-wise. This is only followed when the layers are &lt;strong&gt;closed&lt;/strong&gt;. A layer being in a state of *&lt;em&gt;close *&lt;/em&gt; means that as the request moves from layer to layer, the request must pass through the layer right next to the previous one and not skipping any layer.&lt;/p&gt;

&lt;p&gt;Another state of layers is &lt;strong&gt;open&lt;/strong&gt; (yes you have guessed right). It is not always necessary that this pattern should always go for 4 layer architecture, we can have multiple layers in this system (as the name n-tier suggests). So let's suppose we take a new layer in between the business layer and persistence layer and name it Service Layer and this layer is open. Then when a request will pass through the business layer &lt;strong&gt;AND ** if it's of any use to the service layer **ONLY THEN&lt;/strong&gt; it will be sent into that layer otherwise the request will jump directly to the persistence layer.&lt;/p&gt;

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

&lt;p&gt;Using a combination of both open and closed layers sometimes becomes very messy for the programmer so it should be used wisely. &lt;/p&gt;

&lt;h3&gt;
  
  
  Client-Server Pattern
&lt;/h3&gt;

&lt;p&gt;Before going to this pattern first I'm going to discuss what is a client and a server.&lt;/p&gt;

&lt;h4&gt;
  
  
  Client
&lt;/h4&gt;

&lt;p&gt;A client can be a machine or program. Machines can be a mobile, computer, laptop, etc and a client program is a program that allows users to make a request for example web browsers, editing software, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Servers
&lt;/h4&gt;

&lt;p&gt;As we all must have heard that a server is a high-performing machine but actually it is a program known as a server program that RUNS on a high-performing machine as it has to handle a lot of requests at once and also they provide the functionality to the clients.&lt;/p&gt;

&lt;p&gt;And as I said a server can serve multiple clients at once and a single machine can have multiple servers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Now as we have discussed client and servers we can now move on to the client-server pattern which can now be explained in just a few lines.&lt;/p&gt;

&lt;p&gt;A client-server pattern is a centralized way to get the clients to communicate with servers on the web where the client makes the request and the server responds to it.&lt;/p&gt;

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

&lt;p&gt;This is just one way to surf the web in a centralized manner and similarly, there is a decentralized manner too which is known as &lt;strong&gt;peer-to-peer Model&lt;/strong&gt; where a machine can work both as a client and a server and no one has a specific role both can send requests and respond to it.&lt;/p&gt;

&lt;p&gt;The most common example of this model is bit torrent and skype.&lt;/p&gt;

&lt;p&gt;And now as this blog is getting really long and must be boring (haha I really appreciate it if you are still reading) I should end it here now. Thank you for giving me your valuable time.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Compiler Design</title>
      <dc:creator>Saksham</dc:creator>
      <pubDate>Sun, 25 Apr 2021 16:52:03 +0000</pubDate>
      <link>https://dev.to/sakshamak/understanding-compiler-design-lcd</link>
      <guid>https://dev.to/sakshamak/understanding-compiler-design-lcd</guid>
      <description>&lt;p&gt;Every one of us has used a compiler once in our programming journey or must have read about it. Ever thought about how a compiler works?&lt;/p&gt;

&lt;p&gt;Today I will be discussing the design structure of a compiler.&lt;/p&gt;

&lt;p&gt;A code basically has to pass through a different number of levels to get itself converted from high-level language to assembly language, and these are all hidden in a compiler.&lt;/p&gt;

&lt;p&gt;Here is a basic diagram of a compiler :&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LRYaZRRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqvf8lq9seufgast5sei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LRYaZRRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tqvf8lq9seufgast5sei.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see a compiler consists of a total of 6 different levels, where the first four are grouped together and are called frontend, and the bottom two are grouped and called backend.&lt;/p&gt;

&lt;p&gt;The frontend part checks for any kind of errors in the code like syntax, grammar, or lexical errors whereas the backend part simplifies and generates the program by grouping the code snippets.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Internal Processes in brief.
&lt;/h2&gt;

&lt;p&gt;When we write a code in any language and compiles it, the first thing a compiler does is to check for any kind of errors in the code for which it passes through the frontend or analytic part.&lt;/p&gt;
&lt;h3&gt;
  
  
  Lexical Analysis
&lt;/h3&gt;

&lt;p&gt;When a high-level language code is passed through lexical analysis it generates a stream of tokens, but before that, we should talk about preprocessors, the task of a preprocessor is to filter out a stream of characters by removing the header files and then passing it to the lexical analysis. (A stream of characters is nothing but just the keyboard characters we type in the code: int a = 23; or printf(" Hello World! ");)&lt;/p&gt;

&lt;p&gt;but what is a token?&lt;/p&gt;

&lt;p&gt;let's take a small code&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;a = 10;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Here a, =, 10, ; are all tokens. So total number of tokens here is 5.&lt;/p&gt;

&lt;p&gt;So basically a token is the important part of a code. Why I said important? Because comments and characters such as white space or newline or tabs are not considered as tokens. And then these tokens are passed in the symbol table. The role of the symbol table is to get the record of the properties of tokens or variables such as type, size, scope, etc. The symbol table is connected to all the stages in the compiler as we can see in the diagram for future use.&lt;/p&gt;

&lt;p&gt;After converting all the code to tokens, it is sent to the syntax analysis department.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax Analysis
&lt;/h3&gt;

&lt;p&gt;When the code comes here, it is checked that if a code is syntactically correct or not. A parser is used here and the output that comes is called a parse tree as it comes in the form of a tree as shown:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--epz3O9Cc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmctp0qy902ieunot2sq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--epz3O9Cc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmctp0qy902ieunot2sq.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
If there is a syntax error then an error is produced at this stage.&lt;/p&gt;
&lt;h3&gt;
  
  
  Semantic Analysis
&lt;/h3&gt;

&lt;p&gt;Here the analyzer checks the parse tree and finds semantic errors. Note that this part doesn't care about the syntax but checks whether the value of the variable is as per the type declared or the limit of a particular data type is not exceeded or whether variables are declared properly or not&lt;/p&gt;
&lt;h3&gt;
  
  
  Intermediate Code Generator
&lt;/h3&gt;

&lt;p&gt;This part is the middle man between frontend and backend, it generates a code that can be understood by the backend i.e. a machine-independent code (independent of OS). It creates a 3-address code which means that the code is divided into 3 variable statement which means that maximum of 3 addresses can be there in one statement if there is 4 or 5 then it is divided into 2 3 lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = b + c * d;
// this is converted as
x = c * d;
a = b + x;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This 3-addressed code is sent to the next level i.e. optimization of code&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Optimisation
&lt;/h3&gt;

&lt;p&gt;From here the backend part begins and code optimization is the first stage of the backend. As the name suggests, this part optimizes the code. There is not much to say about it as you all know what is optimisation. + sign is much easier to process than * hence a code like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 4 * y 
// can be converted to 
x = y + y + y + y 
// or 
z = y + y; 
x = z + z;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code generation
&lt;/h3&gt;

&lt;p&gt;Here the code generator takes an optimized version of the intermediate code and links it with the target machine language. It translates the intermediate code into a sequence of re-locatable machine code. The machine code generated works the same way the intermediate code would do.&lt;/p&gt;

&lt;p&gt;Like the Symbol Table, there is an error handler that is linked to all the phases which is responsible for handling the errors detected by the frontend&lt;/p&gt;

&lt;p&gt;And at last, the code is converted to the assembly code or machine code.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
