<?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: Sam</title>
    <description>The latest articles on DEV Community by Sam (@sam0905).</description>
    <link>https://dev.to/sam0905</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%2F982891%2Fd8c3570a-bb0c-44b5-9359-114ef0b87728.jpeg</url>
      <title>DEV Community: Sam</title>
      <link>https://dev.to/sam0905</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sam0905"/>
    <language>en</language>
    <item>
      <title>How JavaScript works?</title>
      <dc:creator>Sam</dc:creator>
      <pubDate>Sat, 03 Dec 2022 10:54:05 +0000</pubDate>
      <link>https://dev.to/sam0905/how-javascript-works-3djm</link>
      <guid>https://dev.to/sam0905/how-javascript-works-3djm</guid>
      <description>&lt;p&gt;Let's Understand JS! There are few around the globe who loves JS like anything and the there is another part of the world who hates JS to the core. Hence on this blog, I will try to explain the behind the scenes on How JS works to make the latter part also fall in love in JS✌️😎&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;JS is a single threaded and synchronous language which means it can handle one task at a time&lt;/strong&gt;.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What the heck is execution context in JS?
&lt;/h3&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%2F6x94ckvwmgliaifbeq0s.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%2F6x94ckvwmgliaifbeq0s.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  You can think of execution context(EC) as a container having two parts. The first part is named as &lt;strong&gt;Memory&lt;/strong&gt; and also called as &lt;em&gt;Variable environment&lt;/em&gt;  and the second part is named &lt;strong&gt;code&lt;/strong&gt; also called as &lt;em&gt;Thread of execution&lt;/em&gt; .
&lt;/h4&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%2Fx96h2tnq1jg3ot4vn5yw.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%2Fx96h2tnq1jg3ot4vn5yw.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first being memory allocation phase, during this phase, JS skims the whole code and assigns memory to each and every variable and function; For variables during this phase, JS assigns a special placeholder called undefined and a whole copy of function code for the function.&lt;/p&gt;

&lt;p&gt;Functions in JavaScript, when you compare with other programming languages, work differently.&lt;/p&gt;

&lt;p&gt;Let's take an simple example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var n = 2;

function square(num) {
 var ans = num * num;
 return ans;
}

var square2 = square(n);
var square4 = square(4);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example has an function which takes an argument of type number and returns the square of the number.&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%2F3hfh8xmte66di1bcdy9g.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%2F3hfh8xmte66di1bcdy9g.gif" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The second phase is the execution phase, during which JS executes the code line by line and assigns the actual value to the variables. The functions are considered as first-class citizens in JS, they behave very differently from any other language. That being the case when JS sees a function invocation it creates a brand new execution context inside the global execution context and executes the function in the same way with this two-phase process.&lt;/p&gt;

&lt;h4&gt;
  
  
  Are you wondering how JS manages its job smoothly?
&lt;/h4&gt;

&lt;p&gt;All these tasks of creating and deleting the EC once the work is done are managed in JS by a stack called the call stack. Call stack has also other names such as,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Execution Context Stack&lt;/li&gt;
&lt;li&gt;Program Stack&lt;/li&gt;
&lt;li&gt;Control Stack&lt;/li&gt;
&lt;li&gt;Machine Stack&lt;/li&gt;
&lt;li&gt;Runtime Stack&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  In this article, we have understood how JS works and the execution context briefly. I hope this blog is helpful, please feel free to share and comment below.
&lt;/h5&gt;

</description>
    </item>
    <item>
      <title>Inline vs. block-level elements</title>
      <dc:creator>Sam</dc:creator>
      <pubDate>Fri, 02 Dec 2022 08:38:48 +0000</pubDate>
      <link>https://dev.to/sam0905/inline-vs-block-level-elements-22ag</link>
      <guid>https://dev.to/sam0905/inline-vs-block-level-elements-22ag</guid>
      <description>&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%2F3xmcur4ii44b0up4excx.jpg" 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%2F3xmcur4ii44b0up4excx.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many definitions about this topic. And as a developer it is a need to know more in this topic! so, let's see how important and useful to us!&lt;/p&gt;

&lt;p&gt;HTML (HyperText Markup Language) elements historically were categorized as either "block-level" elements or "inline-level" elements. First let see about inline elements,&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Inline elements:&lt;/strong&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  An &lt;strong&gt;inline element&lt;/strong&gt; does not start on a new line. An inline element only takes up as much width as necessary.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  This is a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; element inside a paragraph.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;p&amp;gt;This is an inline span &amp;lt;span style="border: 1px solid black"&amp;gt;Hello World&amp;lt;/span&amp;gt; element inside a paragraph.&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;The SPAN element is an inline element, and will not start on a new line and only takes up as much width as necessary.&amp;lt;/p&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Here is a list of common inline elements
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;br&gt;
 &amp;lt;img&amp;gt;&lt;br&gt;
 &amp;lt;small&amp;gt;&lt;br&gt;
 &amp;lt;script&amp;gt;&lt;br&gt;
 &amp;lt;strong&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I have stacked up multiple inline elements together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="#"&amp;gt;Link&amp;lt;/a&amp;gt;
&amp;lt;img src="" /&amp;gt;
&amp;lt;small&amp;gt;The text gets become smaller&amp;lt;/small&amp;gt;
&amp;lt;script&amp;gt;src=""&amp;lt;/script&amp;gt;
&amp;lt;strong&amp;gt;React&amp;lt;/strong&amp;gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Block-level elements:&lt;/strong&gt;
&lt;/h1&gt;

&lt;h6&gt;
  
  
  A  &lt;strong&gt;Block-level&lt;/strong&gt; &lt;strong&gt;element&lt;/strong&gt; always starts on a new line, and the browsers automatically add some space (a margin) before and after the element.
&lt;/h6&gt;

&lt;h5&gt;
  
  
  A block-level element always takes up the full width available .Two commonly used block elements are: &lt;code&gt;&amp;lt;p&amp;gt; and &amp;lt;div&amp;gt;&lt;/code&gt;
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;p style="border: 1px solid black"&amp;gt;Hello World&amp;lt;/p&amp;gt;
&amp;lt;div style="border: 1px solid black"&amp;gt;Hello World&amp;lt;/div&amp;gt;

&amp;lt;p&amp;gt;The P and the DIV elements are both block elements, and they will always start on a new line and take up the full width available (stretches out to the left and right as far as it can).&amp;lt;/p&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;h6&gt;
  
  
  Here is a list of common Block elements. I have attached some common block elements together.
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1 - h4&amp;gt;,&amp;lt;header&amp;gt; and &amp;lt;section&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;This is heading 1&amp;lt;/h1&amp;gt;
&amp;lt;h2&amp;gt;This is heading 2&amp;lt;/h2&amp;gt;
&amp;lt;h3&amp;gt;This is heading 3&amp;lt;/h3&amp;gt;
&amp;lt;h4&amp;gt;This is heading 4&amp;lt;/h4&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;header&amp;gt;
    &amp;lt;h1&amp;gt;A heading here&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;Posted by John &amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Some additional information here&amp;lt;/p&amp;gt;
&amp;lt;/header&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section&amp;gt;
&amp;lt;h2&amp;gt;WWF's Symbol&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;The Panda has become the symbol of WWF. The well-known panda logo of WWF originated from a panda named Chi Chi that was transferred from the Beijing Zoo to the London Zoo in the same year of the establishment of WWF.&amp;lt;/p&amp;gt;
&amp;lt;/section&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here are some useful references.&lt;/p&gt;

&lt;p&gt;Full list of block level elements:[&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Full list of inline level elements: including inline-block elements:(&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#Elements" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#Elements&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

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