<?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: adebomiolusegun</title>
    <description>The latest articles on Forem by adebomiolusegun (@adebomiolusegun).</description>
    <link>https://forem.com/adebomiolusegun</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%2F935930%2Ff5d83887-7da4-44e3-abc1-5e3727330894.png</url>
      <title>Forem: adebomiolusegun</title>
      <link>https://forem.com/adebomiolusegun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adebomiolusegun"/>
    <language>en</language>
    <item>
      <title>Function declaration and Function Expression</title>
      <dc:creator>adebomiolusegun</dc:creator>
      <pubDate>Mon, 02 Jan 2023 02:42:51 +0000</pubDate>
      <link>https://forem.com/adebomiolusegun/function-declaration-and-function-expression-1o63</link>
      <guid>https://forem.com/adebomiolusegun/function-declaration-and-function-expression-1o63</guid>
      <description>&lt;p&gt;The function expression is nearly similar to the function declaration, but there are some differences.&lt;/p&gt;

&lt;p&gt;The function declaration is created by first declaring the function keyword, followed by a code block where we put our code to be executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function name(parameters){
  Our code to be executed 
}

name(argument);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And meanwhile, the function expression can be stored in a variable, which is then used as a 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 name = function ( parameters a, parameter b){

 Our code to be executed 
};

name(argument);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As an expression, the semicolon is placed at the end of the code block because that is where it is expected to be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hoisting&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;hoisting allows you to use functions and variables before they are declared.&lt;/p&gt;

&lt;p&gt;This is done with function declaration but not with function expression.&lt;/p&gt;

&lt;p&gt;Examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name(argument);

Function name(parameters){
  Our code to be executed 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a function declaration; the code will be executed because JavaScript hoisting accepts it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name(argument);

Const name = function ( parameters a, parameter b){

 Our code to be executed 
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile, because this is a function expression, the code will not run because JavaScript hoisting does not accept it. &lt;br&gt;
It’s will display undefined.&lt;/p&gt;

&lt;p&gt;I hope this is of great assistance to someone out there.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript arrays and array methods</title>
      <dc:creator>adebomiolusegun</dc:creator>
      <pubDate>Wed, 05 Oct 2022 22:56:00 +0000</pubDate>
      <link>https://forem.com/adebomiolusegun/javascript-arrays-and-array-methods-3288</link>
      <guid>https://forem.com/adebomiolusegun/javascript-arrays-and-array-methods-3288</guid>
      <description>&lt;h2&gt;
  
  
  What are Arrays?
&lt;/h2&gt;

&lt;p&gt;An array is a collection of variables that store multiple values in a single variable. Arrays indicate the beginning and end of the element by using a square bracket. &lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Mexico", "São Paulo", "Cairo"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Javascript arrays make use of index numbers. It begins by counting the element by 0 (zero).&lt;br&gt;
&lt;br&gt;
  &lt;br&gt;
         &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   0        1        2          3
let cities = ["Tokyo", "Mexico", "São Paulo", "Cairo"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Array Methods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The toString&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Strings are automatically separated with commas using the toString method.&lt;br&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 cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo"];
let x = cities.toString(2);
console.log(x);
output [Tokyo,Delhi,Mexico,São Paulo,Mumbai,Cairo]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The isArray method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The array method determines whether the value is an array and returns true if it is. Otherwise, a false positive is returned.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico",  "São Paulo", "Mumbai" ,"Cairo"];
let x = Array.isArray(cities);  
console.log (x); // As a result, this will return True.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = "Mumbai";
let x = Array.isArray(cities);  
console.log (x);  
The result will be false.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Push Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The push method adds an element at the end of the array and returns the new length.&lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.push("Hong kong");  
console.log (x);  
x will have the value 7
This is the outcome ["Tokyo," "Delhi," "Mexico," "So Paulo," "Mumbai," "Hong Kong"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add as many elements as you want using the push method.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Pop Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What the pop method does is remove the last element from an array and return that element.&lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.pop();    
console.log (x); 
 x will have the value Cairo.
 the outcome will be ["Tokyo," "Delhi," "Mexico," "So Paulo," and "Mumbai"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Shift Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The shift method removes the first element from an array and returns the shifted element.&lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cars.shift();  
console.log(x); 
the value of x will be Tokyo
This will be the result ["Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Unshift Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The unshift method adds an element to the beginning of an array and returns the length.&lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.unshift("Hong Kong"); 
console.log (x); 
x will be set to 7
The result will look like this [ "Hong Kong" "Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" "Cairo" ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The IndexOf Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;indexOf returns the first index for an element. It will return -1 if the index is not found.&lt;br&gt;
example&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Mexico", "Cairo"];
let x = cities.indexOf("Mexico"); 
console.log (x); 
 returns a value of 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo"];
let x = cities.indexOf("Hong Kong"); 
console.log(x); 
//this will return -1 because we don't have Hong Kong in the list of our elements.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will search Mexico starting from the 3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo", "Mexico"];
let x =cities.indexOf("Mexico", 3); 
console.log(x); 
 this will return 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The lastIndexOf Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The lastIndexOf returns the last index of the last element. It will return -1 if the index is not found.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Mexico", "Cairo"];
let x =cities.lastIndexOf("Mexico"); 
console.log (x); 
this will return a value of 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The reverse method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reverse method reverses the order of the elements in an array.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x =cities.reverse(); 
console.log(x);   
 The result will look like this ['Cairo', 'Mexico', 'Mumbai', 'São Paulo', 'Mexico', 'Delhi', 'Tokyo'].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The sort method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Arrays are sorted in descending order using the sort method.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x =cities.sort(); 
console.log(x);  
this will be the result ['Cairo', 'Delhi', 'Mexico', 'Mexico', 'Mumbai', 'São Paulo', 'Tokyo']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strings can be sorted in descending order with the aid of the reverse method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x =cities.sort(); 
cities.reverse();
console.log(x);  
The final result will be ['Tokyo,' 'So Paulo,' 'Mumbai,' 'Mexico,' 'Delhi,' 'Cairo.']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Numerical sorting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sorting numbers is not similar to sorting alphabets. When sorting numbers, use the compare function.&lt;br&gt;
Ascending order of numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =[5, 20, 40, 10, 30, 60, 50];
let x =cities.sort(function (a, b) {return a - b});
console.log(x); 
output [5, 10, 20, 30, 40, 50, 60]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
   &lt;br&gt;
Descending order of numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =[5, 20, 40, 10, 30, 60, 50];
let x =cities.sort(function (a, b) {return b - a});
console.log(x); 
output [60, 50, 40, 30, 20, 10, 5]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The method includes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The include method checks if an element is inside an array and it returns the result as a boolean (True or false).&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x = cities.includes("tokyo"); 
console.log(x); 
The result will be true.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x =cities.includes("Hong Kong"); 
console.log(x); 
The result will be false, because Hong Kong is not among the elements listed.  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The join method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The join method concatenates every element in an array using a comma or another string separator, then returns the array as a string.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Mexico", "Cairo"];
let x =cities.join(); 
console.log(x); 
 This will be the result  Tokyo,Delhi,Mexico,São Paulo,Mumbai,Mexico,Cairo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Mexico", "Cairo"];
let x =cities.join(" - "); 
console.log(x); 
This will be the result Tokyo - Delhi - Mexico - São Paulo - Mumbai - Mexico - Cairo   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When adding something to an array, it gives you the resulting length. When you remove it, it gives you the item that you removed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The index number can also be used to access an array.
&lt;/h2&gt;

&lt;p&gt;You can access an element by its index number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities[ 3];  
console.log(x);
The output will be São Paulo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can change elements in an array by its index number. Look at the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities[3] = "Abuja";  
console.log(x);
"São Paulo" will be replaced with "Abuja"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The splice method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The splice method adds and removes array elements.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo"];
let x = cities.splice(7,0, "abuja");
console.log(cities);
output ['Tokyo', 'Delhi', 'Mexico', 'São Paulo', 'Mumbai', 'Cairo', 'abuja']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the preceding example, we added an element at position 7. You can add more elements with this method.&lt;br&gt;
New elements can also be inserted between existing ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.splice(2,0, "abuja", "lagos");
console.log(cities)
output ['Tokyo', 'Delhi', 'abuja', 'lagos', 'Mexico', 'São Paulo', 'Mumbai', 'Cairo']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We added two elements to position 2.&lt;br&gt;
We will see how we can remove the element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.splice(2,2);
console.log(cities);
output ['Tokyo', 'Delhi', 'Mumbai' ,'Cairo']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We removed two elements from position 2.&lt;br&gt;
Elements can be replaced using the splice method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities = ["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.splice(2, 2, "abuja", "lagos");
console.log(cities);
The output ['Tokyo', 'Delhi', 'Mumbai', 'Cairo']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The slice method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The slice method slices a portion of an array and returns the sliced portion as the new array. It  slices elements from beginning to end. The index of the element determines its beginning to end.&lt;br&gt;
&lt;br&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 cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.slice(2, 5);
console.log(x);
The output ['Mexico', 'São Paulo', 'Mumbai']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;br&gt;
    &lt;br&gt;
You can start from the end and slice.&lt;br&gt;
&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" ,"Cairo"];
let x = cities.slice( -4, -1);
console.log(x);
The output ['Mexico', 'São Paulo', 'Mumbai']

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

&lt;/div&gt;



&lt;p&gt;This example slices out a portion of an array starting from the 2 array element.&lt;br&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 cities =["Tokyo", "Delhi", "Mexico", "São Paulo", "Mumbai" , "Cairo"];
let x = cities.slice(2);
console.log(x);
The output ['Mexico', 'São Paulo', 'Mumbai', 'Cairo']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Arrays and objects are quite similar. The distinction is that objects use a named index while arrays use a numbered index in JavaScript.For further information on arrays, I suggest visiting w3schools.com and developer.mozilla.org.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Introduction to HTML and HTML Document Structure</title>
      <dc:creator>adebomiolusegun</dc:creator>
      <pubDate>Sun, 02 Oct 2022 11:00:52 +0000</pubDate>
      <link>https://forem.com/adebomiolusegun/introduction-to-html-and-html-document-structure-5agj</link>
      <guid>https://forem.com/adebomiolusegun/introduction-to-html-and-html-document-structure-5agj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If web development is something you are interested in, HTML will be the first thing you learn. Before understanding other languages, everyone who has become a web developer has learned HTML. Images, text, videos, and forms are all displayed on websites using the HTML markup language.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is HTML
&lt;/h2&gt;

&lt;p&gt;"HTML" stands for Hypertext Markup Language. It's the skeleton of a website. HTML is a combination of hypertext and a markup language. Hypertext refers to links that connect pages either within the website or between websites.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Tag Structure
&lt;/h2&gt;

&lt;p&gt;The website is structured using HTML elements, tags, and attributes. An HTML tag indicates the start and end of an HTML element. The HTML tags are enclosed by an angular bracket. As a result, it is important that you close a tag after opening it. To close a tag, we use the same angular brackets, but we must use a forward slash.&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;h1&amp;gt; This is an opening tag.
&amp;lt;/h1&amp;gt; This is a closing tag.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Element
&lt;/h2&gt;

&lt;p&gt;Elements and tags are not the same thing. An element is anything within the starting and closing tags.&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;h1&amp;gt;HEADING1&amp;lt;/h1&amp;gt;
&amp;lt;h1&amp;gt;&amp;lt;/h1&amp;gt; Are the opening and closing tags. 
HEADING 1 is the content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some elements have no content and no closing tags. Such elements are known as "empty elements."&lt;br&gt;
Some examples of empty elements are provided below.&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;br&amp;gt; 
&amp;lt;hr&amp;gt; 
&amp;lt;img&amp;gt; 
&amp;lt;area&amp;gt;
&amp;lt;input&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Attributes
&lt;/h2&gt;

&lt;p&gt;HTML attributes are special words used inside the opening tag to modify the behavior of the element. Additional details about the HTML elements you're working with are provided by HTML attributes. Attributes are made up of two parts: name and value. A semicolon follows the attribute value.&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;openin_tag attribute_name= attribute_value ("value")&amp;gt;Element&amp;lt;/closing_tag&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For proper comprehension, we will discuss the various types of attributes below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types and examples of Attributes
&lt;/h2&gt;

&lt;p&gt;Some attributes are universal and can be applied to any element. As a result, they're known as standard or global attributes.&lt;br&gt;
Here are some examples of global attributes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Class Attribute&lt;/strong&gt;
The class attribute assigns one or more class names to an element.
&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;h1 class="firstheader"&amp;gt;Header 1&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The ID Attribute&lt;/strong&gt;
The id attribute is used to uniquely identify an element, and unlike the class attribute, multiple       elements cannot have the same id name. The same class name, on the other hand, may apply to many elements.
&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;h1 id="myid"&amp;gt;Header 1&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Title Attributes&lt;/strong&gt;
The title contains text that provides additional information about the element to which it belongs and will be displayed as a tooltip if you hover over the element.
&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;p title="your welcome"&amp;gt;Hello.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The value of the of the title attribute will be displayed if you hover your mouse above the element.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The style attributes&lt;/strong&gt;
Fonts, colors, and other elements get styles added through the style attribute.
&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;p style="color:blue;"&amp;gt;Hello.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Some attributes must be used with a particular element or set of elements. As a result, they're known as required and optional attributes.&lt;br&gt;
Here are some examples of required and optional attributes. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The ALT Attribute&lt;/strong&gt;
The alt attribute is used to display text as an alternative when you cannot view an image in the browser due to a slow network or other reasons.
&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;img src="car.jpg" alt="This is a toyota car"&amp;gt;     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The alt attribute can be used with the following elements.&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;area&amp;gt;
&amp;lt;input&amp;gt; 
&amp;lt;image&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Src Attribute&lt;/strong&gt;
The src attributes specify the URL to the image to be displayed.
&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;img src="car.jpg"&amp;gt;
     You can also get images from a folder on your computer. 
    &amp;lt;img src="/images/car.jpg"&amp;gt;        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The href Attribute&lt;/strong&gt;
The href attribute indicates the link's destination.
&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;a href="https://www.toyota.com"&amp;gt;Visit Toyota&amp;lt;/a&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The alt attribute can be used with the following elements.&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;area&amp;gt;
&amp;lt;link&amp;gt; 
&amp;lt;a&amp;gt;
&amp;lt;base&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Checked Attribute&lt;/strong&gt;
It specifies that an  element should be pre-selected when the page loads.
&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;form action="/action_page.php"&amp;gt;    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The alt attribute can be used with the following elements. &lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The last is the event attribute, Most elements support event attributes, which can be used to execute JavaScript when certain events occur, You'll use and understand more of these attributes when you start writing javascript.&lt;br&gt;
Here are some examples of required and optional attributes. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The On Mouseover&lt;/strong&gt;
When the mouse is moved over an element, the onmouserover attribute is triggered.
&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;div class="circle" onmousemove="mouseMoveFn()" onmouseout="mouseOutFn()"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The onclick&lt;/strong&gt;
This event attribute is triggered when a user clicks an element with the mouse, this works with all HTML element.
&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;p id="click" onclick="myFunction()"&amp;gt;Click me to change my text color.&amp;lt;/p&amp;gt;      
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The ononline&lt;/strong&gt;
When the browser starts working, this attribute becomes active. It works with the body tag only.
&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;body ononline="myFunction()"&amp;gt;      
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The onwaiting&lt;/strong&gt;
Both audio and video can be used with this attribute. It is triggered when the media is paused and ready to resume.
&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;audio onwaiting="myFunction()"&amp;gt;
&amp;lt;video onwaiting="myFunction()"&amp;gt;    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  THE HTML Document Structure
&lt;/h2&gt;

&lt;p&gt;The Doctype declaration, HTML, head, title, body, and body content make up the structure of an HTML document. This is the information that HTML sends to web browsers.&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;!DOCTYPE html&amp;gt;
    &amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="UTF-8"&amp;gt;
        &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, 
         initial-scale=1.0"&amp;gt;
        &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;   

    &amp;lt;/body&amp;gt; 
    &amp;lt;/html&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The !DOCTYPE html
&lt;/h2&gt;

&lt;p&gt;The first thing on the page should be the DOCTYPE declaration, which tells the browser that the current version of HTML is HTML 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  The html
&lt;/h2&gt;

&lt;p&gt;The root element in HTML is the next. Everything in the document, including the "head" and "body" tags, is contained in this tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  The head
&lt;/h2&gt;

&lt;p&gt;The head element tag comes after the root element tag. This is where the metadata is saved; the browser will only read it, it will not be displayed on the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Meta
&lt;/h2&gt;

&lt;p&gt;The meta tag contains information about the webpage and instructs the browser on how to display it to the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  The charset="UTF-8"
&lt;/h2&gt;

&lt;p&gt;The charset attribute tells the browser what character encoding is used to display content on the webpage. Character encoding instructs the computer on how to translate digital data into symbols, letters, and numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The UTF-8
&lt;/h2&gt;

&lt;p&gt;This is the version of the character set. It is the most widely used character encoding format on the web, covering nearly all of the world's characters and symbols.&lt;/p&gt;

&lt;h2&gt;
  
  
  Http-equiv
&lt;/h2&gt;

&lt;p&gt;This attribute uses HTTP headers to provide information about the web page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Name Viewport
&lt;/h2&gt;

&lt;p&gt;The viewport meta tag enables us to specify the width and scaling of the viewport in order to properly size all devices. On a desktop computer, for instance, it will appear larger, medium on tablet, whereas on a mobile device, it will appear smaller.&lt;/p&gt;

&lt;h2&gt;
  
  
  initial-scale=1.0
&lt;/h2&gt;

&lt;p&gt;The initial scale controls the browser's initial zoom level when the page is first loaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Content
&lt;/h2&gt;

&lt;p&gt;The content attribute contains the value linked to the name or HTTP-equivalent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tittle
&lt;/h2&gt;

&lt;p&gt;This is the title of the document, and it appears in the browser's title bar.&lt;/p&gt;

&lt;h2&gt;
  
  
  The body
&lt;/h2&gt;

&lt;p&gt;The content of the body element is displayed on the web page for the user that visits your website,all the content you see on the web page, including images, videos, and text, is contained in the body section.&lt;/p&gt;

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

&lt;p&gt;We've all read and understood the fundamentals of HTML and have a basic understanding of how it works, and you'll learn more about HTML and its elements, as well as how to use them to structure your website. If you want to learn more about it, I recommend w3schools.com and freecodecamp.org.&lt;/p&gt;

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