<?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>Forem: Shem Jaoko</title>
    <description>The latest articles on Forem by Shem Jaoko (@shemjay).</description>
    <link>https://forem.com/shemjay</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%2F864444%2Fb4917cab-eaa1-452c-bf99-20e1e3016f44.png</url>
      <title>Forem: Shem Jaoko</title>
      <link>https://forem.com/shemjay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shemjay"/>
    <language>en</language>
    <item>
      <title>JavaScript Assignment Operators💻🧮 Explained with Canvas API🎨</title>
      <dc:creator>Shem Jaoko</dc:creator>
      <pubDate>Sun, 01 Jan 2023 20:51:42 +0000</pubDate>
      <link>https://forem.com/shemjay/javascript-assignment-operators-explained-with-canvas-api-mon</link>
      <guid>https://forem.com/shemjay/javascript-assignment-operators-explained-with-canvas-api-mon</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;1 JavaScript Assignment Operators&lt;br&gt;
2 Code Workplace&lt;br&gt;
3 Questions&lt;br&gt;
4 Answers&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Assignment Operators brief overview
&lt;/h2&gt;

&lt;p&gt;The Assignment operator is  &lt;code&gt;equal (=)&lt;/code&gt; which assigns the value of right-hand operand to its left-hand operand. That is if a = b assigns the value of b to a.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;+=&lt;/code&gt; Addition Assignment: This operator adds the value to the right operand to a variable and assigns the result to the variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-=&lt;/code&gt; Subtraction assignment: Subtracts the value on the right from the variable value on the left, and returns the new variable value.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*=&lt;/code&gt; Multiplication assignment: Multiplies the variable value on the left by the value on the right, and returns the new variable value.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/=&lt;/code&gt; Division Assignment: This operator divides a variable by the value of the right operand and assigns the result to the variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;%=&lt;/code&gt; Remainder/Modulus Assignment: This operator divides a variable by the value of the right operand and assigns the remainder to the variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4gYRbYr_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1dqv7xordn7hm6dzmwx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4gYRbYr_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1dqv7xordn7hm6dzmwx.jpg" alt="javaScript operators" width="365" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;image credit:&lt;/em&gt; &lt;code&gt;http://www.corelangs.com/js/basics/operators.html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's carry out an exercise to manipulate some numbers and operators to change the size of a box. The box is drawn using a browser API called the Canvas API. There is no need to worry about how this works — just concentrate on the math for now. The width and height of the box (in pixels) are defined by the variables x and y, which are initially both given a value of 50.&lt;/p&gt;

&lt;p&gt;The following questions are obtained from the MDN JavaScript Documentation which you can find &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Math#active_learning_sizing_a_canvas_box"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Workplace
&lt;/h2&gt;

&lt;p&gt;Practice working on the coding questions using this workspace. Then check the answers if you need help💯&lt;br&gt;
JSitor: &lt;a href="https://jsitor.com/mxtwfi8OL5"&gt;https://jsitor.com/mxtwfi8OL5&lt;/a&gt;&lt;br&gt;
You only edit these two lines for this exercise:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HtjBFONW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbaha9mxfindvz304bkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HtjBFONW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbaha9mxfindvz304bkg.png" alt="two lines to edit" width="336" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Question 1
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates x so the box is still 50px wide, but the 50 is calculated using the numbers 43 and 7 and an arithmetic operator.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h3&gt;
  
  
  Question 2
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates y so the box is 75px high, but the 75 is calculated using the numbers 25 and 3 and an arithmetic operator.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h3&gt;
  
  
  Question 3
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates x so the box is 250px wide, but the 250 is calculated using two numbers and the remainder (modulo) operator.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h3&gt;
  
  
  Question 4
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates y so the box is 150px high, but the 150 is calculated using three numbers and the subtraction and division operators.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h3&gt;
  
  
  Question 5
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates x so the box is 200px wide, but the 200 is calculated using the number 4 and an assignment operator.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h3&gt;
  
  
  Question 6
&lt;/h3&gt;

&lt;p&gt;Change the line that calculates y so the box is 200px high, but the 200 is calculated using the numbers 50 and 3, the multiplication operator, and the addition assignment operator.&lt;/p&gt;

&lt;p&gt;view the possible solution here&lt;/p&gt;

&lt;h2&gt;
  
  
  Answers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Answer 1
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x = (43 + 7);&lt;br&gt;
y = 50;&lt;/code&gt;&lt;br&gt;
simple right? The total, of course, will add up to 50 so the square will not change in size:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FFMPdYU8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/goddb67t806xfdna7a8p.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FFMPdYU8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/goddb67t806xfdna7a8p.JPG" alt="Solution for Question 1" width="321" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 1&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer 2
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x = 50;&lt;br&gt;
y = (25 + 3);&lt;/code&gt;&lt;br&gt;
Just like the previous question this merely involves a simple subtraction operation to get the desired result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NW8RL-yS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8idxaxthx3zy9k08ji2l.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NW8RL-yS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8idxaxthx3zy9k08ji2l.JPG" alt="Solution for Question 2" width="315" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 2&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer 3
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x = 750 % 500;&lt;br&gt;
y = 50;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And voila! By dividing 750 by 500 we get a remainder of 250 exactly what we wanted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2aFaqyxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewxhqpp4scckcfm84cbv.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2aFaqyxL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewxhqpp4scckcfm84cbv.JPG" alt="Solution for Question 3" width="314" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 3&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer 4
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x = 50;&lt;br&gt;
y = 500 / 2 - 100;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Not much explanation needed here. Our three numbers are 500, 100 and 2. When we divide 500 by 2 we get 250 which we then subtract 100 from to get 150:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jEUSNrD4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2itf33rsoxy18zvgfqc.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jEUSNrD4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2itf33rsoxy18zvgfqc.JPG" alt="Solution for Question 4" width="321" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 4&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer 5
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x *= 4;&lt;br&gt;
y = 50;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we already know, the &lt;code&gt;*=&lt;/code&gt; operator multiplies the variable value on the left by the value on the right, and returns the new variable value. Since x has been assigned 50 it will multiply it by 4 to get 200:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYUFjlYW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n7n5cqf9e3hwtkwjta9.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYUFjlYW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n7n5cqf9e3hwtkwjta9.JPG" alt="Solution for Question 5" width="317" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 5&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer 6
&lt;/h3&gt;

&lt;p&gt;Possible solution:&lt;br&gt;
&lt;code&gt;x = 50;&lt;br&gt;
y *= 50 + 3;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here we have merely used the &lt;code&gt;*=&lt;/code&gt; operator then added our two numbers 50 + 3 to get our solution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bb-4yXHq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m00x7pmhylsk5vku5huf.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bb-4yXHq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m00x7pmhylsk5vku5huf.JPG" alt="Solution for Question 6" width="316" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;back to question 6&lt;/p&gt;

&lt;p&gt;You can practice making more complex scenarios with assignment operators. To read more on JavaScript assignment operators, take a look at this article on &lt;a href="https://javascript.info/operators"&gt;javaScript.info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this article useful or if you spotted an error drop me a line in the comments I'd love to hear from you😁&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Defer vs Async Attributes</title>
      <dc:creator>Shem Jaoko</dc:creator>
      <pubDate>Wed, 01 Jun 2022 07:02:03 +0000</pubDate>
      <link>https://forem.com/shemjay/defer-vs-async-attributes-4p2k</link>
      <guid>https://forem.com/shemjay/defer-vs-async-attributes-4p2k</guid>
      <description>&lt;p&gt;Async and Defer may look to have the same function but they are actually quite different. Usually its best to use Defer even though Async looks tastier😁. Though that's not to say you can't use Async. In this post I'll speak about what they both do and when you should use either one. So, let's begin.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;SCRIPT TAG IN THE HEAD WITH NO ASYNC OR DEFER&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
Before we begin looking at script loading with async and defer, lets look at a script tag with none of them loaded in the head of the document. &lt;/p&gt;

&lt;p&gt;An example could look 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;&amp;lt;head&amp;gt;
&amp;lt;script src = "index.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;When the browser is typically parsing an HTML document, it will stop parsing the HTML doc the moment it encounters a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in the head. The browser will be forced to download parse the entire &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag and evaluate it. Only then can the HTML parsing continue.&lt;/p&gt;

&lt;p&gt;Here is a diagram I made to illustrate:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9cCeGbp2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83jnj1k9ydf3ap3xbg0n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9cCeGbp2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83jnj1k9ydf3ap3xbg0n.jpg" alt="A diagram of html parsing with script tag in the head" width="512" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem is that large scripts can cause the DOM to stop loading. This can provide a very unsatisfactory user experience.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;SCRIPT TAG IN THE BODY WITH NO ASYNC OR DEFER&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
However, when the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; is placed at the end of the body tag, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;JS Script Loading&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;p&amp;gt;Some Content&amp;lt;/p&amp;gt;
&amp;lt;script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML parsing will be carried out first then the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; is fetched and executed like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--enOnAByf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qzybr6ndexd8txm4q66.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--enOnAByf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qzybr6ndexd8txm4q66.jpg" alt="A diagram of html parsing with script tag in the body" width="512" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;SCRIPT LOADING IN THE HEAD WITH ASYNC&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
When loading &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; with Async the browser will fetch and download the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; as it is parsing the HTML. It will only pause the HTML parsing when it wants to execute the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hIkt5TQG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dt7w1i7q7h1pkdvsu3po.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hIkt5TQG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dt7w1i7q7h1pkdvsu3po.jpg" alt="A diagram of html parsing with script tag and async attribute" width="512" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;SCRIPT LOADING IN THE HEAD WITH DEFER&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
Jus like with Async, Defer will fetch and download the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; as it parsing the HTML. However, Defer is different from Async in that it will complete the HTML parsing before it executes the script:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ypD1lEHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmkavtnjhx11f65m2vxq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ypD1lEHv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmkavtnjhx11f65m2vxq.jpg" alt="A diagram of html parsing with script tag and defer attribute" width="512" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;DEFER vs ASYNC&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
Both Asnyc and Defer load scripts without blocking the DOM, but they have two main differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Async does not load scripts in order while defer does.
This means that if you have three scripts loaded like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script async src="script1.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script async src="script2.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script async src="script3.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Async can randomize the order of execution while defer will respect the sequence order. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defer waits for the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;DOM (Document Object Model)&lt;/a&gt; while Async does not. Defer will wait for the DOM to fully load before it executes. Async will not. This means if your &lt;code&gt;script&lt;/code&gt; requires the DOM you should use defer. If you use Async in this scenario you stand the chance that  element you need cannot be found which can lead to bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some general rules on when to use either:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the script does not rely on any other scripts or if it does not require the DOM then you can use &lt;strong&gt;Async&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If you want to load scripts in the middle of your HTML you can use &lt;strong&gt;Async&lt;/strong&gt;. Since the DOM is already present, the &lt;code&gt;script&lt;/code&gt; can be executed immediately without any problems.&lt;/li&gt;
&lt;li&gt;You should use &lt;strong&gt;defer&lt;/strong&gt; for all other scripts because:&lt;/li&gt;
&lt;li&gt;It gets loaded ASAP which reduces load time.&lt;/li&gt;
&lt;li&gt;It respects the script order letting you structure which script will come first.&lt;/li&gt;
&lt;li&gt;It only executes once the DOM is ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
In conclusion, it usually better to use defer because it has more  advantages over Async in most use cases even though Async can sound much better.&lt;/p&gt;

&lt;p&gt;If you found this article useful or if you spotted an error drop me a line in the comments i'd love to hear you opnions😁. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>html</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
