<?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: Shreya Joshi</title>
    <description>The latest articles on DEV Community by Shreya Joshi (@codebyshreya).</description>
    <link>https://dev.to/codebyshreya</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%2F1419088%2F3106a8dc-2dd5-4eaa-a67e-3617f454538e.png</url>
      <title>DEV Community: Shreya Joshi</title>
      <link>https://dev.to/codebyshreya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codebyshreya"/>
    <language>en</language>
    <item>
      <title>Every Wonder What is Hoisting? let's understand JavaScript's Built-in Behaviour</title>
      <dc:creator>Shreya Joshi</dc:creator>
      <pubDate>Sat, 11 May 2024 13:59:14 +0000</pubDate>
      <link>https://dev.to/codebyshreya/every-wonder-what-is-hoisting-3ch</link>
      <guid>https://dev.to/codebyshreya/every-wonder-what-is-hoisting-3ch</guid>
      <description>&lt;p&gt;Ever wonder what's the deal with hoisting in JavaScript? 🤯 Don't fret! This article is here to help you get a good grasp of the two terms.&lt;/p&gt;

&lt;p&gt;So relax, grab your favorite cup of coffee ☕️, and let’s get started with Hoisting. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prerequisite: Execution Context&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we dive into the fascinating world of hoisting, let's first understand the basics of execution context in JavaScript.&lt;/p&gt;

&lt;p&gt;With every code execution, JavaScript creates an execution context. As part of this process, JavaScript creates a virtual object for each variable and initializes them with a value of &lt;code&gt;undefined&lt;/code&gt;. This ensures that even before code execution begins, variables have a designated space in memory. So, if we attempt to access a variable before it's initialized, &lt;strong&gt;it will return &lt;code&gt;undefined&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is Hosting?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the MDN document it shows like this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript &lt;strong&gt;Hoisting&lt;/strong&gt; refers to the process whereby the interpreter appears to move the &lt;em&gt;declaration&lt;/em&gt; of functions, variables, classes, or imports to the top of their scope, prior to execution of the code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In JavaScript, hoisting refers to &lt;strong&gt;the built-in behavior of the language through which declarations of functions, variables, and classes are moved to the top of their scope – all before code execution&lt;/strong&gt;. In turn, this allows us to use functions, variables, and classes before they are declared.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;yup i know definition wont help much, Let's unpack this with some examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let consider the following -
&lt;/h2&gt;

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

&lt;p&gt;In the above example everything seems to work as expected. This is a normal function code and output is also we get is obvious this is how code has to work but lets consider the below example.&lt;/p&gt;

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

&lt;p&gt;Here, we're calling variables and functions before they're even initialized. Surprisingly, JavaScript doesn't throw an error as many other programming languages would. Instead, it treats this behaviour as perfectly normal - &lt;br&gt;
&lt;strong&gt;this is hoisting in action!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let us see how it works separately for variable and function.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hoisting in Variable
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;VAR&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Consider this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcg8686yjgxs6dbyq0c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhcg8686yjgxs6dbyq0c3.png" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;br&gt;
Surprisingly, this outputs &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt; instead of causing chaos. How? Well, during compilation, JavaScript sets aside memory for &lt;strong&gt;&lt;code&gt;name&lt;/code&gt;&lt;/strong&gt; and assigns it the value &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt; until it's properly initialized. It's like reserving a seat at the table before the guest arrives! 🪑&lt;/p&gt;

&lt;p&gt;When JavaScript code is executed, it goes through a process known as the execution phase. During this phase, JavaScript creates what's called an execution context for each code execution. Think of it as setting the stage for the code to run smoothly.&lt;/p&gt;

&lt;p&gt;As part of setting up this execution context, JavaScript allocates memory for variables but doesn't assign them any values yet. Instead, it initializes them with a special value called &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;. This essentially reserves a spot in memory for each variable, marking it as empty or uninitialized.&lt;/p&gt;

&lt;p&gt;Now, if we attempt to access or reference a variable before it's been assigned a value during this initialization phase, JavaScript returns the default value for uninitialized variables, which is &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;. This behavior ensures that the code doesn't crash or throw errors when trying to access variables that haven't been explicitly defined yet.&lt;/p&gt;

&lt;p&gt;So, in the context of hoisting, when we access a variable before it's been initialized, JavaScript doesn't throw an error. Instead, it returns &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;, indicating that the variable exists but hasn't been assigned a value yet. This behaviour is fundamental to how JavaScript handles variable declarations and hoisting.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let and Const&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Like Var let and const are also hoisted but there is some difference, consider the following example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feuj569mu46a8032o89q2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feuj569mu46a8032o89q2.png" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;br&gt;
In the above code the output is Reference:…” &lt;br&gt;
but why var give undefined and let and const give reference error.&lt;/p&gt;

&lt;p&gt;Unlike &lt;strong&gt;&lt;code&gt;var&lt;/code&gt;&lt;/strong&gt;, they throw a reference error when accessed before declaration. This is due to the concept of the Temporal Dead Zone (TDZ)&lt;/p&gt;

&lt;h3&gt;
  
  
  Temporal dead zone (TDZ)
&lt;/h3&gt;

&lt;p&gt;Ever heard of it? Well, it's a bit of a mouthful, but don't worry, we'll break it down.&lt;/p&gt;

&lt;p&gt;When we declare a variable using &lt;strong&gt;&lt;code&gt;let&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;const&lt;/code&gt;&lt;/strong&gt;, or &lt;strong&gt;&lt;code&gt;class&lt;/code&gt;&lt;/strong&gt;, JavaScript creates what's called a "temporal dead zone" (TDZ) for that variable. Now, this TDZ is like a waiting room – it's where the variable sits before it gets its value.&lt;/p&gt;

&lt;p&gt;During the TDZ period, which starts as soon as the block containing the variable begins and ends when the variable is declared and initialized, the variable exists, but it hasn't been given a value yet. So, if you try to access it during this time, JavaScript gets a bit cranky and throws a &lt;strong&gt;&lt;code&gt;[ReferenceError].&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But here's the interesting part: once JavaScript reaches the declaration of the variable and gives it a value, the TDZ ends, and the variable becomes accessible. If no initial value was specified during the declaration, JavaScript initializes the variable with a value of &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;Now, compare this to &lt;strong&gt;&lt;code&gt;var&lt;/code&gt;&lt;/strong&gt; variables. With &lt;strong&gt;&lt;code&gt;var&lt;/code&gt;&lt;/strong&gt;, if you try to access a variable before it's declared, JavaScript doesn't throw an error – it just returns &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;. This is because &lt;strong&gt;&lt;code&gt;var&lt;/code&gt;&lt;/strong&gt; variables are hoisted to the top of their scope, giving them a head start in the code execution process.&lt;/p&gt;

&lt;p&gt;So, why "temporal" dead zone? Well, it's because this zone depends on the order of execution, not the order in which the code is written. Take this example: even though a function using a &lt;strong&gt;&lt;code&gt;let&lt;/code&gt;&lt;/strong&gt; variable appears before the variable is declared, it's called outside the TDZ, so everything works smoothly.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Hoisting in Functions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ever tried calling a function before it's even declared? Well, in JavaScript, you can do just that! Unlike variables, functions don't throw an error when you try to use them before declaring them. Instead, they give you the whole function. Interesting, right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's dive into how hoisting works with functions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider this scenario:&lt;/p&gt;

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

&lt;p&gt;Here, we get the output as the whole function. Ever wonder why? It's because when JavaScript runs this code, we know that function is added in the memory component as whole in the execution context and when we call this function with out initilizing it give whole function and output.. &lt;/p&gt;

&lt;p&gt;So, even if you call the function before declaring it, JavaScript already knows about it and happily executes it without any complaints.&lt;/p&gt;

&lt;p&gt;But wait, there's a twist! When you use a function expression or an arrow function, things work a bit differently. In these cases, JavaScript treats the function as a variable. So, before the function is declared, JavaScript stores &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt; for it in memory. When you call the function without initializing it, it returns &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Declaration and arrow function:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n465t5zgdjzl2dua6ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n465t5zgdjzl2dua6ly.png" alt="Image description" width="800" height="292"&gt;&lt;/a&gt;&lt;br&gt;
In the above example, we get different outputs for function expression and function declaration or arrow function. Why? Because when you use function expression or arrow functions, JavaScript considers them as variables. So, before the function is initialized, JavaScript stores &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt; for it in memory. When you call the function without initializing it, it returns &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, next time you wonder why functions behave differently than variables when it comes to hoisting, remember this little quirk!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Wrap Up&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In summary, hoisting is JavaScript's behind-the-scenes magic that rearranges declarations, allowing us to use them before they're officially declared. Understanding this behavior is crucial for writing more efficient and effective JavaScript code.&lt;/p&gt;

&lt;p&gt;So, the next time you encounter hoisting in your code, you'll know exactly what's happening behind the scenes!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for Reading!&lt;/strong&gt; 😃&lt;/p&gt;

&lt;p&gt;Connect with Me! 🙋🏻‍♀️&lt;br&gt;
My Website - &lt;a href="https://shreyajoshi.tech/"&gt;https://shreyajoshi.tech/&lt;/a&gt;&lt;br&gt;
Instagram - &lt;a href="https://www.instagram.com/codebyshreya/"&gt;https://www.instagram.com/codebyshreya/&lt;/a&gt;&lt;br&gt;
LinkedIn - &lt;a href="https://www.linkedin.com/in/codebyshreya/"&gt;https://www.linkedin.com/in/codebyshreya/&lt;/a&gt;&lt;br&gt;
Linktree - &lt;a href="https://linktr.ee/codebyshreya"&gt;https://linktr.ee/codebyshreya&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding! 🎉&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Behind the Scenes: JavaScript Code Execution</title>
      <dc:creator>Shreya Joshi</dc:creator>
      <pubDate>Wed, 17 Apr 2024 07:44:56 +0000</pubDate>
      <link>https://dev.to/codebyshreya/behind-the-scenes-javascript-code-execution-52lc</link>
      <guid>https://dev.to/codebyshreya/behind-the-scenes-javascript-code-execution-52lc</guid>
      <description>&lt;p&gt;Ever found yourself in a late-night coding session, staring at your JavaScript code and wondering,&lt;em&gt;"What is going on here?"&lt;/em&gt; 🤷🏻‍♀️&lt;/p&gt;

&lt;p&gt;Well, buckle up because we're about to take a ride through the execution context of JavaScript. Maybe not as exciting as binge-watching your favourite series, but trust me, it's important stuff 🤨! You might not know it, but there's a whole lot happening behind the scenes when you write a simple script.🤯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's break down what an execution context is and why it’s important to know how it works in JavaScript.&lt;/strong&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Execution Context: What is it?
&lt;/h2&gt;

&lt;p&gt;All JavaScript code needs an environment to run in, and typically that environment is a web browser. The browser’s JavaScript engine sets up a special environment to manage your code, known as an &lt;strong&gt;&lt;code&gt;Execution Context&lt;/code&gt;&lt;/strong&gt;. &lt;br&gt;
It's where all the action happens, as your code gets parsed, interpreted, and executed.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol2deiz2abafie0o8kef.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol2deiz2abafie0o8kef.png" alt="Image description" width="800" height="215"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;There are two types of execution contexts in JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Global Execution Context (GEC)&lt;/li&gt;
&lt;li&gt;Function Execution Context (FEC)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Global Execution Context (GEC)
&lt;/h2&gt;

&lt;p&gt;When a JavaScript file is loaded, the engine first creates a default Execution Context called the &lt;strong&gt;&lt;code&gt;Global Execution Context (GEC)&lt;/code&gt;&lt;/strong&gt;. It's the top-level environment where global variables and functions live.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: there can only be one per JavaScript file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Function Execution Context (FEC)
&lt;/h2&gt;

&lt;p&gt;Every time you call a function, the JavaScript engine creates a Function Execution Context (FEC). This FEC lives inside the GEC, and it runs the function's code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Since each function call creates its own FEC, you might end up with multiple FECs at runtime.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h2&gt;
  
  
  Call Stack: The Execution Organizer
&lt;/h2&gt;

&lt;p&gt;The Call Stack, also known as the Execution Stack, plays a key role in JavaScript's execution model. It keeps track of all the Execution Contexts created during the life cycle of a script. &lt;/p&gt;

&lt;p&gt;It follows a Last In, First Out (LIFO) structure, meaning the most recently called function is executed first and removed from the stack when it finishes. &lt;/p&gt;

&lt;p&gt;This stack-based execution model allows JavaScript to manage function calls, returns, and the flow of control within a script.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Creation of Execution Contexts
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about how these &lt;code&gt;execution contexts (GEC or FEC)&lt;/code&gt; are created. &lt;br&gt;
&lt;strong&gt;It happens in two phases:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Creation Phase&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Execution Phase&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1️⃣ Creation Phase (Memory Phase)
&lt;/h2&gt;

&lt;p&gt;In this phase, variables and functions are declared in memory but not yet initialized. The Execution Context Object holds important data for the code in the Execution Context during its run-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The creation phase includes 3 stages:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creation of the Variable Object (VO)&lt;/li&gt;
&lt;li&gt;Creation of the Scope Chain&lt;/li&gt;
&lt;li&gt;Setting the value of the &lt;code&gt;this&lt;/code&gt; keyword&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;&lt;strong&gt;Creation Phase:&lt;/strong&gt;&lt;/u&gt; Creation of the Variable Object (VO)
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Variable Object (VO)&lt;/code&gt; is an object-like container created within an Execution Context. It stores the variables and function declarations defined within that Execution Context in the &lt;strong&gt;&lt;u&gt;&lt;em&gt;Memory Component as shown below in the diagram&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables declared with &lt;strong&gt;&lt;code&gt;var&lt;/code&gt;&lt;/strong&gt; are set to 'undefined' in the VO.&lt;/li&gt;
&lt;li&gt;Function declarations are added to the VO and stored in memory, making them accessible even before the code starts running.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;blockquote&gt;
&lt;p&gt;This process of storing variables and function declaration in memory prior to the execution of the code is known as &lt;code&gt;Hoisting&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;&lt;strong&gt;Creation Phase:&lt;/strong&gt;&lt;/u&gt;  &lt;strong&gt;Creation of The Scope Chain&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;In FEC,&lt;/strong&gt; Each Function Execution Context creates its scope: the space/environment where the variables and functions it defined can be accessed via a process called Scoping.&lt;/p&gt;

&lt;p&gt;When a function is defined inside another function, the inner function can access the outer function's code and even the scope of its parent functions. This hierarchy of scopes is known as &lt;strong&gt;&lt;code&gt;lexical scoping&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;This concept of scope brings up an associate phenomenon in JavaScript called &lt;code&gt;closures&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;u&gt;Creation Phase:&lt;/u&gt; Setting The Value of The "this" Keyword&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The JavaScript &lt;code&gt;**this**&lt;/code&gt; keyword refers to the scope where an Execution Context belongs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Global Execution Context (GEC)&lt;/strong&gt;, the &lt;strong&gt;&lt;code&gt;this&lt;/code&gt;&lt;/strong&gt; keyword refers to the global object, which in a web browser is the &lt;strong&gt;&lt;code&gt;window&lt;/code&gt;&lt;/strong&gt; object.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Function Execution Context (FEC)&lt;/strong&gt;, the &lt;strong&gt;&lt;code&gt;this&lt;/code&gt;&lt;/strong&gt; keyword points to the context where the function is called. This depends on how the function is invoked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These stages set the foundation for code execution in JavaScript by properly organizing the context's memory, scope, and references.&lt;/p&gt;

&lt;h2&gt;
  
  
  2️⃣ Execution Phase
&lt;/h2&gt;

&lt;p&gt;_&lt;strong&gt;This is where the real work gets done.&lt;/strong&gt; _&lt;br&gt;
After the creation phase, the execution phase begins.Up until now, the VO contained variables set to &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now, the JavaScript engine reads the code again, updates the all the variable with the actual values, and then the code is executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;u&gt;Let's Put It All Together&lt;/u&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To understand how this all plays out, consider the following example:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Here's how the execution context unfolds step by step in your JavaScript code:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;➡️ Step 1: Global Execution Context (GEC)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phase 1 : Memory Creation Phase&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;var n = 5&lt;/code&gt;&lt;/strong&gt; declaration creates a variable &lt;strong&gt;&lt;code&gt;n&lt;/code&gt;&lt;/strong&gt; with an initial value of &lt;code&gt;**undefined**&lt;/code&gt; .&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;function square(n)&lt;/code&gt;&lt;/strong&gt; declaration creates the function &lt;strong&gt;&lt;code&gt;square&lt;/code&gt; .&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;showsquare&lt;/code&gt;&lt;/strong&gt; declaration creates a variable with an initial value of &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phase 2 : Execution Phase&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;n&lt;/code&gt;&lt;/strong&gt; assigned the value 5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;var square1 = square(n)&lt;/code&gt;&lt;/strong&gt; is evaluated. This calls the function &lt;strong&gt;&lt;code&gt;square&lt;/code&gt;&lt;/strong&gt; with the argument &lt;strong&gt;&lt;code&gt;n&lt;/code&gt;&lt;/strong&gt; (which has a value of &lt;strong&gt;&lt;code&gt;5&lt;/code&gt;&lt;/strong&gt;). The Call Stack is used to create a new Function Execution Context (FEC) for the &lt;strong&gt;&lt;code&gt;square&lt;/code&gt;&lt;/strong&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;➡️ Step 2: Function Execution Context (FEC)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Phase 1 :  Memory Creation Phase&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;&lt;code&gt;square&lt;/code&gt;&lt;/strong&gt; function, the parameter &lt;strong&gt;&lt;code&gt;n&lt;/code&gt;&lt;/strong&gt; is created and assigned the value of &lt;strong&gt;&lt;code&gt;5&lt;/code&gt;&lt;/strong&gt; (the argument passed in).&lt;/li&gt;
&lt;li&gt;The variable &lt;strong&gt;&lt;code&gt;ans&lt;/code&gt;&lt;/strong&gt; is created and initialized to &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Phase 2 :  Execution Phase&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The expression &lt;strong&gt;&lt;code&gt;n * n&lt;/code&gt;&lt;/strong&gt; is calculated, resulting in &lt;strong&gt;&lt;code&gt;5 * 5 = 25&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The variable &lt;strong&gt;&lt;code&gt;ans&lt;/code&gt;&lt;/strong&gt; is assigned the value of &lt;strong&gt;&lt;code&gt;25&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;square&lt;/code&gt;&lt;/strong&gt; function returns the value &lt;strong&gt;&lt;code&gt;25&lt;/code&gt;&lt;/strong&gt; and its Function Execution Context is popped off the Call Stack.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h3&gt;
  
  
  &lt;strong&gt;➡️ Step 3: Return to Global Execution Context&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The returned value &lt;strong&gt;&lt;code&gt;25&lt;/code&gt;&lt;/strong&gt; from the &lt;strong&gt;&lt;code&gt;square&lt;/code&gt;&lt;/strong&gt; function is assigned to the &lt;strong&gt;&lt;code&gt;showsquare&lt;/code&gt;&lt;/strong&gt; variable in the Global Execution Context.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;console.log(showsquare)&lt;/code&gt;&lt;/strong&gt; statement is executed, printing the value &lt;strong&gt;&lt;code&gt;25&lt;/code&gt;&lt;/strong&gt; to the console.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;By following these steps, the JavaScript engine processes the code in terms of creating and executing the necessary execution contexts for both the global and function scopes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And there you have it! By understanding how execution contexts work, you gain insight into how JavaScript processes your code.👩🏻‍💻&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thanks for Reading! 😃&lt;/p&gt;

&lt;p&gt;Connect with Me! 🙋🏻‍♀️&lt;br&gt;
If you enjoyed this journey through JavaScript execution contexts, be sure to check out my &lt;a href="https://shreyajoshi.tech/"&gt;website&lt;/a&gt; for more tech insights. I am also on &lt;a href="https://www.instagram.com/codebyshreya/"&gt;Instagram&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/codebyshreya/"&gt;LinkedIn&lt;/a&gt; for more updates. &lt;/p&gt;

&lt;p&gt;And if you want to keep everything neat and tidy, &lt;a href="https://linktr.ee/codebyshreya"&gt;Linktree&lt;/a&gt; might just be your new best friend.&lt;/p&gt;

&lt;p&gt;Happy Coding! 🎉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>learning</category>
    </item>
    <item>
      <title>Flex It Like a Pro: A Beginner's Guide to CSS Flexbox</title>
      <dc:creator>Shreya Joshi</dc:creator>
      <pubDate>Fri, 12 Apr 2024 07:51:53 +0000</pubDate>
      <link>https://dev.to/codebyshreya/flex-it-like-a-pro-a-beginners-guide-to-css-flexbox-4m5m</link>
      <guid>https://dev.to/codebyshreya/flex-it-like-a-pro-a-beginners-guide-to-css-flexbox-4m5m</guid>
      <description>&lt;p&gt;CSS Flexbox, short for "CSS Flexible Box Layout," is a layout model in CSS designed to create more efficient and flexible ways to organize and arrange elements in a container. &lt;/p&gt;

&lt;p&gt;Unlike traditional CSS layouts that rely on block and inline directions, Flexbox is based on a single direction (either horizontal or vertical), making it easier to control the alignment and distribution of space among items in a container.&lt;/p&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Basic and Terminology&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here's a figure to illustrate the main idea behind the flex layout:&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Main Axis:&lt;/strong&gt; The main direction in which flex items are arranged in the container (left-to-right or top-to-bottom).&lt;br&gt;
&lt;strong&gt;Main Start | Main End:&lt;/strong&gt; The start and end points of the main axis.&lt;br&gt;
&lt;strong&gt;Cross Axis:&lt;/strong&gt; The direction perpendicular to the main axis.&lt;br&gt;
&lt;strong&gt;Cross Start | Cross End:&lt;/strong&gt; The start and end points of the cross axis.&lt;br&gt;
&lt;strong&gt;Main Size:&lt;/strong&gt; The size of a flex item in the main axis (width or height).&lt;br&gt;
&lt;strong&gt;Cross Size:&lt;/strong&gt; The size of a flex item in the cross axis (width or height).&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Flexbox Properties&lt;/strong&gt;
&lt;/h2&gt;

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

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Properties for the Parent (Flex Container):&lt;/strong&gt; &lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. display&lt;/strong&gt;&lt;br&gt;
To enable Flexbox, set the &lt;code&gt;display&lt;/code&gt; property of the container to &lt;code&gt;flex&lt;/code&gt; or &lt;code&gt;inline-flex&lt;/code&gt;. The flex value creates a block-level flex container, while inline-flex creates an inline-level flex container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
    display: flex;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2. flex-direction&lt;/strong&gt;&lt;br&gt;
This property sets the direction of the flex items.&lt;br&gt;
The possible values are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;row&lt;/code&gt;&lt;/strong&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;row-reverse&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;column&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;column-reverse&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  flex-direction: row | row-reverse | column | column-reverse;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;3. flex-wrap&lt;/strong&gt;&lt;br&gt;
It determines if flex items wrap onto multiple lines&lt;br&gt;
The possible values are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;nowrap&lt;/code&gt;&lt;/strong&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;wrap&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;wrap-reverse&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.div {
  flex-wrap: nowrap | wrap | wrap-reverse;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;4. Justify content&lt;/strong&gt;&lt;br&gt;
This property aligns flex items along the &lt;strong&gt;main axis&lt;/strong&gt;.&lt;br&gt;
The possible values are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;/strong&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;flex-end&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;center&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-between&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-around&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-evenly&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;5. align-items&lt;/strong&gt;&lt;br&gt;
This property aligns flex items along the &lt;strong&gt;cross axis&lt;/strong&gt;.&lt;br&gt;
The possible values are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;/strong&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;flex-end&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;center&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;baseline&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;6. align-content&lt;/strong&gt;&lt;br&gt;
Aligns lines of flex items when there is extra space in the &lt;strong&gt;cross axis&lt;/strong&gt;.&lt;br&gt;
The possible values are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;/strong&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;flex-end&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;center&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-between&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-around&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;space-evenly&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;7. gap, row-gap, column-gap&lt;/strong&gt;&lt;br&gt;
Explicitly controls the space between flex items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.div {
  display: flex;
  ...
  gap: 10px;
  gap: 10px 20px; /* row-gap column gap */
  row-gap: 10px;
  column-gap: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Properties for the Child (Flex items):&lt;/strong&gt; &lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. order&lt;/strong&gt;&lt;br&gt;
Sets the order of flex items. Default is 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item1 {
    order: 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2. flex-grow&lt;/strong&gt;&lt;br&gt;
Controls how much a flex item should grow relative to its siblings. Default is 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item2 {
    flex-grow: 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;3. flex-shrink&lt;/strong&gt;&lt;br&gt;
Controls how much a flex item should shrink relative to its siblings. Default is 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item2 {
    flex-shrink: 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;strong&gt;4. align-self&lt;/strong&gt;&lt;br&gt;
Allows flex items to override the container’s align-items property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
    align-self: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdfubgik0sf2h3d844b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdfubgik0sf2h3d844b2.png" alt="Image description" width="800" height="217"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;5. flex-basis&lt;/strong&gt;&lt;br&gt;
Sets the initial size of a flex item before growing or shrinking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item2 {
    flex-basis: 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h2&gt;
  
  
  &lt;strong&gt;More Information&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.w3.org/TR/css-flexbox-1/"&gt;CSS Flexible Box Layout Module Level 1 (W3C)&lt;/a&gt;: The official specification for CSS Flexbox.&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/cheatsheets/css-flexbox"&gt;A CSS Flexbox Cheatsheet (DigitalOcean)&lt;/a&gt;: A handy guide with examples and explanations.&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/css-centering-using-flexbox"&gt;Centering Things in CSS With Flexbox (DigitalOcean)&lt;/a&gt;: A tutorial on using Flexbox for centering elements.&lt;/p&gt;

&lt;p&gt;That's it! You're now equipped with a strong foundation in CSS Flexbox. Let me know if you have any questions or if you need further assistance!&lt;/p&gt;

&lt;p&gt;Happy coding! 😊&lt;/p&gt;

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