<?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: Ike-Nwako Chukwudi</title>
    <description>The latest articles on DEV Community by Ike-Nwako Chukwudi (@inchukwudi).</description>
    <link>https://dev.to/inchukwudi</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%2F683918%2Ffc7f2056-4a84-4035-b261-127a229c552a.png</url>
      <title>DEV Community: Ike-Nwako Chukwudi</title>
      <link>https://dev.to/inchukwudi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/inchukwudi"/>
    <language>en</language>
    <item>
      <title>Setting up an Angular Project</title>
      <dc:creator>Ike-Nwako Chukwudi</dc:creator>
      <pubDate>Fri, 07 Jan 2022 21:20:08 +0000</pubDate>
      <link>https://dev.to/inchukwudi/setting-up-an-angular-project-4nl</link>
      <guid>https://dev.to/inchukwudi/setting-up-an-angular-project-4nl</guid>
      <description>&lt;p&gt;Angular, today, is one of the popular front-end platforms in use. Angular provides you with various tools to use for standard software development. Alongside these tools, there are design patterns that help you build your software in a maintainable way. This makes Angular robust and makes software development easy.&lt;/p&gt;

&lt;p&gt;Some of the reasons you might want to use Angular are it is built with TypeScript, applications built with it are mobile and desktop ready. Also, it has a large ecosystem and is actively maintained in contrast to AngularJS whose active support ended December 31, 2021.&lt;/p&gt;

&lt;p&gt;Do not get off track by the “robustness” of Angular, is neither complex to set up nor use on your machine. Setting up an Angular project will require us to have the Angular CLI installed and this is done easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Node.Js
&lt;/h2&gt;

&lt;p&gt;To start, we need to download and install Node.Js. If you have this installed, you can proceed to the next step. You might ask, why? Node.Js allows JavaScript to run on our machines and it also gives us access to the Node Package Manager (NPM) so we can download packages our software needs.&lt;/p&gt;

&lt;p&gt;To download Node.Js, run a &lt;a href="https://www.google.com/search?q=node+js" rel="noopener noreferrer"&gt;google search&lt;/a&gt; for node js. Visit their website and download of node designed for your machine. After the download is done, open the installer and follow the steps. Do not be worried about the options to select, the default options would work just fine.&lt;/p&gt;

&lt;p&gt;When Node.Js is installed in your machine, open the command line terminal on your device and run the following command to test the installation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get a response showing the version of Node.Js running on your device if it was installed without a hitch.&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%2Fay7aavj7h87jp2z9qotu.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%2Fay7aavj7h87jp2z9qotu.png" alt="response of the node --version command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Angular CLI
&lt;/h2&gt;

&lt;p&gt;Next, run this 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 install -g @Angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command installs the Angular CLI globally on your machine through the node package manager. If you do not want to install Angular globally, omit “-g” in your command. The effect of this is the Angular CLI can only be accessed from the location you installed it in. I will advise you to install it globally.&lt;/p&gt;

&lt;p&gt;After the command runs, you would get a success message at the bottom when the installation was successful and an appropriate error message when it does not. If you get the success message, we can proceed to check the version of Angular in our machine. We can do this with this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng --version
&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%2F6pp9feb1jje2gq928aaw.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%2F6pp9feb1jje2gq928aaw.png" alt="response of ng --version"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Project Environment
&lt;/h2&gt;

&lt;p&gt;Now, we have Angular running comfortably on our machine. Next, we create our project. There are various methods of doing this but I do feel this one is straightforward to follow.&lt;/p&gt;

&lt;p&gt;Create a folder for the project in your desired location. If you are on a PC, hold down the shift key and right-click on the folder. Select the option of “Copy as Path”. If you are on a Mac, select the folder and press this key combination, option + command + c. This copies the absolute path of the folder to the clipboard. Open the command line terminal on your device and run this command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;You are currently in the folder of the project you want to create. Run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new project_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This then creates a new Angular project in the folder. You would need to answer a couple of question on if you would like Angular routing in the project and which stylesheet format you want to use. After you answer these questions, the installation runs and you are all set to work. You might see some warnings displayed in the output too. They can be ignored.&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%2Frmip7b6r09jgxmri4x2o.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%2Frmip7b6r09jgxmri4x2o.png" alt="angular project initialisation success"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open the folder in your favourite IDE and get to work. One benefit of Angular is you are not constrained to a particular development environment, you can use any one of your choices and it doesn’t affect the project. This is because the Angular CLI is the development centrepiece.&lt;/p&gt;

&lt;p&gt;To build your Angular project and then view it in a browser, run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve -o
&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%2Fve7djlj39t6zakoox218.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%2Fve7djlj39t6zakoox218.png" alt="building an angular app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This builds the project and opens it in your default browser.&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%2Fezedwh14tousbko20t5y.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%2Fezedwh14tousbko20t5y.png" alt="default angular project display in the browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this stage, your Angular project setup is complete and it works. You can get down to creating those amazing ideas.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>angular</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>JavaScript: A Wonderful Language for a Beginner</title>
      <dc:creator>Ike-Nwako Chukwudi</dc:creator>
      <pubDate>Sun, 22 Aug 2021 22:24:48 +0000</pubDate>
      <link>https://dev.to/inchukwudi/javascript-a-wonderful-language-for-a-beginner-1pa0</link>
      <guid>https://dev.to/inchukwudi/javascript-a-wonderful-language-for-a-beginner-1pa0</guid>
      <description>&lt;p&gt;Alongside HTML and CSS, JavaScript is one of the core technologies of the World Wide Web. It is the programming language of the web, having various applications. Over 97% of websites use it client-side for web page behaviour. All major web browsers have a dedicated JavaScript engine to execute the JavaScript code on the user's device.&lt;/p&gt;

&lt;p&gt;JavaScript is an easy language to learn and use. It does not require a lot on initial setup. What you need to deploy applications are a major web browser and an editor. I see JavaScript as an excellent language for a beginner to learn programming with. Hopefully, at the end of the article, you would agree with me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Brief History
&lt;/h2&gt;

&lt;p&gt;JavaScript was introduced about 26 years ago. It was officially released on December 4, 1995. It was developed by Brendan Eich.&lt;/p&gt;

&lt;p&gt;In the early days of the web, web pages were only static. They lacked dynamic behaviour once loaded. Netscape, the company that owned Netscape Navigator – the most widely used web browser at that time – decided to add a scripting language that would allow dynamic content to be served to their browser and Eich was hired.&lt;/p&gt;

&lt;p&gt;A common misconception is JavaScript and Java are directly related but that is not so. The idea behind the name JavaScript has been seen to be a marketing strategy by Netscape to make their new language gain popularity as Java as the new programming language making great headway at that time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of JavaScript
&lt;/h2&gt;

&lt;p&gt;One of the features of JavaScript is it is a multi-paradigm language. This makes it very flexible and easy to use. Instructions can be written in different styles and they would still run as expected. For a beginner, this can be viewed as a haven. You would not have to bother about the structure of code, just follow the basic rules of the language and it would be alright.&lt;/p&gt;

&lt;p&gt;This “loose” nature of JavaScript makes it very beginner-friendly. It is not required that you end each line of code with a semi-colon. You can omit it and the code will function properly. It is not required but it is recommended you end lines of instructions with a semi-colon. Many programming languages end their instructions with a semi-colon, it is a good way to train yourself to do so. You can also write two or more instructions on the same line of code and it would not throw any errors. When doing this, you would need to end each separate instruction with a semi-colon.&lt;/p&gt;

&lt;p&gt;These lines of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 4 + 5
console.log(sum)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and these lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 4 + 5;
console.log(sum);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would both give the same expected output with no errors. Also, writing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = 4 + 5; console.log(sum);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would work just fine too.&lt;/p&gt;

&lt;p&gt;Typing is not strict in JavaScript as a variable can hold various types of data throughout the execution of the program without throwing any exceptions. In other words, it supports dynamic typing. The various data types JavaScript supports are Strings (&lt;code&gt;“name”&lt;/code&gt;, &lt;code&gt;“16 September”&lt;/code&gt;, &lt;code&gt;“”&lt;/code&gt;), Numbers (&lt;code&gt;1&lt;/code&gt;, &lt;code&gt;17.557&lt;/code&gt;, &lt;code&gt;31e12&lt;/code&gt;), Arrays (&lt;code&gt;[“lord”, 16, [“award”]]&lt;/code&gt;), Objects(&lt;code&gt;{name: “France”, capital: “Paris”}&lt;/code&gt;), Booleans (&lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;) and undefined.&lt;/p&gt;

&lt;p&gt;JavaScript supports Object-Oriented Programming (OOP). You can create objects, assign them properties and methods and use these properties and methods in code to achieve certain tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Linking JavaScript to an HTML file
&lt;/h2&gt;

&lt;p&gt;For you to visibly see the effects of the instructions you write in a JavaScript file, you should link it to an HTML document.&lt;br&gt;
In an HTML document, JavaScript is written with the script tag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uLQKDob5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/www1p2xnihmdqy66zwq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uLQKDob5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/www1p2xnihmdqy66zwq7.png" alt="image of a script element"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script tag can be placed in the head or the body of the HTML document.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tpxv2sj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb1efs5jkyut6tnkqrid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tpxv2sj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb1efs5jkyut6tnkqrid.png" alt="placing the script element in the head element"&gt;&lt;/a&gt;&lt;/p&gt;
Screenshot of code showing Script tag in the Head Element



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gn3BCwxW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh35z5248ib9y4w066z9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gn3BCwxW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xh35z5248ib9y4w066z9.png" alt="placing the script element in the body element"&gt;&lt;/a&gt;&lt;/p&gt;
Screenshot of code showing Script tag in the Body Element



&lt;p&gt;JavaScript files can be written in the HTML document as shown in the snippets above or they can be written in separate .js files and then linked to the HTML document. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ld3e-oYq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gocm2zmal080dalpqwti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ld3e-oYq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gocm2zmal080dalpqwti.png" alt="placing the script element with the src attribute in the head element"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5yrU-g3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r757mkbi22sy29m14q08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5yrU-g3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r757mkbi22sy29m14q08.png" alt="placing the script element with the src attribute in the body element"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The linking can also be done absolutely by using the URL to the JavaScript as the value for the &lt;code&gt;src&lt;/code&gt; attribute.&lt;/p&gt;
&lt;h2&gt;
  
  
  What can JavaScript do?
&lt;/h2&gt;

&lt;p&gt;As a programming language, JavaScript provides you with features other languages have. JavaScript supports different selection and looping constructs. When you have to run a particular block of code when a particular condition is met, you are making a selection. A selection statement checks a certain condition and allows for the execution of a block of code if the condition is met. Selection statements supported in JavaScript include the &lt;code&gt;if&lt;/code&gt; statement, the &lt;code&gt;if … else&lt;/code&gt; statement, the &lt;code&gt;if … else if&lt;/code&gt; statement and the &lt;code&gt;switch&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;if&lt;/code&gt; statement can be used when there is a block of code to be run if a certain situation is encountered. When the condition set is not met, it does not run the code and moves on with the program execution as intended. In natural language, this can be put as perform this action if this happens. For example, if you see a dog, shout dog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GxXsX7do--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6g3cvdpzzwuh9xq52o4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GxXsX7do--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6g3cvdpzzwuh9xq52o4.png" alt="if statement"&gt;&lt;/a&gt;&lt;/p&gt;
An if statement that outputs the value of the variable animal if it is equal to dog



&lt;p&gt;The &lt;code&gt;if … else&lt;/code&gt; statement in JavaScript allows you to state a certain condition to be passed and when the condition is passed, the code in the &lt;code&gt;if&lt;/code&gt; block gets executed and the code in the &lt;code&gt;else&lt;/code&gt; block is neglected. When the condition is not passed, the code in the &lt;code&gt;if&lt;/code&gt; block is neglected and the code in the &lt;code&gt;else&lt;/code&gt; block is executed. In natural language, you can put it as if this happens, perform this action, else, perform that action. For example, if a sports car passes, shout “a sports car”, else, shout “a normal car”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Bea9ezQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2gugs187u56a4ru0iid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Bea9ezQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2gugs187u56a4ru0iid.png" alt="if … else statement"&gt;&lt;/a&gt;&lt;/p&gt;
An if … else statement that checks if the type property of an object car is equal to "sports car"



&lt;p&gt;The &lt;code&gt;if … else if&lt;/code&gt; statement is similar to the &lt;code&gt;if … else&lt;/code&gt; statement. The first condition is checked and if it passes, the code contained in that &lt;code&gt;if&lt;/code&gt; block is executed and the code in the other blocks are neglected. If the first condition set does not pass, it checks the next condition. If the next condition passes, the code in its block is executed with the rest neglected and if it does not pass, it checks the next condition. It repeats this process till all conditions are checked. You can choose to give your &lt;code&gt;if … else if&lt;/code&gt; statement an &lt;code&gt;else&lt;/code&gt; block and the code contained in it will run when no initial conditions set are met. For example, listen to the scores the teacher calls out in class if the score is above 90 and below or equal to 100, write A, else if the score is above 80 and below 91, write B, else if the score is above 70 and below 81, write C, else write F.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wYtpppgh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9g46iu98pto44o8mgxd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wYtpppgh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9g46iu98pto44o8mgxd.png" alt="if … else if statement"&gt;&lt;/a&gt;&lt;/p&gt;
The if … else if statement for the example stated above



&lt;p&gt;The &lt;code&gt;switch&lt;/code&gt; statement works like the &lt;code&gt;if … else if&lt;/code&gt; statement but here, a condition, usually an expression, is given and then different &lt;code&gt;cases&lt;/code&gt; of expected outputs are provided. Each case having instructions that are to be executed if the output matches it. Switch statements usually have a &lt;code&gt;default&lt;/code&gt; case that gets executed when the other cases are not matched. At the end of each case, a &lt;code&gt;break&lt;/code&gt; statement is written, this ensures other cases do not get checked after a case has been matched. It “breaks” out of the selection construct once a case is matched. For example, if we are to read input from a user and display different content based on the user's input, a switch statement is a good fit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SIAFPHE_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj2cnwi82jcu57xp1439.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SIAFPHE_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj2cnwi82jcu57xp1439.png" alt="switch statement"&gt;&lt;/a&gt;&lt;/p&gt;
A switch statement that displays an ouput message based off a user's input



&lt;p&gt;In a &lt;code&gt;switch&lt;/code&gt; statement, you can merge two or more cases if they will all execute the same block of code if any of them gets matched.&lt;/p&gt;

&lt;p&gt;A loop is a sequence of instructions that is continually repeated until a certain condition is reached. Loops are handy, if you want to run the same code over and over again, each time with a different value. They help you reduce writing unnecessary lines of code and help you stick to the DRY (Don’t Repeat Yourself) principle.&lt;/p&gt;

&lt;p&gt;Let us take into consideration the code below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fZHc2bab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clcy9ktl170e0eei01pd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fZHc2bab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/clcy9ktl170e0eei01pd.png" alt="repeated code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I was trying to extract all the elements of the cars array and store them in a carList variable. The cars array has 6 elements so it was easy to write this out. Now, let us imagine that the cars array had 100 elements, writing this out, line by line would take a couple of minutes. Now, say I have to fetch this array from an API where all the names of all cars in the world were stored and the total number of elements in the array is over 10,000. You would agree with me that writing it out line by line would be burdensome and time-consuming. &lt;/p&gt;

&lt;p&gt;Another case is if I do not know the total number of elements in the array. I would not know where to stop indexing at. So, we need a way to extract all the elements without undue stress and uncertainty. This is where a loop comes in.&lt;/p&gt;

&lt;p&gt;Loops are meant to terminate, hence, a condition or limit is put and when the condition for the running of the loop is met, the loop terminates. If the condition is wrongly set that it would never be met or is omitted totally, the loop will run infinitely and this can cause problems for your program. When using loops, be careful to set a condition that will ensure the loop will terminate when it has run for the number of times it is expected to run for. Loops supported in JavaScript are for loop, for … in loop, for … of loop, while loop and do … while loop. These loops mostly do the same thing but differ in syntax and implementation.&lt;/p&gt;

&lt;p&gt;The for loop has this syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (statement 1; statement 2; statement 3) {
  // code block to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Statement 1 is used to initialise the variables used in the loop, statement 2 is the condition at which when met, the loop terminates and statement 3 is used to increment or decrement the value of the initial variable initialised. For loops can be used to loop through arrays, strings, node lists and so on. Let us use a for loop to solve the problem we ran into earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5kOfukLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qd0rxjdr4vxaevbrgm28.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5kOfukLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qd0rxjdr4vxaevbrgm28.png" alt="for loop"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The for … in loop in JavaScript loops through the properties of an Object. It is written 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;for (key in object) {
  // code block to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The for … in loop iterates over the object. Each iteration returns a key. The key is used to access the value of the key. The value of the key is object[key]. The value can then be used as the programmer wishes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3j3xtvLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcbim36kb7kw6bskr1zy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3j3xtvLF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcbim36kb7kw6bskr1zy.png" alt="for … in loop"&gt;&lt;/a&gt;&lt;br&gt;
A screenshot of a for … in loop that iterates over an object&lt;/p&gt;

&lt;p&gt;The for … of loop loops through the values of an iterable object. It lets you loop over iterable data structures such as Arrays, Strings, Maps, Node Lists and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (variable of iterable) {
  // code block to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For every iteration of the iterable, the value of the next property is assigned to the variable. The iterable is an object that has iterable properties.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bmp0KPvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ir989kenlpqf9jsabzw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bmp0KPvN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ir989kenlpqf9jsabzw1.png" alt="for … of loop"&gt;&lt;/a&gt;&lt;/p&gt;
A screenshot of a for … of loop that loops through the values of an array



&lt;p&gt;The while loop loops through a block of code as long as a specified condition is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {
  // code block to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wGUBNmVg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hr4y5bl51cn0p73btgae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wGUBNmVg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hr4y5bl51cn0p73btgae.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you forget to increase or decrease the variable used in the condition, the loop will never end. This will crash your browser.&lt;/p&gt;

&lt;p&gt;The do-while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FXmQ9RTv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j7s2xfuh9hmqcf740st.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FXmQ9RTv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j7s2xfuh9hmqcf740st.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a while loop, it is possible for the while block of code not to run, that is, when the condition is not met, but in the do … while loop, the do block of code would run, at least once because the condition is checked after the execution of the do block.&lt;/p&gt;

&lt;p&gt;Furthermore, JavaScript is an event-driven and functional programming language. With this, it is widely used for HTML DOM manipulation. The Document Object Model (DOM) is the data representation of the objects (elements) that comprise the structure and content of a document on the web. The Document Object Model (DOM) connects web pages to scripts or programming languages by representing the structure of a document—such as the HTML representing a web page—in memory.&lt;/p&gt;

&lt;p&gt;With JavaScript, HTML elements are accessed through the DOM and can be edited. HTML elements’ contents can be changed with JavaScript. Their attributes can be changed also, styles applied to those elements can be edited and even the display and visibility status of the elements can be controlled with JavaScript. JavaScript can add more elements to the DOM and also remove existing elements from the DOM. The DOM is not a programming language but just a representation of a web page. The DOM can be accessed by calling the document object and using the available methods to manipulate the element(s).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aDEYVP4K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is3d819j5rl1axd47hpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aDEYVP4K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is3d819j5rl1axd47hpt.png" alt="DOM methods for accessing html elements"&gt;&lt;/a&gt;&lt;/p&gt;
DOM methods for accessing elements in the DOM



&lt;p&gt;The manipulations to the DOM with JavaScript are usually event triggered. Various HTML events can occur in the course of viewing a web page. As you would guess, JavaScript employs the use of event listeners to detect when these events happen. These event listeners have provisions for functions to be executed when the event they listen for has occurred. Events can be grouped into different categories. Examples of common events are click event, dblclick (double click) event, mousedown event, mouseenter event, mouseleave event, drag event, play event, ended event, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VEyXp2gM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8p8m8ohdy92y7espnmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VEyXp2gM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8p8m8ohdy92y7espnmh.png" alt="Adding a click event listener to an element"&gt;&lt;/a&gt;&lt;/p&gt;
Adding a click event listener to an element



&lt;p&gt;In addition, JavaScript provides a lot of functions and methods that allow you to control and handle audio and video files. At the occurrence of certain events or completion of functions, you can play your audio and video. Some people take advantage of this and create their custom audio and video player as built-in players by browsers that might have limited functions. When designing a custom media player, HTML and CSS comes in also. Common audio and video methods you can take advantage of in JavaScript are load(), play() and pause() and common events associated with audio and video are ended event, play event, timeupdate event, volumechange event and so on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KuqaqHs_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7l0qjrfcka2i5g4hpbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KuqaqHs_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7l0qjrfcka2i5g4hpbn.png" alt="common audio events"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is also vital to note that JavaScript can connect to web servers, get information from them and also post information to them. This can be done asynchronously using AJAX (Asynchronous JavaScript And XML). AJAX is not a programming language. With AJAX, you can update a web page without reloading the page and send data to a web server - in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications of JavaScript
&lt;/h2&gt;

&lt;p&gt;JavaScript has grown over the years. It was initially created for making web pages dynamic and now, we see it used in different aspects like server-side scripting and even hybrid application development.&lt;/p&gt;

&lt;p&gt;JavaScript is applied in front-end development. With the development of various frameworks and libraries, front-end development is easier and also more powerful as these frameworks and libraries give you the platform to harness the full power of JavaScript in your web application stress-free.&lt;/p&gt;

&lt;p&gt;JavaScript can be used in server-side scripting though it was originally meant for front-end web development. &lt;a href="https://nodejs.org/"&gt;Node.Js&lt;/a&gt; is an open-source development environment that allows you to run JavaScript on a server. This is helpful for front-end developers with JavaScript knowledge as they can write server-side scripts in JavaScript and it would run efficiently. There is no need to learn another language.&lt;/p&gt;

&lt;p&gt;Writing JavaScript for the server-side is possible, also writing JavaScript for mobile applications and desktop applications is also possible. &lt;a href="https://cordova.apache.org/"&gt;Apache Cordova&lt;/a&gt; is a free mobile application development framework that allows you to develop an application in HTML/JavaScript and then it wraps it into a native container that can access the device functions of several platforms and hence enables the web app to work on mobile devices. &lt;a href="https://www.electronjs.org/"&gt;Electron&lt;/a&gt; is a free and open-source framework for creating native desktop applications with web technologies. It allows building cross-platform desktop apps with JavaScript, HTML, and CSS. There are other examples of such development frameworks that exist like &lt;a href="https://ionicframework.com/"&gt;Ionic&lt;/a&gt; and &lt;a href="https://nativescript.org/"&gt;NativeScript&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding Subresource Integrity (SRI)</title>
      <dc:creator>Ike-Nwako Chukwudi</dc:creator>
      <pubDate>Wed, 11 Aug 2021 12:17:54 +0000</pubDate>
      <link>https://dev.to/inchukwudi/understanding-subresource-integrity-sri-3ep7</link>
      <guid>https://dev.to/inchukwudi/understanding-subresource-integrity-sri-3ep7</guid>
      <description>&lt;p&gt;There are numerous benefits of embedding files and scripts hosted by third parties, such as a Content Delivery Network (CDN), in your HTML documents. But this comes with its vulnerabilities and most times, we are not aware that we (site owners and site users) are open to such attacks. Using Subresource Integrity can help prevent some of these attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Subresource Integrity?
&lt;/h2&gt;

&lt;p&gt;Subresource Integrity (SRI) is a security feature that enables browsers to verify that resources they fetch (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that a fetched resource must match. In simple terms, it is a feature used by browsers to validate resources fetched from third parties have not been manipulated by comparing them to a hash key and if they do not match, the browsers do not serve up the resources.&lt;/p&gt;

&lt;p&gt;Being new to HTML, I wondered about the use of the &lt;code&gt;integrity&lt;/code&gt; attribute in some HTML elements and sometimes, I removed it and its value from the element. I was ignorant of its use as it isn’t something that pops up most times. Going further and being more security conscious, I discovered the integrity attribute holds the cryptographic hash of the resource to be embedded. This hash could be (but not be limited to) an SHA-256, SHA-384 or SHA-512 hash.&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;script src="https://inchukwudi.example.com/lib-example/example.min.js"
    integrity="sha512-6QWD5OGReFYm4dnWc1Qt5Ntv9qYdvdihz0PPSiiqn/o4EaG7TubfWGUrM"
    crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
A code snippet showing a script element with an integrity attribute





&lt;h2&gt;
  
  
  JavaScript, A Helpful Yet Dangerous Tool
&lt;/h2&gt;

&lt;p&gt;JavaScript is the scripting language of the web. It can perform basic stuff from creating, displaying and hiding new elements, to changing the attributes of elements. It can do more complex functions from posting data to and getting data from APIs. All these can be done without the knowledge of the site user sometimes when a certain event is triggered, for example, clicking on an element or hovering over an element.&lt;/p&gt;

&lt;p&gt;You would agree with me that JavaScript is a powerful tool. An attacker can use JavaScript to mislead users of your site by adding or editing content that you did not put. Phishing links can be added and undue redirection can be initiated. Even, the action attribute of a form can be changed and the information a user inputs in a form is sent elsewhere and vital information exposed.&lt;/p&gt;

&lt;p&gt;SRIs can help against embedding such malicious content unknowingly in your website. Yes, unknowingly as most times, malicious content are embedded without your notice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ways Malicious Content Get Served
&lt;/h2&gt;

&lt;p&gt;When you visit a website, your browser sends a request to the server and the server processes the request and then sends a response to your browser. Your browser interprets this response and then displays the content you see. &lt;/p&gt;

&lt;p&gt;The response sent back from the server can be thwarted in many ways and we might just be oblivious to it. Let's say a user is connected to a network where all requests and responses pass through a proxy server. An attacker with access to such requests and responses can swap or edit a file before it reaches the client and the client gets compromised. &lt;/p&gt;

&lt;p&gt;Another plausible example is an attacker gains access to a trusted CDN vendor and then edits the files on their server and different users using websites that embed such files get comprised. This is just a highlight, the list goes on and on.&lt;/p&gt;

&lt;h2&gt;
  
  
  SRI Working Mechanism
&lt;/h2&gt;

&lt;p&gt;Let us use libraries as a case study. The content of a version of a library is fairly constant and is not expected to change. When there are major changes to be made, a new version is released. Knowing this, adding the integrity attribute with a cryptographic hash of the particular version of the library you intend to use in your HTML document will safeguard against an altered form of the library to be served to your users. Most times, the cryptographic hash of the particular version of the library is provided by the vendor of the library but in some cases, you might have to hash it down yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;integrity="sha512-atM3QqRcbCn6ewmpxcLAHGaDjpEB4xZd47q7pAP+gi5Yu8hFgoh"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
Code snippet showing the integrity attribute and its cryptographic hash (SHA-512) value





&lt;p&gt;When the browser is linking the external library, it will hash it according to the hash algorithm specified in the integrity attribute, in this case, SHA-512, and if the output of the hash does not match the hash specified in the integrity attribute, it tries other known hashing algorithms, for example, SHA-256, and it still does not match, it does not load the file. To illustrate this, here is an example using the jQuery library version 3.6.0. &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%2Fpku3nmmpz0bpc7vwf75h.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%2Fpku3nmmpz0bpc7vwf75h.png" alt="screenshot of the jQuery library v3.6.0"&gt;&lt;/a&gt;&lt;/p&gt;
A screenshot of the end of the minified version of the jQuery library v3.6.0 as gotten from the jQuery Website 



&lt;p&gt;The image above is an image of the jQuery library v3.6.0 as gotten from the jQuery website. Now here is an image of the same file but with a commented line I added myself for the purpose of demonstration of how SRI helps protects you against changes in the resource.&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%2Fyh9wqogevjivnq0jo2dw.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%2Fyh9wqogevjivnq0jo2dw.png" alt="screenshot of the tampered jQuery library v3.6.0"&gt;&lt;/a&gt;&lt;/p&gt;
A screenshot of the end of the minified version of the tampered jQuery library v3.6.0



&lt;p&gt;When the edited jQuery file attempts to get loaded, the browser checks and then displays this error message in the console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Failed to find a valid digest in the 'integrity' attribute for resource 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js' with computed SHA-256 integrity '4ca6xP/WMfyyRx+MmirFEms71HApLgbRdTy0XavPeQA='. The resource has been blocked.&lt;br&gt;
&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The edited file does not load and I am free from potential attacks if it was a malicious code that was added to the file. Most modern browsers support SRI so you do not have to worry as most users of your site would be protected from such attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices When Embedding Content
&lt;/h2&gt;

&lt;p&gt;Some people may advise you self host all resources you might use. Well, this makes the origin of the files trustworthy but it does not stop the files from being manipulated when a response is made. An integrity attribute is needed. Also, you would have to make sure you download such files from the owners of the libraries as there are various counterfeits all over. This might be expensive as it will take up a substantial amount of bandwidth.&lt;/p&gt;

&lt;p&gt;Using a third party resource is beneficial and in most cases cheaper than hosting the files yourself. Many resources owners have CDNs and provide you with the links to access the resource over the internet. Some of these links have the integrity attributes with cryptographic hash values already, some do not. Caution should be exercised when searching for links to CDNs and other resources as attackers might host already tampered files and hash it and make it look trustworthy, so be mindful of the websites you get links to resources from.&lt;/p&gt;

&lt;p&gt;Using this online tool, &lt;a href="https://www.srihash.org/" rel="noopener noreferrer"&gt;SRI Hash Generator&lt;/a&gt;, you can generate a cryptographic hash of the stylesheet or script you want to embed and add use it in your document and even share for others to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  SRI Drawbacks
&lt;/h2&gt;

&lt;p&gt;The benefit of SRI is evident but it has its drawbacks. The file that does not match the cryptographic hash won’t be loaded and this may break a lot of things especially the structure of the page and certain functionalities put in place. If a stylesheet is affected, all elements that use classes defined in the stylesheet would not appear as they ought to and the look of the site may not be palatable to the user of the site.&lt;/p&gt;

&lt;p&gt;Also, when attacks are launched and are countered by using SRI, the owner of the website is not aware that such an attack occurred. A user with no technical expertise would not know too and would think the website is just quirky then might move on to another website and if the website does not make use of SRI, the user can be compromised.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>html</category>
      <category>security</category>
    </item>
  </channel>
</rss>
