<?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: Kani Gureye</title>
    <description>The latest articles on DEV Community by Kani Gureye (@kurgeye).</description>
    <link>https://dev.to/kurgeye</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%2F399589%2F20e308bd-784a-4db9-9c09-ddb566d5916c.jpg</url>
      <title>DEV Community: Kani Gureye</title>
      <link>https://dev.to/kurgeye</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kurgeye"/>
    <language>en</language>
    <item>
      <title>Call Stack - A simplified intro</title>
      <dc:creator>Kani Gureye</dc:creator>
      <pubDate>Tue, 28 Feb 2023 21:04:40 +0000</pubDate>
      <link>https://dev.to/kurgeye/call-stack-a-simplified-intro-c74</link>
      <guid>https://dev.to/kurgeye/call-stack-a-simplified-intro-c74</guid>
      <description>&lt;h2&gt;
  
  
  What is it?
&lt;/h2&gt;

&lt;p&gt;The call stack is a data structure that records the execution of functions in JavaScript. Whenever a function is called, it is added to the top of the call stack, and when a function completes its execution, it is removed from the stack. The call stack follows a last-in, first-out (LIFO) principle, meaning that the last function added to the stack is the first function to be executed.&lt;/p&gt;

&lt;p&gt;In order to better manage this, the JS engine uses the call stack to handle execution contexts. They are the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main ones&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global execution context - for code that’s in the global context&lt;/li&gt;
&lt;li&gt;Function execution contexts - for code that’s inside a function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Occasionally&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eval execution context - for when we use the eval method (creates its own execution context)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you execute a script, the JavaScript engine creates a global execution context and pushes it on top of the call stack.&lt;/p&gt;

&lt;p&gt;Whenever a function is called, the JavaScript engine creates a function execution context for the function, pushes it on top of the call stack, and starts executing the function.&lt;/p&gt;

&lt;p&gt;If a function calls another function, the JavaScript engine creates a new function execution context for the function being called and pushes it on top of the call stack.&lt;/p&gt;

&lt;p&gt;When the current function completes, the JavaScript engine pops it off of the call stack and resumes the execution where it left off.The script will stop when the call stack is empty.&lt;/p&gt;

&lt;p&gt;In order to better understand this, consider the following example code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function one() {
  console.log('one');
}

function two() {
  console.log('two');
  one();
}

function three() {
  console.log('three');
  two();
}

three();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the three function is called, which then calls the two function, which in turn calls the one function. The call stack will record the execution of these functions in the following order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. three
2. two
3. one

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

&lt;/div&gt;



&lt;p&gt;Stack empties in following order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. one
2. two
3. three

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

&lt;/div&gt;



&lt;p&gt;When the one function completes its execution, it is removed from the stack, and the same goes for the two function. Finally, when the three function completes its execution, it is removed from the stack, and the stack becomes empty again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The JS engine uses a call stack to manage execution contexts.&lt;/li&gt;
&lt;li&gt;The call stack uses the stack data structure that works based on the LIFO (last-in-first-out) principle. It's similar to array and uses methods pop and push.&lt;/li&gt;
&lt;li&gt;Only one function is removed at a time because JS is single-threaded. It can only handle one task at a time. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Where can we learn more?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=8aGhZQkoFbQ&amp;amp;ab_channel=JSConf"&gt;Philip Roberts - JSConf EU&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.chrome.com/docs/devtools/#stepping"&gt;Chrome DevTools&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading and I would love to connect on &lt;a href="https://twitter.com/kurgeye"&gt;Twitter&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>PX vs REM: What should we be using?</title>
      <dc:creator>Kani Gureye</dc:creator>
      <pubDate>Sat, 31 Dec 2022 16:09:40 +0000</pubDate>
      <link>https://dev.to/kurgeye/px-vs-rem-what-should-we-be-using-5cki</link>
      <guid>https://dev.to/kurgeye/px-vs-rem-what-should-we-be-using-5cki</guid>
      <description>&lt;h1&gt;
  
  
  What is a PX?
&lt;/h1&gt;

&lt;p&gt;A pixel is a unit of measurement and a commonly used CSS unit. It is an absolute unit, meaning whatever value is assigned is fixed, regardless of the user setting one might have. Let's consider the following example:&lt;/p&gt;


&lt;pre data-lang="css"&gt;html {&lt;br&gt;
  font-size: 18px;&lt;br&gt;
}&lt;/pre&gt;

&lt;p&gt;Here, we've changed the base-size to 18px by targeting the html tag. Most browsers will have a default base-size of 16px, unless you change that base by like we did above. It is this size that will become the basis for what relative units will calculate off of.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a REM?
&lt;/h1&gt;

&lt;p&gt;REM is an acronym for root em and a unit that dictates the element's font size relative to the size of the root element. Due to our example above, let's continue with the assumption that our base size is still 18px. &lt;/p&gt;

&lt;p&gt;If the base size(root element) is 18px, an element with the font-size value of 1rem will always the base size. Therefore, rem units are useful for scaling CSS elements in relation to the size of the root element.&lt;/p&gt;

&lt;p&gt;To use the "rem" unit, you simply specify a value followed by the unit name: &lt;/p&gt;


&lt;pre data-lang="css"&gt;html {&lt;br&gt;
  font-size: 1rem;&lt;br&gt;
}&lt;br&gt;
&lt;/pre&gt;

&lt;h1&gt;
  
  
  Which should we use?
&lt;/h1&gt;

&lt;p&gt;So to recap, one is an absolute unit(px) whereas the other is a relative unit, that will scale off of the base size of the browser.&lt;/p&gt;

&lt;p&gt;So for defining font-sizes, in my opinion, you should mostly use rems as they are relative and it is a best practice in terms of accessibility.&lt;/p&gt;

&lt;p&gt;As for the rest, the view is more nuanced so for properties like padding and border it's still down to preference. This is due to these two properties not being directly linked to accessibility like font-size is.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;There's definitely a place for using pixels, and there will be edge cases where pixels might prove to be the better option. An example could be if a user is on a small screen and the use of rems could make the user experience worse due to the limited space. &lt;/p&gt;

&lt;p&gt;If you're dealing with media queries or font-sizes, I'd go with rems. It's also easier to for the most part stick with one of them, with the occasional exception.&lt;/p&gt;

&lt;p&gt;Another thing is that it makes sense to me that things should scale up or down at the same rate if there's a need for it. I'm therefore, personally, of the opinion that you should mostly use rems. There are however more factors at play than what is covered here. You can read more about it in this great article - &lt;a href="https://zellwk.com/blog/media-query-units/"&gt;https://zellwk.com/blog/media-query-units/&lt;/a&gt; by &lt;em&gt;&lt;strong&gt;Zell Liew&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Follow for more content and a Happy New Year to you and your loved ones!&lt;/p&gt;

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