<?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: Badreddine Boudaoud</title>
    <description>The latest articles on DEV Community by Badreddine Boudaoud (@badr21).</description>
    <link>https://dev.to/badr21</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%2F1047516%2Fc6d16797-383f-40e9-b198-73197830f909.JPG</url>
      <title>DEV Community: Badreddine Boudaoud</title>
      <link>https://dev.to/badr21</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/badr21"/>
    <language>en</language>
    <item>
      <title>JavaScript Execution Context &amp; Hoisting</title>
      <dc:creator>Badreddine Boudaoud</dc:creator>
      <pubDate>Wed, 22 Nov 2023 15:29:50 +0000</pubDate>
      <link>https://dev.to/badr21/javascript-execution-context-hoisting-2e4h</link>
      <guid>https://dev.to/badr21/javascript-execution-context-hoisting-2e4h</guid>
      <description>&lt;p&gt;&lt;em&gt;Whether you’ve just started learning JavaScript or have some experience, you might have, at least once, searched for how JavaScript works behind the scenes. If so, you might have come across terms like “execution context” and “hoisting,” two topics that are closely related to each other.&lt;br&gt;
Today, you’ll grasp both of them through the most straightforward explanations you’ll ever encounter.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript is an interpreted, single-threaded language that processes one command at a time. To understand how JavaScript scripts are executed, it’s essential to comprehend the concept of execution context and hoisting.&lt;/p&gt;
&lt;h2&gt;
  
  
  Execution Context
&lt;/h2&gt;

&lt;p&gt;The execution context is the environment created when running JavaScript code. There are two types of execution contexts: Global execution context and function execution context. The global execution context represents the global scope, it’s created when JavaScript first runs. The function execution context is created whenever a function is called.&lt;/p&gt;
&lt;h3&gt;
  
  
  Execution Context Phases
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Creation Phase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;During this phase, the global object is created, the this keyword is generated and linked to the global object, and functions and variables are allocated memory and stored (variables are set to undefined).&lt;/p&gt;

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

&lt;p&gt;In this phase, the code is executed line by line, and a new execution context is created whenever a function is called.&lt;/p&gt;

&lt;p&gt;Let’s understand it with an 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 x = 3;
function getSquare(n) {
   var square = n ** 2;
   return square;
}
var theSquare = getSquare(x);

console.log(theSquare);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;strong&gt;Line 1:&lt;/strong&gt; Allocates memory for the variable &lt;code&gt;x&lt;/code&gt; and initializes it with the value &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 2:&lt;/strong&gt; Allocates memory for the function &lt;code&gt;getSquare()&lt;/code&gt; and stores the entire code within it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 6:&lt;/strong&gt; Allocates memory for the variable &lt;code&gt;theSqureand&lt;/code&gt; and initializes it with &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Line 1:&lt;/strong&gt; Sets the variable &lt;code&gt;x&lt;/code&gt;to the value 3.&lt;br&gt;
&lt;strong&gt;Line 2:&lt;/strong&gt; Skips the function &lt;code&gt;getSquare()&lt;/code&gt; as there is nothing to execute.&lt;br&gt;
&lt;strong&gt;Line 6:&lt;/strong&gt; Initiates a new execution context (function execution context) as the function is called.&lt;br&gt;
&lt;strong&gt;Creation Phase (function execution context):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Line 2:&lt;/strong&gt; Allocates memory for the variable &lt;code&gt;n&lt;/code&gt;and initializes it with &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line 3:&lt;/strong&gt; Allocates memory for the variable &lt;code&gt;square&lt;/code&gt; and initializes &lt;br&gt;
it with &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Execution Phase (function execution context):&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line 2:&lt;/strong&gt; Assigns 3 to the variable &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line 3:&lt;/strong&gt; Calculates and assigns the result to the variable &lt;code&gt;square&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Line 4:&lt;/strong&gt; Returns to the global execution context.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Line 6: Assigns the returned value of &lt;code&gt;square&lt;/code&gt;into the variable &lt;code&gt;theSqure&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now if we console log the output(line8) we will get the following:&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2A0BroGaupL-4ajopsPbLa_g.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2A0BroGaupL-4ajopsPbLa_g.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What if we console log the output before all the code?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(theSquare);

var x = 3;
function getSquare(n) {
   var square = n ** 2;
   return square;
}
var theSquare = getSquare(x);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is undefined&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2AkghMyidkUKhVnI8Pzp2f5Q.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2Fformat%3Awebp%2F1%2AkghMyidkUKhVnI8Pzp2f5Q.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might wonder why the default value for variables is set to undefined. This is a result of the creation phase during the execution context, as discussed earlier. In this phase, variables, including &lt;code&gt;theSqure&lt;/code&gt;, are allocated memory with an initial value of &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, if you attempt to console log the variable &lt;code&gt;x&lt;/code&gt; before its initialization, you will also get &lt;code&gt;undefined&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;console.log(x);
var x = 3;
&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AkghMyidkUKhVnI8Pzp2f5Q.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AkghMyidkUKhVnI8Pzp2f5Q.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Understanding the execution context and its creation phase simplifies grasping the concept of hoisting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hoisting
&lt;/h2&gt;

&lt;p&gt;Hoisting is frequently described as the interpreter moving variable and function declarations to the top of their scope before code execution. However, now that you understand the creation phase of the execution context, you realize that this explanation is a simplification to help conceptualize the behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable hoisting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(x);
var x = 2;
console.log(x);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, even though we console log before the variable &lt;code&gt;x&lt;/code&gt; is declared and assigned a value, it doesn’t result in an error. Because of hoisting the variable &lt;code&gt;x&lt;/code&gt; in the first console log outputs &lt;code&gt;undefined&lt;/code&gt; (Allocates memory for the variable x and initializes it with the value undefined).&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AtLm8xyiOcTR-EssWceYRuA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AtLm8xyiOcTR-EssWceYRuA.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function hoisting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(getCube(2));

function getCube(x) {
   return x ** 3;
}
console.log(getCube(2));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the function &lt;code&gt;getCube()&lt;/code&gt; is called before its declaration in the code. Because of hoisting the entire function gets stored(Allocates memory for the function getCube() and stores the entire code within it.), allowing it to be invoked before its actual placement in the 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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AbOJfZmO9faZSE9BOiKDo2Q.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AbOJfZmO9faZSE9BOiKDo2Q.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s crucial to distinguish between function declaration and function expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(getCube(2));

var getCube = (x) =&amp;gt; {
   return x ** 3;
};
console.log(getCube(2));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code, &lt;code&gt;getCube()&lt;/code&gt; is invoked before it is declared. Due to hoisting, the variable declaration(&lt;code&gt;var getCube&lt;/code&gt;)is hoisted, but the function definition (&lt;code&gt;(x) =&amp;gt; { return x ** 3; }&lt;/code&gt;)is not. So, when the first console log is encountered, &lt;code&gt;getCube()&lt;/code&gt; is still &lt;code&gt;undefined&lt;/code&gt;at that point, and trying to invoke it as a function will result in a &lt;code&gt;TypeError&lt;/code&gt;.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AP9gmBC7VR4qn4MOUPLUrag.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A720%2Fformat%3Awebp%2F1%2AP9gmBC7VR4qn4MOUPLUrag.png" alt="code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this juncture, you may notice that we opted for using &lt;code&gt;var&lt;/code&gt;for variable declarations instead of &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;. Why this decision? Simply put, it's to enhance comprehension of the example. While &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;are block-scoped and also hoisted, variables declared with them are not accessible before initialization—unlike variables declared with &lt;code&gt;var&lt;/code&gt;, which are hoisted and stored in memory as undefined during the creation phase of the execution context.&lt;/p&gt;

&lt;p&gt;The rationale behind the inaccessibility of variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; before initialization lies in what is known as the &lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporal dead zone (TDZ)&lt;/strong&gt; is the area of a block where a variable is inaccessible until the moment the computer completely initializes it with a value&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%2Fw8pxv9hbegh7gvwxs03p.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%2Fw8pxv9hbegh7gvwxs03p.jpg" alt="A diagram to illustrate the difference between the var and let lifecycles"&gt;&lt;/a&gt;&lt;br&gt;
A simple diagram to illustrate the difference between the var and let lifecycles&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Whether you’re just starting out with JavaScript or have considerable experience, a thorough understanding of execution context and hoisting is paramount. Delving into the mechanics of how JavaScript functions behind the scenes not only enhances your workflow but also becomes a valuable time-saving skill.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>hoisting</category>
      <category>executioncontext</category>
    </item>
    <item>
      <title>JavaScript ‘this’ keyword’s binding rules</title>
      <dc:creator>Badreddine Boudaoud</dc:creator>
      <pubDate>Sun, 17 Sep 2023 22:37:03 +0000</pubDate>
      <link>https://dev.to/badr21/javascript-this-keywords-binding-rules-2n4e</link>
      <guid>https://dev.to/badr21/javascript-this-keywords-binding-rules-2n4e</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;The ‘this’ keyword in JavaScript can be perplexing for many developers, and I, too, struggled with it for quite some time. If you’re one of those developers eager to grasp how ‘this’ works, you’re in the right place. By the end of this article, you’ll have a clear understanding of ‘this’. So, let’s get started!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is the ‘this’ keyword in JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, the ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword refers to the object being executed in the current context, in other words, The ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword refers to different objects depending on how it is used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does the ‘this’ keyword allow you to do?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword allows you to reuse functions with different contexts. In other words, it enables you to determine or specify which object should be the focus of the context when invoking a function or a method. For example, when you have multiple objects with the same properties and a single function, ‘&lt;strong&gt;this&lt;/strong&gt;’ allows that function to work with all of your objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binding rules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Global object binding
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A. ‘this’ In the global context&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword is not inside a function or an object, it refers to the window(global) object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(this);
console.log(this === window);
window.firstName = "Badreddine";
console.log(this.firstName);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned earlier, in the global context, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the window(global) object. In the example above, the first line logs the window object, and the second line logs true.&lt;/p&gt;

&lt;p&gt;To illustrate further, we create a variable “firstName” on the window object and assign it the value “Badreddine”. Since ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the window (global) object, the fourth line will log the value “Badreddine”, which is the value of the “firstName” property on the global (window) object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F1TDg4oR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71qaki97l3mdleomw2py.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F1TDg4oR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71qaki97l3mdleomw2py.png" alt="console log of the code above" width="800" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And it’s the same output whether it’s in strict mode or default mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. ‘this’ in a regular function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;‘&lt;strong&gt;this&lt;/strong&gt;’ inside a regular function, when ‘&lt;strong&gt;this&lt;/strong&gt;’ is used without any specific context, it still refers to the window object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example1&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

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

regularFunction();
&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://res.cloudinary.com/practicaldev/image/fetch/s--EHe2xIZc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbd7l8s0tp84u0i3fqoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EHe2xIZc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbd7l8s0tp84u0i3fqoe.png" alt="console log of the code above" width="800" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In strict mode, ‘&lt;strong&gt;this&lt;/strong&gt;’ in a regular function is undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example2&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use strict";
function regularFunction() {
    console.log(this);
}

regularFunction();
&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://res.cloudinary.com/practicaldev/image/fetch/s--skBJt91P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwpihuqwtgp3i55bbjw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--skBJt91P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwpihuqwtgp3i55bbjw6.png" alt="console log of the code above" width="588" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example3&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var firstName = "Badreddine";
function regularFunction() {
   const firstName = "Badr";
   console.log(firstName);
   console.log(this.firstName);
}

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

&lt;/div&gt;



&lt;p&gt;In the example above we declare two variables with the same name, one inside the function and another one outside, what would be the output?&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IOIPZkm6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cid7us4nc0t8jfcn4unh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IOIPZkm6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cid7us4nc0t8jfcn4unh.png" alt="console log of the code above" width="513" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first log (fourth line) will output “Badr”. However, the second log (fifth line) will output “Badreddine”, and that’s because ‘&lt;strong&gt;this&lt;/strong&gt;’ in regular function refers to the window(global) object as we said earlier.&lt;/p&gt;

&lt;p&gt;Just one thing to add: if the outside “firstName” variable was declared with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;, the output would be undefined, as shown below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example4&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const firstName = "Badreddine";
function regularFunction() {
   const firstName = "Badr";
   console.log(firstName);
   console.log(this.firstName);
}

regularFunction();
&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://res.cloudinary.com/practicaldev/image/fetch/s--CAy5_FWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rj6s72ub13y4aooq5d1z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CAy5_FWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rj6s72ub13y4aooq5d1z.png" alt="console log of the code above" width="359" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that’s because variables declared with &lt;code&gt;var&lt;/code&gt; are added as properties of the global (window) object, unlike variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;, which are not.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Implicit Binding
&lt;/h3&gt;

&lt;p&gt;Implicit binding occurs when you invoke a function using dot notation, in those cases, we need to check the object adjacent to the method at invocation time. In simple words look at the function invocation, the object on its left is what ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example1&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = {
   firstName: "Badreddine",
   job: "Frontend Developer",
   msg() {
      console.log(`Hi my name is ${this.firstName}, I'm a ${this.job}`);
   },
};

infos.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create an object “infos” with two properties and one method, then we invoke the “msg” method using &lt;code&gt;infos.msg()&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B4qHBs5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55aec9k75kgc2p5nhs8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B4qHBs5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55aec9k75kgc2p5nhs8n.png" alt="console log of the code above" width="800" height="46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The output is as expected, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the object on the left of the function invocation(“infos”).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example2&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function infosMsg(obj) {
   obj.msg = function () {
      console.log(`Hi, my name is ${this.name}, I'm a ${this.job}`);
   };
}

const badreddine = {
   name: "Badreddine",
   job: "Frontend Developer",
};

const ali = {
   name: "Ali",
   job: "Backend Developer",
};

infosMsg(badreddine);
infosMsg(ali);

badreddine.msg();
ali.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create a function “infoMsg” that takes one parameter, “obj”. Inside the function, we add a new method called “msg” to the “obj” parameter.&lt;/p&gt;

&lt;p&gt;Then, we create two objects, “badreddine” and “ali”, and called the “infoMsg” function for both objects.&lt;/p&gt;

&lt;p&gt;Finally, we invoke the “msg” method on both objects.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iZuR9Ajr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kw3mdjsy2p7cyjr2puw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iZuR9Ajr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kw3mdjsy2p7cyjr2puw6.png" alt="console log of the code above" width="731" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The output is as expected: when the method is called with the “badreddine object, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the “badreddine” object, and when it’s called with the “ali” object, it refers to the “ali” object.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Explicit Binding
&lt;/h3&gt;

&lt;p&gt;Explicit binding occurs when we use &lt;code&gt;call()&lt;/code&gt;, &lt;code&gt;apply()&lt;/code&gt;, and &lt;code&gt;bind()&lt;/code&gt; methods on a function. It’s called explicit because we explicitly specify the value of ‘&lt;strong&gt;this&lt;/strong&gt;’.&lt;/p&gt;

&lt;p&gt;The three methods are predefined JavaScript methods used to control the value of ‘&lt;strong&gt;this&lt;/strong&gt;’, and they can accept additional arguments alongside the context(value of ‘&lt;strong&gt;this&lt;/strong&gt;’) as the first argument.&lt;/p&gt;

&lt;h4&gt;
  
  
  A. call() method
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;call()&lt;/code&gt; method can take ‘&lt;strong&gt;this&lt;/strong&gt;’ as the first argument, followed by an unlimited number of arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = function (techOne, techTwo, techThre) {
   console.log(
      `Hi, my name is ${this.name}, I'm a ${this.job}, I use ${techOne}, ${techTwo} and ${techThre}`
   );
};

const me = {
   name: "Badreddine",
   job: "Frontend Developer",
};

const technologies = ["React", "TypeScript", "Tailwind"];

infos.call(me, technologies[0], technologies[1], technologies[2]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create a function “infos” which takes parameters, an object “me” and an array “technologies”.&lt;/p&gt;

&lt;p&gt;We use the &lt;code&gt;call()&lt;/code&gt; method on the “infos” function to invoke it. The &lt;code&gt;call()&lt;/code&gt; method takes the “me” object as its first argument, which sets the value of ‘&lt;strong&gt;this&lt;/strong&gt;’ inside the “infos” function to the “me” object. The subsequent arguments (technologies[0], technologies[1], and technologies[2]) are passed as arguments to the “infos” function.&lt;/p&gt;

&lt;p&gt;Inside the “infos” function, “this.name” and “this.job” now refer to the properties of the “me” object&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E1z5oXup--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wohug1orl2qqbxbqtcfy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E1z5oXup--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wohug1orl2qqbxbqtcfy.png" alt="console log of the code above" width="800" height="33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  B. apply() method
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;apply()&lt;/code&gt; method can take a ‘&lt;strong&gt;this&lt;/strong&gt;’ argument followed by an array of unlimited elements.&lt;/p&gt;

&lt;p&gt;The difference between &lt;code&gt;call()&lt;/code&gt; and &lt;code&gt;apply()&lt;/code&gt; methods is how arguments are passed to the function. &lt;code&gt;call()&lt;/code&gt; accepts arguments as individual parameters, while &lt;code&gt;apply()&lt;/code&gt; accepts arguments as an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = function (techOne, techTwo, techThre) {
   console.log(
      `Hi, my name is ${this.name}, I'm a ${this.job}, I use ${techOne}, ${techTwo} and ${techThre}`
   );
};

const me = {
   name: "Badreddine",
   job: "Frontend Developer",
};

const technologies = ["React", "TypeScript", "Tailwind"];

infos.apply(me, technologies);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create a function “infos” which takes parameters, an object “me” and an array “technologies”.&lt;/p&gt;

&lt;p&gt;We use the &lt;code&gt;apply()&lt;/code&gt; method on the “infos” function to invoke it. The &lt;code&gt;apply()&lt;/code&gt; method takes “me” object as its first argument, which sets the value of ‘&lt;strong&gt;this&lt;/strong&gt;’ inside the “infos” function to the “me” object. The second argument (technologies) is an array that will be spread as arguments to the “infos” function.&lt;/p&gt;

&lt;p&gt;Inside the “infos” function, “this.name” and “this.job” now refer to the properties of the ‘me’ object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G6NVzehs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qqy9w6ejeeqg8a1ba2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G6NVzehs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qqy9w6ejeeqg8a1ba2q.png" alt="console log of the code above" width="800" height="33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  C. bind() method
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;bind()&lt;/code&gt; method can take ‘&lt;strong&gt;this&lt;/strong&gt;’ as the first argument, followed by an unlimited number of arguments.&lt;/p&gt;

&lt;p&gt;The difference between &lt;code&gt;call()&lt;/code&gt; and &lt;code&gt;bind()&lt;/code&gt;, is that &lt;code&gt;call()&lt;/code&gt; immediately invokes the function, while &lt;code&gt;bind()&lt;/code&gt; returns a new function which you can call it later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = function (techOne, techTwo, techThre) {
   console.log(
      `Hi, my name is ${this.name}, I'm a ${this.job}, I use ${techOne}, ${techTwo} and ${techThre}`
   );
};

const me = {
   name: "Badreddine",
   job: "Frontend Developer",
};

const technologies = ["React", "TypeScript", "Tailwind"];

const newFunc = infos.bind(me, technologies[0], technologies[1], technologies[2]);
newFunc();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create a function “infos” which takes parameters, an object “me” and an array “technologies”.&lt;/p&gt;

&lt;p&gt;Then we create a new function “newFunc” and initialize it with the returned function(the &lt;code&gt;bind()&lt;/code&gt; method on the “infos” function). The bind() method takes “me” object as its first argument, which sets the value of ‘&lt;strong&gt;this&lt;/strong&gt;’ inside the “infos” function to the “me” object. The subsequent arguments (technologies[0], technologies[1], and technologies[2]) are passed as arguments to the “infos” function.&lt;/p&gt;

&lt;p&gt;Finally, we invoke the “newFunc” fonction&lt;/p&gt;

&lt;p&gt;Inside the “infos” function, “this.name” and “this.job” now refer to the properties of the “me” object&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tP8oQbyh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dpcczm4i7w6nf4ii1v4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tP8oQbyh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dpcczm4i7w6nf4ii1v4.png" alt="console log of the code above" width="800" height="33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. The new keyword
&lt;/h3&gt;

&lt;p&gt;When you call a function with the new keyword in JavaScript, a new instance of the constructor is created, and ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword within the constructor function refers to the instance being created. Additionally, any properties and/or methods defined within the constructor will be assigned to that newly created instance.&lt;/p&gt;

&lt;h4&gt;
  
  
  A. function constructor
&lt;/h4&gt;

&lt;p&gt;A function constructor is a regular JavaScript function that is used to create objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Developer(name, job) {
   this.name = name;
   this.job = job;
   this.msg = function () {
      console.log(`Hi my name is ${this.name}, I'm a ${this.job}`);
   };
}

let me = new Developer("Badreddine", "Frontend Developer");
me.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we define a constructor function called “Developer” that takes two parameters “name” and “job”.&lt;/p&gt;

&lt;p&gt;Within the constructor, we use the ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword to assign values to the properties of the object being created (“this.name” and “this.job”). This allows us to initialize each instance of Developer with specific values for name and job.&lt;/p&gt;

&lt;p&gt;Additionally, we define a method named “msg” within the constructor.&lt;/p&gt;

&lt;p&gt;Then we create a new instance of the Developer object by calling &lt;code&gt;new Developer(“Badreddine”, “Frontend Developer”)&lt;/code&gt;. This instance is stored in the variable “me”.&lt;/p&gt;

&lt;p&gt;Finally, we invoke the “msg” method on the “me” object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cn91sA8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6wlc9116egnuy74p7po.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cn91sA8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6wlc9116egnuy74p7po.png" alt="console log of the code above" width="800" height="46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  B. class
&lt;/h4&gt;

&lt;p&gt;a class in JavaScript is essentially a syntactic way of defining constructor functions introduced in ES6.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Developer {
   constructor(name, job) {
      this.name = name;
      this.job = job;
      this.msg = function () {
         console.log(`Hi my name is ${this.name}, I'm a ${this.job}`);
      };
   }
}

let me = new Developer("Badreddine", "Frontend Developer");
me.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we define a class called “Developer” using the “class” keyword. This class serves as a blueprint for creating developer objects. Inside the Developer class, we define a constructor method using the “constructor” keyword. The constructor method takes two parameters, “name” and “job”, representing the name and job title of a developer, and it is automatically called when you create a new instance of the class.&lt;/p&gt;

&lt;p&gt;Within the constructor method, we use the ‘&lt;strong&gt;this&lt;/strong&gt;’ keyword to assign the provided name and job values to the object being created.&lt;/p&gt;

&lt;p&gt;Additionally, we define a method called “msg” within the constructor method.&lt;/p&gt;

&lt;p&gt;we create a new instance of the Developer class by calling &lt;code&gt;new Developer(“Badreddine”, “Frontend Developer”)&lt;/code&gt;. This instance is stored in the variable me.&lt;/p&gt;

&lt;p&gt;Finally, you invoke the “msg” method on the “me” object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v3CMzHiK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2igeyuci5qgidaden1ht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v3CMzHiK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2igeyuci5qgidaden1ht.png" alt="console log of the code above" width="800" height="46"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Arrow Functions
&lt;/h3&gt;

&lt;p&gt;The arrow function is another way to create functions introduced in ES6. When you use ‘&lt;strong&gt;this&lt;/strong&gt;’ with an arrow function, it would refer to the surrounding lexical context and that’s because it does not have its own context. The lexical context could be a parent function, a global context, or any enclosing scope where the arrow function is defined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example1&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = {
   firstName: "Badreddine",
   msg: () =&amp;gt; {
      console.log(`Hi, my name is ${this.firstName}`);
      console.log(this);
   },
};

infos.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create an object “infos” with a “firstName” property set to the string “Badreddine”.&lt;/p&gt;

&lt;p&gt;Inside the “infos” object, we define a method “msg” using an arrow function syntax.&lt;/p&gt;

&lt;p&gt;We call the “msg” method on the “infos” object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ecz_KJBg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/delwjsst7sl7956eq478.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ecz_KJBg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/delwjsst7sl7956eq478.png" alt="console log of the code above" width="800" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, here’s what happens when we run this code:&lt;/p&gt;

&lt;p&gt;The first log attempts to access “this.firstName”. However, since arrow functions inherit the ‘&lt;strong&gt;this&lt;/strong&gt;’ value from their surrounding lexical scope, and there is no outer function or scope that defines ‘&lt;strong&gt;this&lt;/strong&gt;’, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the global object (window). Therefore, “this.firstName” will likely be undefined.&lt;/p&gt;

&lt;p&gt;The second log logs the ‘&lt;strong&gt;this&lt;/strong&gt;’ object, which will typically be the global object (window).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example2&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const infos = {
    firstName: "Badreddine",
    msg() {
       let logMsg = () =&amp;gt; {
          console.log(`Hi, my name is ${this.firstName}`);
          console.log(this);
       };
       logMsg();
    },
 };

 infos.msg();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we create an object named “infos” with a “firstName” property set to the string “Badreddine”.&lt;/p&gt;

&lt;p&gt;Inside the “infos” object, we define a method “msg”.&lt;/p&gt;

&lt;p&gt;Inside the “msg” method, we define a nested function called “logMsg” using the arrow function syntax and we call it.&lt;/p&gt;

&lt;p&gt;Finally, we call the “msg” method on the “infos” object.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--maLoI1zB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmfo83zha06siygiccj0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--maLoI1zB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmfo83zha06siygiccj0.png" alt="console log of the code above" width="800" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, here’s what happens when we run this code:&lt;/p&gt;

&lt;p&gt;The “logMsg” arrow function is called within the “msg” method.&lt;/p&gt;

&lt;p&gt;Inside the “logMsg” function:&lt;/p&gt;

&lt;p&gt;The first log attempts to access “this.firstName”. Since arrow functions inherit the ‘&lt;strong&gt;this&lt;/strong&gt;’ value from their surrounding lexical scope (in this case, the “msg” method), “this.firstName” refers to the “firstName” property of the “infos” object.&lt;/p&gt;

&lt;p&gt;The second log logs the ‘&lt;strong&gt;this&lt;/strong&gt;’ object. Again, ‘&lt;strong&gt;this&lt;/strong&gt;’ inherits the value from the surrounding lexical scope, which is the “msg” method. Therefore, it refers to the “infos” object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Recap of key points about ‘&lt;strong&gt;this&lt;/strong&gt;’ in JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alone, in a global context ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the global(window) object, whether it’s in strict mode or default mode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In a regular function when ‘&lt;strong&gt;this&lt;/strong&gt;’ is used without any specific context, in default mode, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the global(window)object, but in strict mode it’s undefined.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the implicit binding cases, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the object on the left side of the function at invocation time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the explicit binding cases, ‘&lt;strong&gt;this&lt;/strong&gt;’ refers to the value you explicitly specify.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In an arrow function, ‘&lt;strong&gt;this&lt;/strong&gt;’ does not have its own context, so it would refer to the surrounding lexical context.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Value type vs Reference type in JavaScript</title>
      <dc:creator>Badreddine Boudaoud</dc:creator>
      <pubDate>Thu, 30 Mar 2023 23:20:23 +0000</pubDate>
      <link>https://dev.to/badr21/value-type-vs-reference-type-in-javascript-4fp6</link>
      <guid>https://dev.to/badr21/value-type-vs-reference-type-in-javascript-4fp6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript is a dynamic, loosely typed language that allows developers to create and manipulate variables with ease. One of the fundamental concepts in JavaScript is the difference between &lt;strong&gt;reference&lt;/strong&gt; and &lt;strong&gt;value&lt;/strong&gt; types. Understanding the difference between these two types is crucial for writing efficient, bug-free code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Primitives vs Objects
&lt;/h2&gt;

&lt;p&gt;In JavaScript, variables can be assigned values that are either primitives or objects(non-primitives). Understanding the difference between primitive and object(non-primitive) values is essential to understanding &lt;strong&gt;value&lt;/strong&gt; and &lt;strong&gt;reference&lt;/strong&gt; in JavaScript.&lt;/p&gt;

&lt;p&gt;Primitive values are simple, immutable values that are not objects. There are six primitive data types in JavaScript: &lt;strong&gt;string&lt;/strong&gt;, &lt;strong&gt;number&lt;/strong&gt;, &lt;strong&gt;boolean&lt;/strong&gt;, &lt;strong&gt;null&lt;/strong&gt;, &lt;strong&gt;undefined&lt;/strong&gt;, and &lt;strong&gt;symbol&lt;/strong&gt;. When a primitive value is assigned to a variable, the variable holds a copy of that value.&lt;/p&gt;

&lt;p&gt;On the other hand, &lt;strong&gt;objects&lt;/strong&gt; are values that can hold a collection of key-value pairs, methods, and other &lt;strong&gt;objects&lt;/strong&gt;, (in JavaScript arrays and functions are also objects). When an &lt;strong&gt;object&lt;/strong&gt; is assigned to a variable, the variable holds a reference to the memory location where the object is stored.&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%2Fhisqjxt9n50lqlv1aqs0.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%2Fhisqjxt9n50lqlv1aqs0.png" alt="Data types in JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Value vs Reference examples
&lt;/h2&gt;

&lt;p&gt;1- When a variable is assigned a &lt;strong&gt;value&lt;/strong&gt; type, the variable holds a copy of the value.&lt;br&gt;
&lt;strong&gt;Example 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 5;
let b = a;
a = 10;

console.log(a); // Output: 10
console.log(b); // Output: 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the variable a is assigned the value 5. The variable b is then assigned the value of a, which means that b also has the value of 5. When a is then assigned the value 10, the value of b remains unchanged because b has a copy of the value of a, not a reference to a.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str1 = "hello";
let str2 = str1;
str2 = "world";

console.log(str1); // Output: "hello"
console.log(str2); // Output: "world"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, str1 holds the string value “hello”, and when we assign str1 to str2, str2 holds a copy of the value of str1. When we then assign str2 the value “world”, str1 is not affected, because str2 holds a separate copy of the value.&lt;/p&gt;

&lt;p&gt;2- When a variable is assigned a &lt;strong&gt;reference&lt;/strong&gt; type, changes to the object will affect all variables that reference that object. For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr1 = [1, 2, 3];
let arr2 = arr1;
arr1.push(4);

console.log(arr1); // Output: [1, 2, 3, 4]
console.log(arr2); // Output: [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, arr1 is assigned a reference to an array containing the values [1, 2, 3]. arr2 is then assigned the same reference as arr1. When arr1 is then modified by pushing the value 4 onto the end of the array, the change is reflected in arr2 because both variables hold a reference to the same object in memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj1 = { name: "Alice", age: 30 };
let obj2 = obj1;
obj2.age = 31;

console.log(obj1); // Output: { name: "Alice", age: 31 }
console.log(obj2); // Output: { name: "Alice", age: 31 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, obj1 holds a reference to an object with properties name and age. When we assign obj1 to obj2, obj2 holds a copy of the reference to the same object in memory. When we then change the value of the age property of obj2, obj1 is also affected, because both variables hold a reference to the same object in memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use Value Types vs Reference Types
&lt;/h2&gt;

&lt;p&gt;Now that we understand the difference between &lt;strong&gt;value&lt;/strong&gt; and &lt;strong&gt;reference&lt;/strong&gt; types in JavaScript, let’s explore how to use them effectively in our code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt; types are useful when you want to create a copy of a variable without affecting the original value. This is especially important when you are working with primitive data types such as numbers, strings, and Booleans.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt; types are useful when you want to create a variable that refers to the same object or array in memory. This is especially important when you are working with complex data types such as objects and arrays.&lt;/p&gt;

&lt;p&gt;However, it is important to be careful when working with &lt;strong&gt;reference&lt;/strong&gt; types. If you make changes to a &lt;strong&gt;reference&lt;/strong&gt; type variable, it will affect all other variables that reference the same object or array in memory. This can lead to unexpected behavior and bugs in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;knowing the difference between &lt;strong&gt;value&lt;/strong&gt; and &lt;strong&gt;reference&lt;/strong&gt; types in JavaScript is crucial for writing effective and efficient code. By understanding when to use each type, you can avoid bugs and ensure that your code behaves as intended. By keeping these concepts in mind, you can write cleaner and more maintainable code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Eight(8) ES6(ECMAScript 6) features that you need to know before learning React</title>
      <dc:creator>Badreddine Boudaoud</dc:creator>
      <pubDate>Tue, 28 Mar 2023 00:39:50 +0000</pubDate>
      <link>https://dev.to/badr21/eight8-es6ecmascript-6-features-that-you-need-to-know-before-learning-react-4hmn</link>
      <guid>https://dev.to/badr21/eight8-es6ecmascript-6-features-that-you-need-to-know-before-learning-react-4hmn</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;ES6, also known as ECMAScript 2015, is the sixth version of the ECMAScript language specification. ECMAScript is a standardized scripting language specification on which many programming languages, including JavaScript, are based. ES6 was a major update to the language, introducing several new features and syntax enhancements that made JavaScript more powerful, flexible, and easier to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  ES6 Features
&lt;/h2&gt;

&lt;p&gt;React is built using JavaScript, and many of the features used in React are features of ES6. Here are some ES6 features that are particularly useful to know before learning React:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1- let and const&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ES6 introduced two new ways to declare variables in JavaScript: let and const. These are block-scoped variables that have a different scope than variables declared with var.&lt;/p&gt;

&lt;p&gt;The main difference between const and let is that const variables are read-only, meaning their value cannot be reassigned once they are declared, whereas let variables can be reassigned.&lt;/p&gt;

&lt;p&gt;Here is an example to illustrate the difference between const and let:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let favoriteColor = “blue”;
const age = 25;

console.log(favoriteColor); // Output: "blue"
console.log(age); // Output: 25

favoriteColor = "green";
// age = 26; // This will result in an error because age is a constant and its value cannot be reassigned.

console.log(favoriteColor); // Output: "green"
console.log(age); // Output: 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we declare a variable called favoriteColor using let and initialize it to “blue”. We also declare a constant called age and initialize it to 25.&lt;/p&gt;

&lt;p&gt;We then log the initial values of favoriteColor and age to the console, which outputs “blue” and 25, respectively.&lt;/p&gt;

&lt;p&gt;Next, we reassign the value of favoriteColor to “green”, which is allowed because favoriteColor was declared using let. However, we try to reassign the value of age to 26, which would result in an error because age was declared using const and its value cannot be reassigned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- Arrow functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arrow functions are a new syntax for writing JavaScript functions introduced in ECMAScript 6 (ES6). Arrow functions provide a more concise syntax for defining functions compared to traditional function expressions. They are commonly used in modern JavaScript development, particularly in functional programming and in writing code that uses callbacks, event listeners, and promises.&lt;/p&gt;

&lt;p&gt;Here is an example of an arrow function that returns the sum of two numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; {
  return a + b;
};

console.log(add(2, 3)); // Output: 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrow functions also have some unique features, such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- 1- Lexical this binding&lt;/strong&gt;: Arrow functions do not bind their own ‘this’ value, but instead inherit ‘this’ from the surrounding context in which they were defined. This can be useful in certain situations, such as when working with event listeners or in functional programming.&lt;/p&gt;

&lt;p&gt;Here is an example that demonstrates the use of the ‘this ’keyword in an arrow function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myObject = {
  value: 10,
  getValue: function() {
    const innerFunc = () =&amp;gt; {
      console.log(this.value);
    };
    innerFunc();
  }
};

myObject.getValue(); // Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have an object myObject with a property value set to 10, and a method getValue that defines an inner arrow function innerFunc. When getValue is called, it invokes innerFunc which logs the value of this.value to the console.&lt;/p&gt;

&lt;p&gt;Because innerFunc is an arrow function, it inherits this from the surrounding context in which it was defined — in this case, the getValue method of myObject. As a result, this.value refers to the value property of myObject, which has a value of 10.&lt;/p&gt;

&lt;p&gt;If we had used a traditional function expression instead of an arrow function for innerFunc, this keyword inside the function would have referred to the global window object (in a browser environment), or the undefined value (in strict mode). This is because this keyword in a traditional function expression is determined at the time the function is called, not at the time it is defined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- 2- Implicit return&lt;/strong&gt;: If the function body contains only one statement, and that statement is an expression, the return keyword and curly braces can be omitted. The expression will be implicitly returned.&lt;/p&gt;

&lt;p&gt;Here is an example of an arrow function with an implicit return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const double = x =&amp;gt; x * 2;

console.log(double(5)); // Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3- Template literals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Template literals are a feature of the JavaScript programming language that allows for the creation of strings that can contain expressions and variables in a concise and readable manner. They are denoted by backticks () instead of the traditional single quotes (‘) or double quotes (“).&lt;/p&gt;

&lt;p&gt;Template literals allow for the embedding of expressions in the string using the ${} syntax, which allows for the evaluation of JavaScript expressions within the string. This means that the values of variables or the results of expressions can be inserted directly into the string without having to concatenate them using the + operator.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = ‘John’;
const age = 30;

console.log(`My name is ${name} and I am ${age} years old.`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output:&lt;br&gt;
My name is John and I am 30 years old.&lt;/p&gt;

&lt;p&gt;Template literals can also span multiple lines, making it easier to write multi-line strings without having to use escape characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4- Destructuring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Destructuring allows you to extract values from arrays or properties from objects and assign them to distinct variables using a syntax that resembles the structure of the data being extracted. It provides a concise way to extract only the required values from data structures, making the code more readable and easier to understand.&lt;/p&gt;

&lt;p&gt;In array destructuring, you can extract values from an array and assign them to variables by enclosing the variables in square brackets and using the array name on the right-hand side of the equals sign.&lt;/p&gt;

&lt;p&gt;Here’s an example of destructuring an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create an array of numbers
const numbers = [1, 2, 3, 4, 5];

// Destructure the first and last elements of the array
const [first, , , , last] = numbers;

// Output the first and last elements
console.log(`The first element is ${first}`); // Output: The first element is 1
console.log(`The last element is ${last}`); // Output: The last element is 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In object destructuring, you can extract values from an object and assign them to variables by enclosing the variables in curly braces and using the object name on the right-hand side of the equals sign.&lt;/p&gt;

&lt;p&gt;Here’s an example of destructuring an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Create an object representing a person
const person = {
  firstName: 'John',
  lastName: 'Doe',
  age: 30,
  address: {
    street: '123 Main St',
    city: 'Anytown',
    state: 'CA',
    zip: '12345'
  }
};

// Destructure the person object to get the firstName, lastName, and city properties
const { firstName, lastName, address: { city } } = person;

// Output the values of the firstName, lastName, and city variables
console.log(`My name is ${firstName} ${lastName}, and I live in ${city}.`); // Output: My name is John Doe, and I live in Anytown.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5- Spread syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The spread syntax allows you to spread the elements of an array or an object into another array or object. This can make it easier to merge arrays or objects or to pass arguments to a function. It is denoted by the ellipsis (…) operator and can be used in a variety of contexts to provide a concise and powerful way of working with data.&lt;/p&gt;

&lt;p&gt;When used with arrays, the spread syntax can be used to create a new array that combines the elements of multiple arrays. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = […arr1, …arr2];

console.log(combined); // [1, 2, 3, 4, 5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The spread syntax can also be used to copy an array, which is useful when you need to modify an array without affecting the original. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const original = [1, 2, 3];
const copy = […original];
copy.push(4);

console.log(original); // [1, 2, 3]
console.log(copy); // [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When used with objects, the spread syntax can be used to create a new object that combines the properties of multiple objects. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const obj1 = { foo: 'bar' };
const obj2 = { baz: 'qux' };
const combined = { …obj1, …obj2 };

console.log(combined); // { foo: 'bar', baz: 'qux' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The spread syntax can also be used to add new properties to an object or overwrite existing properties. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const original = { foo: 'bar' };
const copy = { …original, baz: 'qux' };

console.log(original); // { foo: 'bar' }
console.log(copy); // { foo: 'bar', baz: 'qux' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6- Promises&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A promise is an object representing the eventual completion or failure of an asynchronous operation. It is a way of handling asynchronous code that allows developers to write code that is more readable and easier to reason about.&lt;/p&gt;

&lt;p&gt;A promise has three states: pending, fulfilled, or rejected.&lt;/p&gt;

&lt;p&gt;When a promise is pending, it means that the asynchronous operation has not yet been completed.&lt;/p&gt;

&lt;p&gt;When a promise is fulfilled, it means that the operation has been completed successfully, and the promise returns a value.&lt;/p&gt;

&lt;p&gt;When a promise is rejected, it means that the operation has failed, and the promise returns a reason for the failure.&lt;/p&gt;

&lt;p&gt;Here’s an example of using promises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addNumbers(a, b) {
  return new Promise((resolve, reject) =&amp;gt; {
    if (typeof a !== 'number' || typeof b !== 'number') {
      reject('Both arguments must be numbers.');
    } else {
    const sum = a + b;
    resolve(sum);
    }
  });
}
addNumbers(2, 3)
.then(sum =&amp;gt; {
  console.log(`The sum of 2 and 3 is ${sum}.`);
})
.catch(error =&amp;gt; {
  console.error(error);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a function called addNumbers() that takes two arguments and returns a promise. Inside the promise, we check if both arguments are numbers and if so, we calculate their sum and resolve the promise with the result. If either argument is not a number, we reject the promise with an error message.&lt;/p&gt;

&lt;p&gt;We then call addNumbers() with arguments of 2 and 3, and chain a then() method to log the resulting sum to the console when the promise is fulfilled. If there is an error, the catch() method is called and the error message is logged to the console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7- Modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modules are a standardized way of organizing and sharing code between files and projects. A module is a self-contained block of code that can define variables, functions, classes, and other objects, and can selectively expose these objects to other parts of the application.&lt;/p&gt;

&lt;p&gt;Modules allow you to import and export code between different files and namespaces. You can now export a default value from a module using the default keyword, or export multiple named values using the export keyword.&lt;/p&gt;

&lt;p&gt;Here are examples of both default exports and named exports&lt;/p&gt;

&lt;p&gt;Default export example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// math.js
const add = (a, b) =&amp;gt; a + b;

export default add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a function called add and export it as the default export of the math.js module using the export default syntax.&lt;/p&gt;

&lt;p&gt;We can then import the add function in another module like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js
import add from './math.js';

console.log(add(2, 3)); // logs 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this importing module, we use the import statement to import the default export from the math.js module. Since we used export default, we can assign the imported object to any variable name we want, in this case, add.&lt;/p&gt;

&lt;p&gt;Named export example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// utils.js
export const formatName = (firstName, lastName) =&amp;gt; `${lastName}, ${firstName}`;

export const formatNumber = (num) =&amp;gt; {
  const formatted = num.toLocaleString('en-US', { style: 'decimal' });
  return `$${formatted}`;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define two functions called formatName and formatNumber and export them as named exports of the utils.js module using the export syntax.&lt;/p&gt;

&lt;p&gt;We can then import the named exports in another module like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js
import { formatName, formatNumber } from './utils.js';

console.log(formatName('John', 'Doe')); // logs "Doe, John"
console.log(formatNumber(123456.78)); // logs "$123,456.78"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this importing module, we use the import statement to import the named exports from the utils.js module. We use curly braces {} to specify which exports we want to import, and we use the same names that we used in the exporting module (formatName and formatNumber in this case).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8- Default parameters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Default parameters allow for the specification of default values for function parameters. If a function is called with a missing or undefined value for a parameter with a default value, the default value is used instead.&lt;/p&gt;

&lt;p&gt;Default parameters are denoted by assigning a default value to a function parameter in the function definition. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name = 'World') {
  console.log(`Hello, ${name}!`);
}

greet(); // outputs "Hello, World!"
greet('John'); // outputs "Hello, John!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Default parameters can be used with any type of function parameter, including object and array destructuring. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function processUser({ name = 'Unknown', age = 0 }) {
  console.log(`The user ${name} is ${age} years old.`);
}

processUser({}); // outputs "The user Unknown is 0 years old."
processUser({ name: 'John', age: 30 }); // outputs "The user John is 30 years old."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, understanding ES6 features is essential to effectively work with React. The let and const, arrow functions, template literals, destructuring, spread syntax, promises, modules, and default parameters, are some of the most commonly used features in React development. Learning these features will not only make your code more concise and readable but also increase your productivity by providing a more modern syntax for creating robust and scalable React applications. As React continues to evolve, it’s important to keep up with the latest ES6 features to stay up-to-date with the best practices in the industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1- Async/await&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Async/await is a feature in modern JavaScript that simplifies the process of working with asynchronous code. It was introduced in ECMAScript 2017 (ES8) and is built on top of promises, another feature that was added in ES6.&lt;/p&gt;

&lt;p&gt;In traditional asynchronous programming, callbacks or promises are used to handle the response from an asynchronous operation. However, this can lead to callback hell or complicated chains of promises. Async/await provides a simpler, more readable syntax for working with asynchronous code.&lt;/p&gt;

&lt;p&gt;Here’s how async/await works:&lt;/p&gt;

&lt;p&gt;The async keyword is used to define a function that returns a promise. The async keyword essentially turns the function into a generator function that yields promises.&lt;/p&gt;

&lt;p&gt;The await keyword is used to pause the execution of the async function until a promise is fulfilled. When an await expression is encountered, the function is paused and control is returned to the event loop, allowing other code to execute. When the promise is fulfilled, the function resumes execution and the result of the promise is returned.&lt;/p&gt;

&lt;p&gt;Here’s an example of an async function that uses await to handle a network request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchUserData(userId) {
  const response = await fetch(`https://api.example.com/users/${userId}`);
  const userData = await response.json();
  return userData;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the fetchUserData function is defined as an async function using the async keyword. Inside the function, we use the await keyword to pause the execution of the function until the fetch call completes and returns a response object. We then use await again to pause the execution of the function until the response has been converted to JSON using the json() method. Finally, we return the userData object.&lt;/p&gt;

&lt;p&gt;Using async/await, we can write asynchronous code that looks and behaves like synchronous code, making it easier to read and understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- Filter and map&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Filter and map are two common higher-order functions, they are features of ECMAScript 5 (ES5) that are used to manipulate arrays.&lt;/p&gt;

&lt;p&gt;Filter is used to create a new array with all elements that pass a certain test (predicate) provided as a callback function. The filter method does not modify the original array and returns a new array with the filtered elements.&lt;/p&gt;

&lt;p&gt;Here’s an example of using filter to create a new array of even numbers from an array of integers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const evenNumbers = numbers.filter(number =&amp;gt; number % 2 === 0);

console.log(evenNumbers); // [2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define an array of numbers and use the filter method to create a new array evenNumbers that contains only the even numbers from the original array. We pass a callback function to filter that tests each element in the array to see if it is even, and returns true or false accordingly.&lt;/p&gt;

&lt;p&gt;Map, on the other hand, is used to create a new array by applying a transformation function to each element in the original array. The map method does not modify the original array and returns a new array with the transformed elements.&lt;/p&gt;

&lt;p&gt;Here’s an example of using map to create a new array of squared numbers from an array of integers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const squaredNumbers = numbers.map(number =&amp;gt; number * number);

console.log(squaredNumbers); // [1, 4, 9, 16, 25]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define an array of numbers and use the map method to create a new array squaredNumbers that contains the squared value of each number in the original array. We pass a callback function to map that returns the squared value of each number.&lt;/p&gt;

&lt;p&gt;In React, you often need to manipulate arrays of data to render components, and filter and map are commonly used to transform and filter data before rendering. Asynchronous programming is also an essential part of React, as it allows components to interact with APIs and other data sources without blocking the main thread.&lt;/p&gt;

&lt;p&gt;Filter, map, and async/await are not ES6 features, but they are still very important concepts to understand when working with modern web development frameworks such as React.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>es6</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Create a React app with Vite and deploy it on GitHub</title>
      <dc:creator>Badreddine Boudaoud</dc:creator>
      <pubDate>Sun, 26 Mar 2023 13:13:39 +0000</pubDate>
      <link>https://dev.to/badr21/create-a-react-app-with-vite-and-deploy-it-on-github-224n</link>
      <guid>https://dev.to/badr21/create-a-react-app-with-vite-and-deploy-it-on-github-224n</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Deploying a React app on GitHub can be a great way to share your application with others and make it available online. In this article, we will walk through the steps required to create a React app with Vite and deploy it on GitHub.&lt;/p&gt;

&lt;p&gt;React is a popular open-source front-end JavaScript library, used for building user interfaces for web applications quickly and efficiently with significantly less code than you would with vanilla JavaScript.It was developed by Facebook and is now maintained by Facebook and a community of individual developers and companies.&lt;/p&gt;

&lt;p&gt;Vite is a build tool and development server that is used to build modern web applications. It is designed to be fast, lightweight, and easy to use. Vite is developed by Evan You, the creator of Vue.js, and is heavily inspired by the development experience provided by Vue.js.&lt;/p&gt;

&lt;p&gt;GitHub is a web-based platform that provides a wide range of collaborative tools for software development teams. It is a popular platform for hosting, sharing, and collaborating on code repositories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow along with this tutorial, you will need:&lt;/p&gt;

&lt;p&gt;1- &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; installed on your system Node &amp;gt;= 16.&lt;/p&gt;

&lt;p&gt;2- A &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; account.&lt;/p&gt;

&lt;p&gt;When developing a React app, one important step is to deploy the project to a hosting service so that others can access it. GitHub is a popular platform for hosting and sharing code, and it also provides a simple way to deploy React projects using ‘gh-Pages’.‘gh-pages’ is a package for Node.js that allows you to easily deploy a static website to GitHub Pages.&lt;/p&gt;

&lt;p&gt;With this being said, let’s begin the tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a GitHub repository
&lt;/h2&gt;

&lt;p&gt;The first step is to create a GitHub repository for your project. If you already have a repository for your project, you can skip this step. To create a new repository, follow these steps:&lt;/p&gt;

&lt;p&gt;1- Go to GitHub.com and log in to your account.&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%2Fqsuhumcp086thk6w92bk.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%2Fqsuhumcp086thk6w92bk.png" alt="GitHub log in page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Click on the “+” icon in the top right corner and select “New repository”.&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%2F3rks9y8tswxqcpwuflca.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%2F3rks9y8tswxqcpwuflca.png" alt="GitHub repository options"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Give your repository a name, and add a brief description if desired. I will name it react-project.&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%2Ft0elr74hg1we6fetd2em.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%2Ft0elr74hg1we6fetd2em.png" alt="Create new repository page, add the repository name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- Choose whether to make the repository public or private.&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%2Foka6id0qjyknollmutb8.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%2Foka6id0qjyknollmutb8.png" alt="Create new repository page, choose public or private"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- Click on the “Create repository” button.&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%2Ffq3obaphnpq0ik54rbvy.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%2Ffq3obaphnpq0ik54rbvy.png" alt="Create new repository page, click create repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6- After clicking on Create repository you will see this page.&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%2Fczbd9u8dvt68mo9bz5ur.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%2Fczbd9u8dvt68mo9bz5ur.png" alt="The page after creating new repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a React app with Vite
&lt;/h2&gt;

&lt;p&gt;If you have not yet created a React app, you can use Vite. With Vite, you can create a React app with less build time and the files in the folder are minimal with optimal output. To do this, you will need to have Node.js installed on your computer. Here are the steps:&lt;/p&gt;

&lt;p&gt;1- Create a folder and name it whatever you want.&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%2Fbz1ufirlvm8xl6wez878.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%2Fbz1ufirlvm8xl6wez878.png" alt="Create a folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Open the folder with your preferred IDE, I will be using Visual Studio Code.&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%2Faotpsu37ub5xd6gsy4wn.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%2Faotpsu37ub5xd6gsy4wn.png" alt="Open folder with visual studio code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Make sure to open your terminal in that folder.&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%2Fy1b02ahkuc6uoi2hrak4.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%2Fy1b02ahkuc6uoi2hrak4.png" alt="Open terminal in visual studio code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- To install Vite, you need to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest
&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%2Fw9beyejoih35srfvoxpl.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%2Fw9beyejoih35srfvoxpl.png" alt="In the terminal, run npm create vite@latest"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- After running npm create vite@latest, you will be asked to put a project name.&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%2Fnuop3zantf2i3ynyhgfb.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%2Fnuop3zantf2i3ynyhgfb.png" alt="In the terminal, write the project name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will name it react-project.&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%2Fiy8fwterasrovkl8qyrz.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%2Fiy8fwterasrovkl8qyrz.png" alt="In the terminal, the project is named react-project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6- You will be asked to select a framework. Since this project is a React project, you need to select React from the list.&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%2Fjllayz60gla7rtnk61x1.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%2Fjllayz60gla7rtnk61x1.png" alt="In the terminal, select React from the list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;7- You will also be asked to choose a variant. I will choose JavaScript.&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%2F3d3m3nyb6u0v8eoahuwc.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%2F3d3m3nyb6u0v8eoahuwc.png" alt="In the terminal, choose a variant"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;8- Change your directory to the react-project by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd &amp;lt;Your project name&amp;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%2F2hkjn517wykxqh811mbz.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%2F2hkjn517wykxqh811mbz.png" alt="In the terminal, run cd &amp;lt;your project name&amp;gt;"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my example, I will run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd react-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;9- To install all the dependencies React needs run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&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%2Fr6a1gkwdw3xqsm1jlfwb.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%2Fr6a1gkwdw3xqsm1jlfwb.png" alt="In the terminal, run npm install"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;10- Wait for the installation to finish.&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%2Fvlcjzmknl7gspbn0a7jx.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%2Fvlcjzmknl7gspbn0a7jx.png" alt="In the terminal, wait for the installation to finish"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install the gh-pages package
&lt;/h2&gt;

&lt;p&gt;After the dependencies are installed completely, you need to install ‘gh-Pages’ package.&lt;/p&gt;

&lt;p&gt;1- To install ‘gh-pages’ run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev gh-pages
&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%2Ff31jc0k1vu5wlnpw1n6t.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%2Ff31jc0k1vu5wlnpw1n6t.png" alt="In the terminal, run npm install — save-dev gh-pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Wait for the installation to finish.&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%2Fwr9ah19ua501x0wmpf60.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%2Fwr9ah19ua501x0wmpf60.png" alt="In the terminal, wait for the installation to finish"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Update the package.json file
&lt;/h2&gt;

&lt;p&gt;The ‘gh-pages’ package uses the homepage field in the package.json file to determine where to deploy your app. To update the package.json file, follow these steps:&lt;/p&gt;

&lt;p&gt;1- Add a homepage field with the URL of your GitHub repository in the following format:&lt;/p&gt;

&lt;p&gt;“homepage”: https://.github.io//&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%2Fr6u6dkmjg445ysh4y1bl.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%2Fr6u6dkmjg445ysh4y1bl.png" alt="Update the package.json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- In the scripts tag add:&lt;/p&gt;

&lt;p&gt;“predeploy”: “npm run build”,&lt;/p&gt;

&lt;p&gt;“deploy”: “gh-pages -d dist”.&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%2Fssxtw2kkdrrrog9jdrud.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%2Fssxtw2kkdrrrog9jdrud.png" alt="Update the package.json file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The “predeploy” and “deploy” scripts are used to automate the deployment process.&lt;/p&gt;

&lt;p&gt;3- Save the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update the vite.config.js file
&lt;/h2&gt;

&lt;p&gt;1- Add base: “//”, to vite.config.js, in my example it would be base: “/react-project/”&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%2F3qaeg9rrcpx5ezjoelhs.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%2F3qaeg9rrcpx5ezjoelhs.png" alt="Update vite.config.js file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- save the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Push the React app to GitHub
&lt;/h2&gt;

&lt;p&gt;With the ‘gh-Pages’ package installed and the package.json and the vite.config.js files updated&lt;/p&gt;

&lt;p&gt;1- Initialize a Git repository by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&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%2F5664zp493odo9tfftfd9.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%2F5664zp493odo9tfftfd9.png" alt="In the terminal, Initialize a Git repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will create a new Git repository in your project’s directory.&lt;/p&gt;

&lt;p&gt;2- Add all the files in your project to the Git repository by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&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%2Fv3k8z97kpi8s99bbx8rr.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%2Fv3k8z97kpi8s99bbx8rr.png" alt="In the terminal, Add all the files in your project to the Git repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will stage all the files in your project for committing.&lt;/p&gt;

&lt;p&gt;3- Commit the changes by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Initial commit"
&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%2F7ugzhelii608m07bkuyt.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%2F7ugzhelii608m07bkuyt.png" alt="In the terminal, Commit the changes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will create a new commit in the Git repository with the message “Initial commit”.&lt;/p&gt;

&lt;p&gt;4- Rename the master branch to main by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -M main
&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%2Fttuzt2ramjwqpckvwm1t.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%2Fttuzt2ramjwqpckvwm1t.png" alt="In the terminal, Rename the master branch to main"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5- Add the remote repository by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin &amp;lt;repository URL&amp;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%2Fys1gw5q4qyurdup1exhv.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%2Fys1gw5q4qyurdup1exhv.png" alt="The GitHub repository page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the repository URL in the GitHub repository that you’ve created&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%2Fem5b3suyhi4qf6n8dna6.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%2Fem5b3suyhi4qf6n8dna6.png" alt="In the terminal, add the remote repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will add the GitHub repository as a remote for your local Git repository.&lt;/p&gt;

&lt;p&gt;6- Finally, push the changes to the remote repository by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin master
&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%2Fk66pxr8iw741f9u042bz.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%2Fk66pxr8iw741f9u042bz.png" alt="In the terminal, push the changes to the remote repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will push the initial commit of your local Git repository to the GitHub repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy your React app
&lt;/h2&gt;

&lt;p&gt;With the React app pushed to Github, you can now deploy your React app. &lt;br&gt;
1- Run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&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%2Fayqfdr1dlebvjla4qf50.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%2Fayqfdr1dlebvjla4qf50.png" alt="In the terminal, deploy the React app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2- Wait for the deployment to finish.&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%2Foqv0kypv1eb1lqevfz1s.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%2Foqv0kypv1eb1lqevfz1s.png" alt="In the terminal, the deployment is finished"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Access your app
&lt;/h2&gt;

&lt;p&gt;Once the deployment is complete, you can access your React app by going to the URL specified in the homepage field of your package.json file. Typically, the URL will be in the form of https://.github.io//.&lt;/p&gt;

&lt;p&gt;Or you can find the URL by clicking on the repository setting.&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%2F0gfaifdpgap4aoi6l5e4.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%2F0gfaifdpgap4aoi6l5e4.png" alt="The GitHub repository setting page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click on pages.&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%2Fkf3iiny4an2ej37ec8tk.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%2Fkf3iiny4an2ej37ec8tk.png" alt="In the GitHub repository page click on pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the URL.&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%2Fedq9hd7or9eu83d86vhg.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%2Fedq9hd7or9eu83d86vhg.png" alt="The GitHub repository setting pages page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the URL, and here is your deployed React app.&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%2Ffo347w624kufje21vgi4.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%2Ffo347w624kufje21vgi4.png" alt="The project page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Deploying a React app to GitHub Pages using the ‘gh-Pages’ package is a simple and convenient way to share your work with others. By following the steps outlined in this article, you can easily deploy your own React projects to GitHub Pages and share your work with the world.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>vite</category>
      <category>github</category>
    </item>
  </channel>
</rss>
