<?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: Angeline Wang</title>
    <description>The latest articles on Forem by Angeline Wang (@angelinewang).</description>
    <link>https://forem.com/angelinewang</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%2F873244%2F0ece4647-e712-4835-9af6-7b0714d4158a.png</url>
      <title>Forem: Angeline Wang</title>
      <link>https://forem.com/angelinewang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/angelinewang"/>
    <language>en</language>
    <item>
      <title>How Control Flow Works in JavaScript</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Mon, 21 Nov 2022 18:43:13 +0000</pubDate>
      <link>https://forem.com/angelinewang/how-control-flow-works-in-javascript-3ope</link>
      <guid>https://forem.com/angelinewang/how-control-flow-works-in-javascript-3ope</guid>
      <description>&lt;h2&gt;
  
  
  Introduction: What is Control Flow?
&lt;/h2&gt;

&lt;p&gt;A computer program is an algorithm that contains a sequence of events. And control flow is set up to execute those events in the correct order. Throughout this sequence of events, decisions are made based on inputs. In colloquial terms, it sounds like: “If this, then… If that, then that…”&lt;/p&gt;

&lt;p&gt;Everything discussed below are control flow statements, which you can use to change and interfere with the normal execution of code in JavaScript. &lt;/p&gt;

&lt;p&gt;These are all useful ways to write code that can be reused throughout a program, which will help you finish your app faster, make your codebase more concise and run more efficiently. &lt;/p&gt;

&lt;p&gt;In this article, you will learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are conditionals?&lt;/li&gt;
&lt;li&gt;What are the different ways you can write conditionals in JavaScript?&lt;/li&gt;
&lt;li&gt;When and why should you use each type of conditional&lt;/li&gt;
&lt;li&gt;What are loops?&lt;/li&gt;
&lt;li&gt;What kind of loops are available in JavaScript?&lt;/li&gt;
&lt;li&gt;When and why should you use each type of loop&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What are Conditionals?
&lt;/h3&gt;

&lt;p&gt;Conditionals are used to decide which certain code blocks are executed, based on the evaluation of a condition. This makes a program more dynamic as it is able to react differently depending on the circumstances at runtime. &lt;/p&gt;

&lt;p&gt;There are three different ways you can write conditionals in JavaScript…&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Conditional Statements
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;if else&lt;/code&gt; statements&lt;/li&gt;
&lt;li&gt;Ternary operators&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;switch&lt;/code&gt; statements&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;if else&lt;/code&gt; Statements
&lt;/h4&gt;

&lt;p&gt;The purpose of &lt;code&gt;if else&lt;/code&gt; statements is to make binary decisions–either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;–that tell a computer to do something. &lt;em&gt;All&lt;/em&gt; decisions are technically binary, and a final decision can be delineated from a series of binary decisions. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;if else&lt;/code&gt; Statements
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(*condition*) {
*code block*
}

else if(*condition*) {
*code block*
}

else {
*code block*
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (i % 2 === 0) {
    console.log(i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A condition is a small equation evaluated into a Boolean result, and it is evaluated at the time the program teaches that block of code. When using &lt;code&gt;if else&lt;/code&gt; statements, you can add as many conditions as you want. &lt;/p&gt;

&lt;p&gt;Any string, and indeed anything that is not a &lt;em&gt;falsy&lt;/em&gt; value, will be evaluated as &lt;code&gt;true&lt;/code&gt;. And in order to turn any truthy value into a falsy value, simply use a bang operator 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;if (!a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To combine conditions, you can add multiple into one conditional statement by using the AND operator &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or the OR operator &lt;code&gt;||&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Ternary Operators
&lt;/h4&gt;

&lt;p&gt;Ternary operators are a shorthand way to write &lt;code&gt;if else&lt;/code&gt; conditional statements. What’s special about them is that they are also &lt;em&gt;right-associative&lt;/em&gt;, which means that they can be chained. &lt;/p&gt;

&lt;h5&gt;
  
  
  When to Use Ternary Operators
&lt;/h5&gt;

&lt;p&gt;They are especially helpful for condensing code in cases where you only have one line of code to run after the evaluation of a condition. This may mean assigning a value or an increment. &lt;/p&gt;

&lt;p&gt;Another case where they are helpful is in handling &lt;code&gt;null&lt;/code&gt; values. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of Ternary Operators
&lt;/h5&gt;

&lt;p&gt;The ternary operator is the only JavaScript operator that takes 3 operands: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Condition followed by a question mark &lt;code&gt;?&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Expression to execute if Condition is truthy followed by a colon &lt;code&gt;:&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Expression to execute if Condition is falsey&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? exprIfTrue : exprIfFalse;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;

&lt;p&gt;This code logs the result of the ternary operator evaluation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var age = 26;
var beverage = (age &amp;gt;= 21) ? “Beer” : “Juice”;
console.log(beverage); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Handling &lt;code&gt;null&lt;/code&gt; Values
&lt;/h5&gt;

&lt;p&gt;Here’s a code example that allows an operation in the case of a &lt;code&gt;null&lt;/code&gt; value by replacing the variable that is &lt;code&gt;null&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let greeting = person =&amp;gt; 
    let name = person ? person.name : `stranger`
    return `Howdy, ${name}`
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Combining Conditions
&lt;/h5&gt;

&lt;p&gt;To combine conditions while using a ternary operator, you must add parentheses around each additional condition, with an intervening AND operator &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or an OR operator &lt;code&gt;||&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  Combining Operations
&lt;/h5&gt;

&lt;p&gt;Furthermore, while adding multiple operations, ternary operators can be chained 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;return condition1 ? value 1  // If ___ then ___
    : condition2 ? value2 // else if ___ then ___
    : condition3 ? value3 // else if ___ then ___
    : value4; // else ___
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The equivalent operations would need to be written in far more elaborate form using &lt;code&gt;if else&lt;/code&gt; statements, and would 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;if (condition1) {return value1;}
else if (condition2) {return value2;}
else if (condition3) {return value3;}
else {return value4;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Refactoring &lt;code&gt;if else&lt;/code&gt; Statements
&lt;/h5&gt;

&lt;p&gt;Here’s a situation where a ternary operator could reduce the code written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let status; // Variable waiting to be assigned a value 
if(age &amp;gt; 18) {
status = ‘adult’;
} else {
status = ‘child’;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code would be translated as such with a ternary operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const status = age &amp;gt; 18 ? ‘adult’: ‘child’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first value after &lt;code&gt;?&lt;/code&gt; is returned if &lt;code&gt;true&lt;/code&gt;, and the second value is returned if &lt;code&gt;false&lt;/code&gt;. Placed between the &lt;code&gt;=&lt;/code&gt; and the &lt;code&gt;&amp;gt;&lt;/code&gt; is the condition. &lt;/p&gt;

&lt;h4&gt;
  
  
  Comparison Operators
&lt;/h4&gt;

&lt;p&gt;Comparison operators always return a boolean value, and they are used in many languages, including JavaScript. &lt;/p&gt;

&lt;h5&gt;
  
  
  Types of Comparison Operators
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; Greater than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt; Less than&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; Greater than or equal to &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt; Less than or equal to&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; Loosely equal to

&lt;ul&gt;
&lt;li&gt;This operator converts values into the same type.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;!=&lt;/code&gt; Loosely not equal to&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;===&lt;/code&gt; Strictly equal to

&lt;ul&gt;
&lt;li&gt;This operator checks for the same value and the same type. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;!==&lt;/code&gt; Strictly not equal to &lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Logical Operators
&lt;/h4&gt;

&lt;p&gt;Local operators are used to connect two or more expressions in order to create a compound expression whose value is derived solely from the meaning of the original expressions and the operator(s) used.&lt;/p&gt;

&lt;h5&gt;
  
  
  Types of Logical Operators
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;And operator&lt;/li&gt;
&lt;li&gt;Or operator&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; AND Operator
&lt;/h5&gt;

&lt;p&gt;The AND operator requires both values to be &lt;code&gt;true&lt;/code&gt; in order to return &lt;code&gt;true&lt;/code&gt;. And the order of the two values does not affect the outcome. The operator does not check the second condition if the first is &lt;code&gt;false&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;||&lt;/code&gt; OR Operator
&lt;/h5&gt;

&lt;p&gt;The OR operator required either value to be &lt;code&gt;true&lt;/code&gt; to return &lt;code&gt;true&lt;/code&gt;. And it stops at the first condition evaluating as &lt;code&gt;true&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  Non-Boolean Values
&lt;/h5&gt;

&lt;p&gt;Using logical operators in JavaScript involves different semantics compared to other C-like languages. &lt;/p&gt;

&lt;p&gt;This is because logical operators can operate on expressions of any type in JavaScript, not &lt;em&gt;just&lt;/em&gt; booleans. Following this, logical operators in JavaScript do not always return a boolean value. The value returned will always be the value of one of the two operand expressions. &lt;/p&gt;

&lt;h5&gt;
  
  
  Return from Logical Operators
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; return the value of only one of their operands. This means that &lt;code&gt;A &amp;amp;&amp;amp; B&lt;/code&gt; returns the value &lt;code&gt;A&lt;/code&gt; if &lt;code&gt;A&lt;/code&gt; can be coerced into &lt;code&gt;false&lt;/code&gt;; otherwise, it returns &lt;code&gt;B&lt;/code&gt;. &lt;code&gt;A || B&lt;/code&gt; returns the value &lt;code&gt;A&lt;/code&gt; if &lt;code&gt;A&lt;/code&gt; can be coerced into &lt;code&gt;true&lt;/code&gt;; otherwise, it returns &lt;code&gt;B&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;However, in practice, it is difficult to notice that &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; don’t consistently return boolean values. &lt;code&gt;if&lt;/code&gt; statements and loops execute when a condition evaluates to a truthy value, which means it does not need to be an actual boolean. &lt;/p&gt;

&lt;h5&gt;
  
  
  Complications with Non-Boolean Values Returned
&lt;/h5&gt;

&lt;p&gt;For example, in a web application where users can be signed out and the &lt;code&gt;user&lt;/code&gt; object is &lt;code&gt;null&lt;/code&gt;, or they can be signed in and the &lt;code&gt;user&lt;/code&gt; object exists and has an &lt;code&gt;isAdmin&lt;/code&gt; property. &lt;/p&gt;

&lt;p&gt;To verify if the current user is an administrator, checking if the user is authenticated is necessary. This means checking if the &lt;code&gt;user&lt;/code&gt; object is not &lt;code&gt;null&lt;/code&gt;. And then, you would check the &lt;code&gt;isAdmin&lt;/code&gt; property to see if it's truthy. &lt;/p&gt;

&lt;p&gt;In the case that the &lt;code&gt;user&lt;/code&gt; object is not &lt;code&gt;null&lt;/code&gt; and the &lt;code&gt;user&lt;/code&gt; is an administrator, the &lt;code&gt;user&lt;/code&gt; object would be returned, rather than &lt;code&gt;true&lt;/code&gt;. The benefit is that this saves you the hassle of needing to check its existence and grabbing the data in separate operations. And in the case that the &lt;code&gt;user&lt;/code&gt; object is &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt; will be returned, rather than &lt;code&gt;false&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;However, this may be a problem if you have an &lt;code&gt;isAdministrator&lt;/code&gt; function which is meant to evaluate both conditions and return a boolean value because the prefix of the function is &lt;code&gt;is&lt;/code&gt;, thus concluding its purpose of returning &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  Convert Truthy/Falsy Value into a Proper Boolean
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Option 1: Implicit Coercion
&lt;/h6&gt;

&lt;p&gt;You can coerce a value into a boolean by using the logical NOT operator, which is the bang operator, and apply it twice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use Case Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isAdministrator(user) {
    return !!(user &amp;amp;&amp;amp; user.isAdmin);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Double Bang Operator&lt;/em&gt;&lt;br&gt;
The first &lt;code&gt;!&lt;/code&gt; returns the value &lt;code&gt;false&lt;/code&gt; if the value can be coerced into &lt;code&gt;true&lt;/code&gt;. If the value cannot be coerced into &lt;code&gt;true&lt;/code&gt;, it will return &lt;code&gt;true&lt;/code&gt;. What is returned is always a proper boolean, however the truthiness of the value is reversed. And then the second &lt;code&gt;!&lt;/code&gt; undoes the reversal of the truthiness of the value. &lt;/p&gt;
&lt;h6&gt;
  
  
  Option 2: Explicit Coercion
&lt;/h6&gt;

&lt;p&gt;You can explicitly coerce a value into a boolean by calling the &lt;code&gt;Boolean&lt;/code&gt; Function. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use Case Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isAdministrator(user) {
    return Boolean(user &amp;amp;&amp;amp; user.isAdmin);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Switch Statements
&lt;/h4&gt;

&lt;p&gt;Switch statements are another way to write a conditional, but it is less used. It takes in the variable and compares it to the value of each &lt;code&gt;case&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;It is a type of conditional statement that evaluates an expression against multiple possible cases and executes one or more blocks of code depending on which cases match. Using switch statements is like using a conditional statement with numerous &lt;code&gt;else if&lt;/code&gt; blocks.&lt;/p&gt;

&lt;h5&gt;
  
  
  Related Keywords for Switch Statements
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;case&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;break&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;default&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;switch&lt;/code&gt; Statements
&lt;/h5&gt;

&lt;p&gt;A &lt;code&gt;switch&lt;/code&gt; statement is always applied using &lt;code&gt;switch () {}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Inside the parentheses is the expression to be tested. And inside the curly braces are the cases along with the code blocks that may be run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch(*variable name*) {
case *value*:
console.log(“”);  // Code block executed on Truthy value
break;
case *value*:
console.log(“”);
break;
default:  // Equivalent to: “else”
console.log(“”);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each &lt;code&gt;case&lt;/code&gt; is evaluated by strict equality, and the cases are checked in chronological order. This example has 2 &lt;code&gt;case&lt;/code&gt; statements and &lt;code&gt;default&lt;/code&gt; is a fallback.&lt;/p&gt;

&lt;p&gt;Here are the things that happen throughout the switch statement:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The expression is evaluated and the value is retrieved &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The value of the first &lt;code&gt;case&lt;/code&gt; is compared with the value of the expression. If there is a match, the code block within the case will run, and the &lt;code&gt;break&lt;/code&gt; keyword will end the &lt;code&gt;switch&lt;/code&gt; block. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If it is not matched with the first &lt;code&gt;case&lt;/code&gt;, the code block within that &lt;code&gt;case&lt;/code&gt; will be overlooked, and the value of the next &lt;code&gt;case&lt;/code&gt; will be compared with the value of the expression.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the value of that case matches the value of the expression, the code block will run and then exit out of the &lt;code&gt;switch&lt;/code&gt; block due to the &lt;code&gt;break&lt;/code&gt; statement. &lt;/p&gt;

&lt;p&gt;If none of the values of the cases match the value of the expression, the code block after the &lt;code&gt;default&lt;/code&gt; statement will run. &lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;

&lt;p&gt;The following code block shows the month of the event with the &lt;code&gt;getEvent()&lt;/code&gt; method, which receives the id of the event as an argument and returns an object with all the event details. On this event object, there is a &lt;code&gt;month&lt;/code&gt; property, which is called, retrieving the number representing the month.&lt;/p&gt;

&lt;p&gt;With a &lt;code&gt;switch&lt;/code&gt; statement, you can print the appropriate month name. The cases will be considered in chronological order and compared with the value of the expression. &lt;/p&gt;

&lt;p&gt;When a matching case is discovered, the code block will run, and the &lt;code&gt;break&lt;/code&gt; statement at the end of that code block will stop the program from evaluating the rest of the cases and exit the switch statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Set the month of the event to a variable, with 1 as January and 12 as December
const numMonth = getEvent(239).month;

switch (numMonth) {
    case 1:
        setMonth(‘January’);
        break;
case 2:
        setMonth(‘February’);
        break;
case 3:
        setMonth(‘March’);
        break;
case 4:
        setMonth(‘April’);
        break;
case 5:
        setMonth(‘May’);
        break;
case 6:
        setMonth(‘June’);
        break;
case 7:
        setMonth(‘July’);
        break;
case 8:
        setMonth(‘August’);
        break;
case 9:
        setMonth(‘September’);
        break;
    case 10:
        setMonth(‘October’);
        break;
    case 11:
        setMonth(‘November’);
        break;
    case 12:
setMonth(‘December’);
        break;
    default:
        setMonth(getCurrentMonth());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the month of the event is &lt;code&gt;3&lt;/code&gt;, then the &lt;code&gt;month&lt;/code&gt; state will be set to the value of &lt;code&gt;March&lt;/code&gt;. And depending on the Event id passed through the getEvent() function, the month will be set to different strings. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;default&lt;/code&gt; block is included at the end to be executed in case of an error where a number not corresponding 1-12 is passed. &lt;/p&gt;

&lt;p&gt;Another use case could be to only set the value of month if the month is within the next three months in order to pull events happening soon in the future. This would mean that events would only be allowed to be in these months; and if the user input fell beyond these months, it would forcibly default to the current month. &lt;/p&gt;

&lt;p&gt;If the &lt;code&gt;break&lt;/code&gt; keyword was not added to the end of each case code block, then none of the other &lt;code&gt;case&lt;/code&gt; statements would have evaluated to &lt;code&gt;true&lt;/code&gt;, but it would have been wasted energy sifting through the extra &lt;code&gt;case&lt;/code&gt;s. &lt;/p&gt;

&lt;p&gt;To make your program faster and more efficient, include &lt;code&gt;break&lt;/code&gt; statements. &lt;/p&gt;

&lt;h5&gt;
  
  
  Switch Ranges
&lt;/h5&gt;

&lt;p&gt;If you want to evaluate a range of values in a &lt;code&gt;switch&lt;/code&gt; statement, instead of just one, you can do so by setting the expression to &lt;code&gt;true&lt;/code&gt;, and then doing an operation within each &lt;code&gt;case&lt;/code&gt; statement specifying different conditions on each &lt;code&gt;case&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since the match is auto-set to evaluate to &lt;code&gt;true&lt;/code&gt;, now the expression after &lt;code&gt;case&lt;/code&gt; will act like the condition after &lt;code&gt;if&lt;/code&gt; in &lt;code&gt;if else&lt;/code&gt; statements, and each &lt;code&gt;case&lt;/code&gt; will be evaluated chronologically until one condition is met or the &lt;code&gt;switch&lt;/code&gt; statement defaults. &lt;/p&gt;

&lt;p&gt;You need to evaluate each &lt;code&gt;case&lt;/code&gt; to see if the expression evaluates to &lt;code&gt;true&lt;/code&gt;, run the appropriate code, and then break out of the &lt;code&gt;switch&lt;/code&gt; statement. &lt;/p&gt;

&lt;h6&gt;
  
  
  Use Case Example
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Set the time of the event 
const time = 1800;

switch (true) {
    case time &amp;gt;= 1800:
        setEventTime(‘Evening’);
        break;
    case time &amp;gt;= 1200:
        setEventTime(‘Afternoon’);
        break;
    case time &amp;gt;= 0:
        setEventTime(‘Morning’);
        break;
    default:
        setEventTime(‘Ambiguous’);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expression in the parentheses to be evaluated is &lt;code&gt;true&lt;/code&gt;, meaning that any &lt;code&gt;case&lt;/code&gt; that evaluates to &lt;code&gt;true&lt;/code&gt; will be a match. In the code above, the &lt;code&gt;eventTime&lt;/code&gt; state will be set to &lt;code&gt;‘Evening’&lt;/code&gt;.  &lt;/p&gt;

&lt;h5&gt;
  
  
  Multiple Cases
&lt;/h5&gt;

&lt;p&gt;If you want to have the same output for multiple different &lt;code&gt;case&lt;/code&gt;s, you can use more than one &lt;code&gt;case&lt;/code&gt; for each block of code.&lt;/p&gt;

&lt;h6&gt;
  
  
  Use Case Example
&lt;/h6&gt;

&lt;p&gt;For example, if you want to match the time after 1800 &lt;strong&gt;and&lt;/strong&gt; the time before 700 to &lt;code&gt;'Evening'&lt;/code&gt;, you can do so 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;// Get number corresponding to the time of the event
const time = getEvent(431).getTime(); 

switch (true) {
    case time &amp;gt;= 1800:
    case time &amp;lt;= 700:
        setEventTime(‘Evening’);
        break;
    case time &amp;gt;= 1200:
        setEventTime(‘Afternoon’);
        break;
    case time &amp;gt;= 0:
        setEventTime(‘Morning’);
        break;
    default:
        setEventTime(‘Ambiguous’);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will result in an output setting the &lt;code&gt;eventTime&lt;/code&gt; state to the time of day depending on the conditions above.&lt;/p&gt;

&lt;p&gt;Although &lt;code&gt;1800&lt;/code&gt; would evaluate to &lt;code&gt;true&lt;/code&gt; for the other 2 &lt;code&gt;case&lt;/code&gt;s as well, the first match is for &lt;code&gt;‘Evening’&lt;/code&gt;, so that will be set to the &lt;code&gt;EventTime&lt;/code&gt; variable. &lt;/p&gt;

&lt;p&gt;The same can be applied to normal switch cases (not switch ranges). &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;switch&lt;/code&gt; vs &lt;code&gt;if else&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Some similarities between &lt;code&gt;switch&lt;/code&gt; statements and &lt;code&gt;if else&lt;/code&gt; statements include the fact that they are both evaluated from top to bottom and also that the first &lt;code&gt;true&lt;/code&gt; returned is accepted. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;switch&lt;/code&gt; statements are advantageous due to their high readability and ability to evaluate the same variable at different values.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Loops?
&lt;/h3&gt;

&lt;p&gt;Loops loop over the same block of code until a certain condition is met. Different types of loops provide different methods of curating the beginning and end points of a loop. &lt;/p&gt;

&lt;p&gt;Loops will be written a lot. In every programming language, there are loops, control flow, &amp;amp; conditionals. And learning about loops is a part of software literacy. &lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Loops
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;do while&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;while&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for in&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for of&lt;/code&gt; loop&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;forEach&lt;/code&gt; loop&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;do while&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;do while&lt;/code&gt; loop runs a statement, and then repeats the statement(s) until a specified condition evaluates to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;do while&lt;/code&gt; Loops
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do
    statement 
while (condition); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The statement is always run one time before the condition is evaluated. If you want to run many statements, use a block statement &lt;code&gt;{}&lt;/code&gt; to group them. If the condition is evaluated to &lt;code&gt;true&lt;/code&gt;, the statement runs again. &lt;/p&gt;

&lt;p&gt;The condition is checked upon the &lt;em&gt;conclusion&lt;/em&gt; of each execution. When the condition returns &lt;code&gt;false&lt;/code&gt;, the execution stops, and the program moves onto the code after the &lt;code&gt;do while&lt;/code&gt; loop. &lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i = 0;
do {
    i += 1;
    console.log(i);
} while (i &amp;lt; 20);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;do&lt;/code&gt; loop iterates at least once and reiterates until &lt;code&gt;i&lt;/code&gt; is no longer less than &lt;code&gt;20&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;while&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;while&lt;/code&gt; loop continues executing its statements given that a specified condition evaluates to &lt;code&gt;true&lt;/code&gt;. It checks the condition at the &lt;em&gt;start&lt;/em&gt; of each loop, and after code execution, it returns to check the condition. If the condition evaluates as &lt;code&gt;true&lt;/code&gt;, it runs the code block again.&lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;while&lt;/code&gt; Loops
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition)
    statement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The evaluation of the condition is done &lt;em&gt;before&lt;/em&gt; the statement in the loop is run. And if the condition returns &lt;code&gt;true&lt;/code&gt;, then the &lt;code&gt;statement&lt;/code&gt; is run, and the &lt;code&gt;condition&lt;/code&gt; is evaluated again. If you want to run a series of statements, you can do so using a block statement &lt;code&gt;{}&lt;/code&gt; to group them. &lt;/p&gt;

&lt;p&gt;If the condition evaluates to &lt;code&gt;false&lt;/code&gt;, then the statement(s) within the loop are not executed, and the program moves onto the next line of code after the loop. &lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 10;
while(a &amp;gt; 5) {
console.log (`a is now ${a}`);
a--;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program goes back to the top of the loop with the new value, and then checks the condition in the &lt;code&gt;()&lt;/code&gt; again. After the condition is met and the loop ends, the program moves onto the next line of code after the &lt;code&gt;while&lt;/code&gt; loop.&lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example #2
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = 0;
let x = 0;
while (n &amp;lt; 50) {
    n++;
    x += n;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;while&lt;/code&gt; loop iterates as long as &lt;code&gt;n&lt;/code&gt; is less than 50. And during each iteration, the loop increments &lt;code&gt;n&lt;/code&gt; and adds that value to &lt;code&gt;x&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;During the first execution, &lt;code&gt;n&lt;/code&gt; takes the value of &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt; takes the value of &lt;code&gt;1&lt;/code&gt;. During the second execution, &lt;code&gt;n&lt;/code&gt; takes the value of &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt; takes the value of &lt;code&gt;3&lt;/code&gt;. And during the third execution, &lt;code&gt;n&lt;/code&gt; takes the value of &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt; takes the value of &lt;code&gt;6&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After the code has executed 50 times, the condition &lt;code&gt;n &amp;lt; 50&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt;, and then the loop ends. &lt;/p&gt;

&lt;h5&gt;
  
  
  Infinite Loop
&lt;/h5&gt;

&lt;p&gt;Infinite loops are possible in both &lt;code&gt;while&lt;/code&gt; and &lt;code&gt;do while&lt;/code&gt; loops, as long as the condition is always evaluated to &lt;code&gt;true&lt;/code&gt;. This allows for the code block to run for an infinite number of times, which will lead to your application crashing. &lt;/p&gt;

&lt;p&gt;It is important to ensure the condition in &lt;code&gt;while&lt;/code&gt; and &lt;code&gt;do while&lt;/code&gt; loops becomes &lt;code&gt;false&lt;/code&gt; at some point. You must modify the variable after each loop, which can be done by providing an incrementer or decrementer.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;while&lt;/code&gt; vs &lt;code&gt;do while&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The key difference between these two loops is the order of operations. &lt;/p&gt;

&lt;p&gt;In a &lt;code&gt;while&lt;/code&gt; loop, the program first checks that the condition evaluates to &lt;code&gt;true&lt;/code&gt;, then runs the code block. In a &lt;code&gt;do while&lt;/code&gt; loop, first, the code block is run, and then the condition is evaluated to determine whether to rerun the code. &lt;/p&gt;

&lt;p&gt;This means that &lt;code&gt;do while&lt;/code&gt; loops ensure the code block is run &lt;em&gt;at least&lt;/em&gt; once; and it is possible for the code in a &lt;code&gt;while&lt;/code&gt; loop to never run. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;while&lt;/code&gt; vs &lt;code&gt;for&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The main advantage of using a &lt;code&gt;while&lt;/code&gt; loop is that it is flexible. This means that it can be made dynamic to the user input. This is useful when you do not know the number of times the loop needs to be run, or when you do not know the specific intent of the loop. &lt;/p&gt;

&lt;p&gt;However, using a &lt;code&gt;for&lt;/code&gt; loop may be better for cases that are more specific. This means that it is useful for looping over arrays, looping over a specific number of lines, or when you know the specific number of times you want to run a code block. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;for&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; loop is similar to the &lt;code&gt;while&lt;/code&gt; loop, but the syntax is different. Nonetheless, the concepts are quite straightforward. &lt;/p&gt;

&lt;p&gt;An advantage of &lt;code&gt;for&lt;/code&gt; loops is the fact that they are self-contained, which means that they cannot accidentally have an infinite loop the way that &lt;code&gt;while&lt;/code&gt; loops can. This is useful when iterating overall, or through a subset of items. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;for&lt;/code&gt; Loops
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(*initial variable*; *condition*; *alteration*) {
*code block = directs logic of code: tells app how to make a decision*
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember that semicolons are necessary within the parentheses &lt;code&gt;()&lt;/code&gt; after &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt;, but they are not necessary within the curly braces &lt;code&gt;{}&lt;/code&gt; after the parentheses &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;for&lt;/code&gt; Loop Condition
&lt;/h5&gt;

&lt;p&gt;There are 3 parts of a &lt;code&gt;for&lt;/code&gt; loop condition. First, the initialisation of a variable to use as part of the condition. Second, the actual condition that’ll evaluate &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. And third, the incrementer to bring you closer to the end of the condition. &lt;/p&gt;

&lt;p&gt;The incrementing will continue until the condition evaluates to &lt;code&gt;false&lt;/code&gt;, and at which point, the program moves onto the rest of the code. &lt;/p&gt;

&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(let a = 1; a &amp;lt; 5; a++) {
console.log(`a is now ${a}`);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The block of code will continue to run as long as the &lt;code&gt;for&lt;/code&gt; loop condition returns &lt;code&gt;true&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;for in&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;for in&lt;/code&gt; loop iterates a specified variable over all the keys inside an Object that are &lt;strong&gt;both&lt;/strong&gt; user-defined &lt;strong&gt;and numeric indices&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;For each distinct property, JavaScript runs the specified statements inside the &lt;code&gt;for in&lt;/code&gt; loop. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;for in&lt;/code&gt; Loops
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (variable in object) 
    statement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;

&lt;p&gt;This function takes an argument of an object and the object’s name. Then, it iterates over all the parent object’s properties and returns a string that lists the property names and values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newProps(object, objectName) {
    let result = ‘’;
    for (const i in object) {
        result += `${objectName}.${i} = ${obj[i]}&amp;lt;br&amp;gt;`;
    }
    result += ‘&amp;lt;hr&amp;gt;’;
    return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For an Object named &lt;code&gt;event&lt;/code&gt; with properties &lt;code&gt;month&lt;/code&gt; and &lt;code&gt;year&lt;/code&gt;, &lt;code&gt;result&lt;/code&gt; returned would be:&lt;br&gt;
&lt;code&gt;event.month = September&lt;/code&gt;&lt;br&gt;
&lt;code&gt;event.year = 2022&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Technically, user-defined properties (like custom properties or methods) can be assigned to arrays, so to ensure only numerically indexed array elements are accessed, rather than accessing both user-defined and numeric indices, use a &lt;code&gt;for of&lt;/code&gt; loop instead.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for in&lt;/code&gt; loops can be used for both iterables and objects; nonetheless, using &lt;code&gt;for in&lt;/code&gt; loops on iterables should be avoided. &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Object.keys()&lt;/code&gt; vs &lt;code&gt;for in&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;for in&lt;/code&gt; loop has the same utility as &lt;code&gt;Object.keys()&lt;/code&gt;. If you only want to return the keys of an object, &lt;code&gt;Object.keys()&lt;/code&gt; may be the way to go. &lt;/p&gt;

&lt;p&gt;However, if you wish also to perform an operation for each element iterated through, &lt;code&gt;for in&lt;/code&gt; will be the faster way to do so, since using &lt;code&gt;Object.keys()&lt;/code&gt; and then a &lt;code&gt;forEach()&lt;/code&gt; requires passing a callback during &lt;em&gt;every&lt;/em&gt; iteration.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;for&lt;/code&gt; vs &lt;code&gt;for in&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Both &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;for in&lt;/code&gt; loops give access to the index of each element in an array and not the actual element value. This means that you still need to use the array name, followed by the given index, in order to find the element value. &lt;/p&gt;
&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [‘Angeline’, ‘Sarah’, ‘Laura’]

for (let i = 0; i &amp;lt; arr.length; ++i) {
    console.log(arr[i]);
}

for (let i in arr) {
    console.log(arr[i]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;for of&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;for of&lt;/code&gt; statements create a loop that iterates over iterable objects. It will invoke a custom iteration hook with statements to be executed for the value of each distinct property. &lt;/p&gt;

&lt;p&gt;The difference between a &lt;code&gt;for of&lt;/code&gt; loop and a &lt;code&gt;for in&lt;/code&gt; loop is that a &lt;code&gt;for of&lt;/code&gt; loop iterates over property &lt;em&gt;values&lt;/em&gt;, instead of names. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;for of&lt;/code&gt; loops (without additional aid) cannot be used to iterate over an object, it can only be used to iterate over iterable objects. &lt;/p&gt;
&lt;h5&gt;
  
  
  When to use &lt;code&gt;for of&lt;/code&gt; loops
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;for of&lt;/code&gt; loops are the best way to iterate over an array in JavaScript because they are more concise than the conventional &lt;code&gt;for&lt;/code&gt; loop and &lt;strong&gt;also&lt;/strong&gt; does not have as many edge cases as &lt;code&gt;for in&lt;/code&gt; and &lt;code&gt;forEach()&lt;/code&gt; loops. &lt;/p&gt;

&lt;p&gt;However, &lt;code&gt;for of&lt;/code&gt; loops do take extra work to access element indices, and you cannot chain them like you can do with &lt;code&gt;forEach()&lt;/code&gt; loops. &lt;/p&gt;
&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;for of&lt;/code&gt; Loops
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (const element of array) {
    console.log(element)

// Each array element is being assigned to the variable named “element” during each iteration until all the elements have been iterated upon 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The first part within the parentheses before &lt;code&gt;of&lt;/code&gt; is a variable declaration (with anything before the &lt;code&gt;=&lt;/code&gt; operator), which can be done with &lt;code&gt;let&lt;/code&gt; &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; can be used so long as the variable is not reassigned within the code block. Between iterations, the function context is considered new, so it is okay to use &lt;code&gt;const&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If the elements within the iterable are objects, you can also destructure the object property like so: &lt;code&gt;for (event.date of events)&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;for of&lt;/code&gt; vs &lt;code&gt;for in&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;There are two important factors that differ in terms of &lt;code&gt;for of&lt;/code&gt; and &lt;code&gt;for in&lt;/code&gt; loops: &lt;/p&gt;

&lt;p&gt;First is what &lt;strong&gt;part&lt;/strong&gt; of each element they iterate over and return. &lt;code&gt;for in&lt;/code&gt; loops iterate over the &lt;em&gt;keys&lt;/em&gt; of each element, while &lt;code&gt;for of&lt;/code&gt; loops iterate over the &lt;em&gt;values&lt;/em&gt; of each element.&lt;/p&gt;

&lt;p&gt;Second is what &lt;strong&gt;kind&lt;/strong&gt; of elements they include in their operations.  &lt;code&gt;for of&lt;/code&gt; loops only iterate through elements with &lt;em&gt;numeric&lt;/em&gt; array index keys, so they only work for array-type objects. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;for in&lt;/code&gt; loops do not discriminate based on the origins of keys, and include all elements, with either &lt;em&gt;numeric&lt;/em&gt; array indices as keys &lt;strong&gt;and&lt;/strong&gt; &lt;em&gt;user-generated&lt;/em&gt; elements with string keys. &lt;/p&gt;
&lt;h5&gt;
  
  
  Comparison Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [1, 2, 3];
arr.greeting = ‘good afternoon’;

// for of 
for (const i of arr) {
    console.log(i);
}
// Prints: “1” “2” “3” 

// for in
for (const i in arr) {
    console.log(i);
}
// Prints: “0” “1” “2” “greeting”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you wish to return the &lt;em&gt;values&lt;/em&gt; of elements including those with &lt;em&gt;user-generated&lt;/em&gt; string keys, you can do so by using a &lt;code&gt;for in&lt;/code&gt; loop with &lt;strong&gt;bracket notation&lt;/strong&gt;. All keys, including user-generated ones, can be passed inside the brackets after the object name, 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;const arr = [1, 2, 3];

arr.greeting = “good afternoon”;

for (const i in arr) {
    console.log(arr[i])
} // Prints: “1” “2” “3” “good afternoon”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It seems there is no premeditated way to return only the &lt;em&gt;keys&lt;/em&gt; that are numeric array index keys. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Object.entries()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Both &lt;code&gt;for of&lt;/code&gt; and &lt;code&gt;for in&lt;/code&gt; loops can also be used with destructuring. For example, they can both simultaneously loop over keys and values of an object with &lt;code&gt;Object.entries()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With the use of &lt;code&gt;Object.entries()&lt;/code&gt;, an array (with numeric indices as keys) is created from an object (previously array or non-array). This means that by replacing the &lt;code&gt;arr&lt;/code&gt; with &lt;code&gt;Object.entries(arr)&lt;/code&gt;, even an object with &lt;em&gt;user-generated&lt;/em&gt; string keys can be used with &lt;code&gt;for of&lt;/code&gt;, 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;// for of 
const obj = { angeline: 10, laura: 20 };

for (const [key, val] of Object.entries(obj)) {
    console.log(key, val);
}
// Prints: 
// “angeline” 10
// “laura” 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;forEach&lt;/code&gt; Loops
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;forEach&lt;/code&gt; loops are useful for iterating through all the items in a collection. It is read-only, meaning it cannot modify items as they are being iterated through. &lt;/p&gt;

&lt;h5&gt;
  
  
  When to Use &lt;code&gt;forEach&lt;/code&gt; Loops
&lt;/h5&gt;

&lt;p&gt;A good rule of thumb is to use &lt;code&gt;forEach&lt;/code&gt; sparingly because it comes with many edge cases. However, there are still many cases where it can be used to make code more concise.&lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;forEach&lt;/code&gt; Loops
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const guests = [‘Angeline’, ‘Laura’, ‘Sarah’];

guests.forEach(guest =&amp;gt; console.log(guest));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;forEach&lt;/code&gt; loop takes a callback function that is used on each element within the array. The callback function takes a mandatory current value parameter, and optionally, the index and the array object. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;forEach&lt;/code&gt; vs &lt;code&gt;for of&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;One similarity between &lt;code&gt;forEach&lt;/code&gt; and &lt;code&gt;for of&lt;/code&gt; is the fact that they both access the array element value itself. One difference is that the &lt;code&gt;forEach&lt;/code&gt; loop can access both the value and the index, which can be passed in as the second parameter.&lt;/p&gt;

&lt;h5&gt;
  
  
  Comparison Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr.forEach((v, i) =&amp;gt; console.log(v));

for (const v of arr) {
    console.log(v);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One case where you would choose to use &lt;code&gt;for of&lt;/code&gt; instead of &lt;code&gt;forEach&lt;/code&gt; is if you want to ensure prevention of “holes” in your user data, which can result from empty array elements. &lt;/p&gt;

&lt;h4&gt;
  
  
  Labeled Statements
&lt;/h4&gt;

&lt;p&gt;You can add a &lt;code&gt;label&lt;/code&gt; to a statement to act as an identifier you can reference elsewhere in your program. &lt;/p&gt;

&lt;h5&gt;
  
  
  When to Use Labeled Statements
&lt;/h5&gt;

&lt;p&gt;A label is useful for identifying a loop, and then to use &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; statements to show if the program should interrupt the loop or continue its execution. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of Labeled Statements
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;label: // This can be any JS identifier, excluding reserved words
    statement // Can be any statement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;angelineLoop:
while (isAngeline) {
    doSomething();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Non-Numeric Properties
&lt;/h4&gt;

&lt;p&gt;Since JavaScript arrays are objects, it is possible to also add string properties to an array, not just the number indices. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;for of&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;forEach&lt;/code&gt; loops all ignore non-numeric properties and print out &lt;em&gt;only&lt;/em&gt; numeric properties; however, &lt;code&gt;for in&lt;/code&gt; loops will print out &lt;em&gt;both&lt;/em&gt; numeric &lt;em&gt;and&lt;/em&gt; non-numeric properties. &lt;/p&gt;

&lt;p&gt;This means that by default, it is best to use &lt;code&gt;for of&lt;/code&gt; loops on arrays with only numeric properties. &lt;/p&gt;

&lt;h4&gt;
  
  
  Empty Elements
&lt;/h4&gt;

&lt;p&gt;You are allowed to have empty elements in a JavaScript array, but the 4 looping constructs will handle empty elements differently. &lt;code&gt;for in&lt;/code&gt; and &lt;code&gt;forEach&lt;/code&gt; loops will skip the empty element; while &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;for of&lt;/code&gt; loops do not skip the empty element, and instead prints out &lt;code&gt;undefined&lt;/code&gt;in its place.&lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [‘Angeline’, , ‘Laura’];

arr.length; // 3

for (let i = 0; i &amp;lt; arr.length; ++i) {
    console.log(arr[i]); // Prints “Angeline, undefined, Laura”
}

arr.forEach(v =&amp;gt; console.log(v)); // Prints “Angeline, Laura”

for (let i in arr) {
    console.log(arr[i]); // Prints “Angeline, Laura”
}

for (const v of arr) {
    console.log(v); // Prints “Angeline, undefined, Laura”
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This behaviour only occurs when there is literally an empty array element. If the array element has a value of &lt;code&gt;undefined&lt;/code&gt;, the 4 looping constructs will universally print &lt;code&gt;“Angeline, undefined, Laura”&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Add Empty Array Element
&lt;/h5&gt;

&lt;p&gt;If an element at a larger index than the logical subsequent is added, the intermediary indices in the array will be filled with empty elements.&lt;/p&gt;

&lt;h6&gt;
  
  
  Use Case Example
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [“Angeline”, “Sarah”, “Laura”];
arr[5] = “Maya”;

// Equivalent to [“Angeline”, “Sarah”, “Laura”, , “Maya”]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;forEach()&lt;/code&gt; and &lt;code&gt;for in&lt;/code&gt; loops skip empty elements in the array. &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;for of&lt;/code&gt; loops do not. &lt;/p&gt;

&lt;h5&gt;
  
  
  Interaction with JSON
&lt;/h5&gt;

&lt;p&gt;However, empty elements are not supported in JSON, and will be marked as a &lt;code&gt;SyntaxError: Unexpected token&lt;/code&gt;. Thus, it is rare that empty elements will be used. &lt;/p&gt;

&lt;p&gt;Likely, &lt;code&gt;null&lt;/code&gt; will be used in place of any empty elements. This means that the behaviour of &lt;code&gt;forEach()&lt;/code&gt; and &lt;code&gt;for in&lt;/code&gt; loops when treating empty elements will rarely cause a practical issue. &lt;/p&gt;

&lt;p&gt;When &lt;code&gt;for…in&lt;/code&gt; and &lt;code&gt;forEach()&lt;/code&gt; loops skip empty elements in an array, this behaviour is called “holes”. Any “holes” should likely be treated as having a value of &lt;code&gt;undefined&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;It is possible to disallow using &lt;code&gt;forEach()&lt;/code&gt; in order to prevent cases of holes. You can write a &lt;code&gt;.eslintrc.yml&lt;/code&gt; file with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parserOptions:
    ecmaVersion: 2018
rules:
    no-restricted-syntax:
        - error
        - selector: CallExpression[callee.property.name="forEach"]
          message: Do not use `forEach()`, use `for/of` instead
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Function Context
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;for&lt;/code&gt;, &lt;code&gt;for in&lt;/code&gt; and &lt;code&gt;for of&lt;/code&gt; loops retain the outside scope’s value of &lt;code&gt;this&lt;/code&gt;. And the &lt;code&gt;forEach()&lt;/code&gt; callback will have a different &lt;code&gt;this&lt;/code&gt; unless you use an array function. &lt;/p&gt;

&lt;p&gt;If you want to ensure that all 4 types of loops access the same value for &lt;code&gt;this&lt;/code&gt;, you need to enforce a rule to only allow &lt;code&gt;forEach()&lt;/code&gt; loops to be used with arrow functions. This can be done through the &lt;code&gt;no-arrow-callback&lt;/code&gt; ESLint rule to require arrow functions for all callbacks that don’t use &lt;code&gt;this&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Async/Await Generators
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;forEach()&lt;/code&gt; loops do not precisely work with async/await or generators. Inside an &lt;code&gt;async&lt;/code&gt; function that has a &lt;code&gt;forEach()&lt;/code&gt; callback function, you cannot use an &lt;code&gt;await&lt;/code&gt;, nor can you use a &lt;code&gt;yield&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Syntax errors will be thrown if code like below is written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function run() {
    const arr = [ ‘Angeline’, ‘Sarah’, ‘Laura’];
    arr.forEach(el =&amp;gt; {
        // SyntaxError
        await new Promise(resolve =&amp;gt; setTimeout(resolve, 1000));
        console.log(el);
    });
}

function* run() {
    const arr = [‘Angeline’, ‘Sarah’, ‘Laura’];
    arr.forEach(el =&amp;gt; {
        yield new Promise(resolve =&amp;gt; setTimeout(resolve, 1000));
        console.log(el);
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the 2 code examples do work with &lt;code&gt;for of&lt;/code&gt; loops, 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;async function asyncFn() {
    const arr = [‘Angeline’, ‘Sarah’, ‘Laura’’];
    for (const el of arr) {
        await new Promise(resolve =&amp;gt; setTimeout(resolve, 1000));
        console.log(el);
    }
}

function* generatorFn() {
    const arr = [‘Angeline’, ‘Sarah’, ‘Laura’];
    for (const el of arr) {
        yield new Promise(resolve =&amp;gt; setTimeout(resolve, 1000));
        console.log(el);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using async/await or generators, &lt;code&gt;forEach()&lt;/code&gt; is syntactic sugar, so it should be used sparingly and not for everything.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Control Loops
&lt;/h3&gt;

&lt;p&gt;There are 2 control flow statements that can be used as operators to further manipulate the execution of code within loops:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;break&lt;/code&gt; statements&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;continue&lt;/code&gt; statements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These can be applied to &lt;code&gt;switch&lt;/code&gt; statements or any of the loops (excluding &lt;code&gt;forEach&lt;/code&gt;) to alter the normal control flow of the loop. Where a statement is exited prematurely, clean-up will be performed with the &lt;code&gt;return()&lt;/code&gt; method of the iterator.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;break&lt;/code&gt; Statements
&lt;/h4&gt;

&lt;p&gt;The purpose of &lt;code&gt;break&lt;/code&gt; statements is to terminate a loop, a &lt;code&gt;switch&lt;/code&gt; statement, or it can be used with a labeled statement.&lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;break&lt;/code&gt; Statement
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;break;
break label;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; events.length; i++) {
    if (events[i] === ‘party’) {
        break;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This iterates through the elements in an array until the program finds the index of an element whose value is &lt;code&gt;‘party’&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  Using &lt;code&gt;break&lt;/code&gt; without a Label
&lt;/h5&gt;

&lt;p&gt;If you use a &lt;code&gt;break&lt;/code&gt; statement without a label, you will immediately stop the innermost enclosing &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do while&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; and move onto the next line of code after the &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do while&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; statement.&lt;/p&gt;

&lt;h5&gt;
  
  
  Using &lt;code&gt;break&lt;/code&gt; with a Label
&lt;/h5&gt;

&lt;p&gt;If you use a &lt;code&gt;break&lt;/code&gt; statement with a label, you will stop the specified labeled statement and move onto the line of case after the &lt;code&gt;break&lt;/code&gt; statement. &lt;/p&gt;

&lt;h5&gt;
  
  
  Break to a Label
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 0;
let z = 0;
labelCancelLoops: while (true) {
    console.log(‘Outer loops: ’, x);
    x += 1;
    z = 1;
    while (true) {
        console.log(‘Inner loops: ’, z);
        z += 1;
        if (z === 10 &amp;amp;&amp;amp; x === 10) {
            break labelCancelLoops;
        } else if (z === 10) {
            break;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;continue&lt;/code&gt; Statements
&lt;/h4&gt;

&lt;p&gt;A &lt;code&gt;continue&lt;/code&gt; statement can be applied to restart a &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do while&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt; loop or &lt;code&gt;label&lt;/code&gt; statement. &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax of &lt;code&gt;continue&lt;/code&gt; Statement
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;continue;
continue label;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;continue&lt;/code&gt; will end the current iteration (leaving remaining code in the block untouched), but it will go back to the start of the loop at the condition and run the loop again. It will not completely break out of the loop as a whole onto the next line of code, it just breaks out of the current &lt;em&gt;iteration&lt;/em&gt; of the loop. &lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example
&lt;/h5&gt;

&lt;p&gt;Here is a &lt;code&gt;while&lt;/code&gt; loop with a &lt;code&gt;continue&lt;/code&gt; statement that runs when the value of &lt;code&gt;i&lt;/code&gt; is &lt;code&gt;5&lt;/code&gt;. &lt;code&gt;n&lt;/code&gt; takes on the values &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;3&lt;/code&gt;, &lt;code&gt;6&lt;/code&gt;, &lt;code&gt;10&lt;/code&gt;, &lt;code&gt;16&lt;/code&gt;, &lt;code&gt;23&lt;/code&gt;, &lt;code&gt;31&lt;/code&gt;, &lt;code&gt;40&lt;/code&gt;, &lt;code&gt;50&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i = 0;
let n = 0;
while (i &amp;lt; 10) {
    i++;
    if (i === 5) {
        continue;
    }
    n += i;
    console.log(n);
}

//1,3,6,10,16,23,21,3,0,40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;continue&lt;/code&gt; is removed, the loop would instead print: &lt;code&gt;1,3,6,10,15,21,28,36,45,55&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case Example #2
&lt;/h5&gt;

&lt;p&gt;Here is a &lt;code&gt;while&lt;/code&gt; loop labeled &lt;code&gt;checkxandy&lt;/code&gt; includes another while loop labeled &lt;code&gt;checky&lt;/code&gt;. If &lt;code&gt;continue&lt;/code&gt; is encountered, the program ends the current iteration of &lt;code&gt;checky&lt;/code&gt; and starts the next iteration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 0;
let y = 10;
checkxandy: while (x &amp;lt; 4) {
    console.log(x);
    x += 1;
    checky: while (y &amp;gt; 4) {
        console.log(y);
        y -= 1;
        if ((y % 2) === 0) {
        continue checky;
} 
console.log(y, ‘ is odd.’);
    }
    console.log(‘x = ‘, x);
    console.log(‘y = ’, y);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every time &lt;code&gt;continue&lt;/code&gt; is encountered, &lt;code&gt;checky&lt;/code&gt; reiterates until its condition returns &lt;code&gt;false&lt;/code&gt;. When &lt;code&gt;false&lt;/code&gt; is returned, the remainder of &lt;code&gt;checkxandy&lt;/code&gt; is run and &lt;code&gt;checkxandy&lt;/code&gt; reiterates until its condition returns &lt;code&gt;false&lt;/code&gt;. When &lt;code&gt;false&lt;/code&gt; is returned from &lt;code&gt;checkxandy&lt;/code&gt;, the program continues onto next line of code after &lt;code&gt;checkxandy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;continue&lt;/code&gt; had a label of &lt;code&gt;checkxandy&lt;/code&gt;, the program would continue at top of &lt;code&gt;checkxandy&lt;/code&gt; loop. &lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;continue&lt;/code&gt; without Label
&lt;/h5&gt;

&lt;p&gt;Using &lt;code&gt;continue&lt;/code&gt; without a label will end the &lt;em&gt;current&lt;/em&gt; iteration of the innermost enclosing &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do while&lt;/code&gt;, or &lt;code&gt;for&lt;/code&gt; statement and continue the execution of the loop with the &lt;em&gt;next&lt;/em&gt; iteration.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;continue&lt;/code&gt; with Label
&lt;/h5&gt;

&lt;p&gt;Using &lt;code&gt;continue&lt;/code&gt; with a label will apply it to the looping statement identified with that label.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;continue&lt;/code&gt; vs &lt;code&gt;break&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;continue&lt;/code&gt; does not end the loop entirely. In a &lt;code&gt;while&lt;/code&gt; loop, &lt;code&gt;continue&lt;/code&gt; will lead the program to jump back to the &lt;code&gt;while&lt;/code&gt; loop’s condition. And in a &lt;code&gt;for&lt;/code&gt; loop, &lt;code&gt;continue&lt;/code&gt; will lead the program to jump to the “increment-expression”.&lt;/p&gt;

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

&lt;p&gt;In this article, we when over what control flow is and different ways we can manipulate control flow in JavaScript through conditionals and loops. &lt;/p&gt;

&lt;p&gt;A wide range of use cases were covered with the functionality of &lt;code&gt;if else&lt;/code&gt;, ternary operators, and &lt;code&gt;switch&lt;/code&gt; statements, in order to alter code blocks executed during runtime conditionally. We also discussed the varying flexibility of using &lt;code&gt;while&lt;/code&gt; loops and &lt;code&gt;for&lt;/code&gt; loops. &lt;/p&gt;

&lt;p&gt;To explore these topics in more detail, I've added some useful links below. &lt;/p&gt;

&lt;p&gt;Happy learning! &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources for Further Exploration
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.javascript.com/learn/conditionals" rel="noopener noreferrer"&gt;Conditionals - Learn: JavaScript.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator" rel="noopener noreferrer"&gt;Conditional (ternary) operator: MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators" rel="noopener noreferrer"&gt;Expressions and operators: MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mariusschulz.com/blog/the-and-and-or-operators-in-javascript" rel="noopener noreferrer"&gt;The &amp;amp;&amp;amp; and &lt;br&gt;
|| Operators in JavaScript: Marius Schulz&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.programiz.com/javascript/for-of" rel="noopener noreferrer"&gt;JavaScript for… of Loop: Programix&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*" rel="noopener noreferrer"&gt;function*: MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#examples" rel="noopener noreferrer"&gt;this: MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/learn-es6-the-dope-way-part-ii-arrow-functions-and-the-this-keyword-381ac7a32881/" rel="noopener noreferrer"&gt;Learn ES6 The Dope Way Part II: Arrow functions and the ‘this’ keyword&lt;/a&gt;&lt;br&gt;
&lt;a href="https://thecodebarbarian.com/for-vs-for-each-vs-for-in-vs-for-of-in-javascript" rel="noopener noreferrer"&gt;For vs forEach() vs for/in vs for/of in JavaScript&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#do...while_statement" rel="noopener noreferrer"&gt;Loops and iteration: MDN Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-switch-statement-in-javascript" rel="noopener noreferrer"&gt;How To Use the Switch Statement in JavaScript: DigitalOcean&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Primitive Data Types - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 17:24:43 +0000</pubDate>
      <link>https://forem.com/angelinewang/primitive-data-types-javascript-core-concepts-15fn</link>
      <guid>https://forem.com/angelinewang/primitive-data-types-javascript-core-concepts-15fn</guid>
      <description>&lt;p&gt;&lt;strong&gt;"JavaScript Core Concepts"&lt;/strong&gt; is a 5-Section Series consisting of:&lt;/p&gt;

&lt;p&gt;Section 1 Data Types &amp;amp; Variables &lt;br&gt;
Part 1 Variables&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Part 2&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;Primitive Data Types&lt;/strong&gt;&lt;br&gt;
Part 3 Complex/Composite Data Types &lt;/p&gt;

&lt;p&gt;Section 2 Functions &amp;amp; Methods&lt;br&gt;
Section 3 Control Flow &amp;amp; Conditional Statements &lt;br&gt;
Section 4 Past, Present &amp;amp; Future &lt;br&gt;
Section 5 Data Structures &amp;amp; Algorithms&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript Primitive Data Types
&lt;/h2&gt;
&lt;h3&gt;
  
  
  What is the purpose of primitive data types?
&lt;/h3&gt;

&lt;p&gt;Primitive data types are used to define immutable values, ones that cannot be changed. &lt;/p&gt;
&lt;h3&gt;
  
  
  How can you use primitive data types?
&lt;/h3&gt;

&lt;p&gt;Booleans, strings and numbers can be wrapped by their object counterparts&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;typeof&lt;/code&gt; Operator
&lt;/h4&gt;

&lt;p&gt;This returns a string indicating a value/operand’s data type. In ES6, the variable must be initialized before the usage of this operator. &lt;/p&gt;

&lt;p&gt;This operator can be used with or without parentheses. For example: &lt;code&gt;typeof(x)&lt;/code&gt; or &lt;code&gt;typeof x&lt;/code&gt;. And the best use case is when you need to identify the type of the value in order to process them accordingly, &lt;/p&gt;

&lt;p&gt;However, this operator may produce unexpected results in some cases. For example: &lt;code&gt;NaN&lt;/code&gt; returns &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;''&lt;/code&gt; returns &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;'12'&lt;/code&gt; returns &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;Null&lt;/code&gt; returns &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;[1, 2, 4]&lt;/code&gt; returns &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;function(){};&lt;/code&gt; returns &lt;code&gt;function&lt;/code&gt;. &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;.length&lt;/code&gt; Method
&lt;/h4&gt;

&lt;p&gt;In action, this method means that a string value is coerced into an object using &lt;code&gt;.returnMe()&lt;/code&gt; in order to access property length. &lt;/p&gt;

&lt;p&gt;However, the created string object is only used for a fraction of a second, and then disposed of. Even though primitives do not have properties, Javascript coerces between primitives and objects. &lt;/p&gt;
&lt;h3&gt;
  
  
  List of Primitive Data Types
&lt;/h3&gt;
&lt;h4&gt;
  
  
  #1 Boolean
&lt;/h4&gt;
&lt;h5&gt;
  
  
  What are possible boolean values?
&lt;/h5&gt;

&lt;p&gt;There are only 2 boolean values: &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;h5&gt;
  
  
  How do you use booleans?
&lt;/h5&gt;

&lt;p&gt;All JavaScript values can be converted into booleans, and all will become &lt;code&gt;true&lt;/code&gt;, expect these falsy values: &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;''&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To convert a value into a boolean and flip it, you can use the bang operator: &lt;code&gt;!&lt;/code&gt;. This will make any truthy value false, and any falsy value true. &lt;/p&gt;
&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!false // =&amp;gt; true 
!20 // =&amp;gt; false 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To convert a value into a boolean, you can use the double bang: &lt;code&gt;!!&lt;/code&gt;. The first bang converts the value into a boolean and flips it, and the second bang flips it back.&lt;/p&gt;
&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!!false // =&amp;gt; false
!!20 // =&amp;gt; true 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  #2 Null
&lt;/h4&gt;

&lt;p&gt;The null data type only has one value: &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  #3 Undefined
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;undefined&lt;/code&gt; is a variable without an assigned value.&lt;/p&gt;
&lt;h4&gt;
  
  
  #4 Number
&lt;/h4&gt;

&lt;p&gt;A number is the first of 2 JavaScript numeric primitive data types. &lt;/p&gt;
&lt;h5&gt;
  
  
  What does a number store?
&lt;/h5&gt;

&lt;p&gt;A number stores positive floating-point numbers between 2^-1074 to 2^1024, negative floating-point numbers between 2^1074 to 2^1024, and integers between 2^53 to 1 and 2^53 to 1. Values outside these ranges and are positive above the maximum are represented as +Infinity, positive values below the minimum are represented as +0, negative values below the maximum are represented as -Infinity, and negative values above the minimum as represented as -0.&lt;/p&gt;
&lt;h5&gt;
  
  
  What are the special number values?
&lt;/h5&gt;
&lt;h6&gt;
  
  
  1. Infinity
&lt;/h6&gt;

&lt;p&gt;You can test for infinity using &lt;code&gt;isFinite&lt;/code&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(1 / 0) // =&amp;gt; Infinity
console.log(-1 / 0) // =&amp;gt; -Infinity
console.log(isFinite(1 / 0)) // =&amp;gt; false 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  2. NaN
&lt;/h6&gt;

&lt;p&gt;NaN means not a number, and this is the result of an arithmetic operation that cannot be expressed as a number. For example, it’ll be the value shown after multiplying a number with a string. This is the only value in JavaScript that is not equal to itself. &lt;/p&gt;

&lt;p&gt;You can test for NaN using &lt;code&gt;isNan&lt;/code&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(12 * 'b') // =&amp;gt; NaN
console.log(isNaN(12 * 'b')) // =&amp;gt; true 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  When are numbers used?
&lt;/h5&gt;

&lt;p&gt;Numbers can be used with all standard arithmetic operators. They can also be used with Math object objects, and for advanced functionality including square root, rounding, and the random generator. &lt;/p&gt;

&lt;h4&gt;
  
  
  #5 BigInt
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;BigInt&lt;/code&gt; is the second of the 2 numeric JavaScript primitive data types. Its purpose is to represent integers with arbitrary precision. &lt;/p&gt;

&lt;h5&gt;
  
  
  What does a BigInt store?
&lt;/h5&gt;

&lt;p&gt;A &lt;code&gt;BigInt&lt;/code&gt; stores large integers that are beyond the safe integer limit for numbers. &lt;/p&gt;

&lt;h5&gt;
  
  
  How do you create a BigInt?
&lt;/h5&gt;

&lt;p&gt;To create a &lt;code&gt;BigInt&lt;/code&gt;, you need to append &lt;code&gt;n&lt;/code&gt; to the end of an integer, or call the constructor. &lt;/p&gt;

&lt;h5&gt;
  
  
  How does a BigInt behave?
&lt;/h5&gt;

&lt;p&gt;A &lt;code&gt;BigInt&lt;/code&gt; behaves like a number when converted to a boolean with conditional statements, or operators, and operators, &amp;amp; bang operators. &lt;/p&gt;

&lt;h4&gt;
  
  
  #6 String
&lt;/h4&gt;

&lt;h5&gt;
  
  
  What is a string?
&lt;/h5&gt;

&lt;p&gt;A string is a sequence of characters defined by wrapping text in single or double quotes. &lt;/p&gt;

&lt;h5&gt;
  
  
  What are string methods?
&lt;/h5&gt;

&lt;p&gt;Strings have in-built properties and functions which allow us to access information about the string or modify it in some way.&lt;/p&gt;

&lt;h5&gt;
  
  
  Common string methods
&lt;/h5&gt;

&lt;h6&gt;
  
  
  .length()
&lt;/h6&gt;

&lt;p&gt;This outputs the number of characters in a string.&lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'Angeline'.length
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  .replace()
&lt;/h6&gt;

&lt;p&gt;This replaces a substring with a string. &lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'good morning'.replace('morning', 'night')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  .charAt()
&lt;/h6&gt;

&lt;p&gt;This finds the character at the given index.&lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'tutorial'.charAt(e)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  .toUpperCase()
&lt;/h6&gt;

&lt;p&gt;This makes all the characters in the string uppercase.&lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'error message'.toUpperCase()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  .toLowerCase()
&lt;/h6&gt;

&lt;p&gt;This makes all the characters in the string lowercase.&lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'WHO\'S HEADLINING THIS CONCERT?'.toLowerCase()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Concatenation
&lt;/h5&gt;

&lt;p&gt;Concatenation is the process of joining two strings together through an &lt;code&gt;+&lt;/code&gt; operator, backticks, or &lt;code&gt;String.concat()&lt;/code&gt;.&lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(a + ' ' + b + '!') // =&amp;gt; hello world!
console.log(`${a} ${b}!`) // =&amp;gt; hello world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Get a substring of the original string
&lt;/h5&gt;

&lt;p&gt;To get the substring of the original string, pick individual letters, and then use &lt;code&gt;String.substr()&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Convert a string into a number
&lt;/h5&gt;

&lt;p&gt;To convert a string into a number, you can use &lt;code&gt;parseInt&lt;/code&gt; or &lt;code&gt;parseFloat&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;parseInt&lt;/code&gt; takes a numeric string and converts it to an integer, providing a base as the 2nd argument.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(parseInt('45', 10)) // =&amp;gt; 45 (base 10 is decimal)
console.log(parseInt('1011', 2)) // =&amp;gt; 11 (base 2 is binary)
console.log(parseInt('a4', 16)) // =&amp;gt; 164 (base 16 is hexadecimal)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;parseFloat&lt;/code&gt; converts a string into a float/decimal number and does not need a base.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(parseFloat('67.4894')) // =&amp;gt; 67.4894
console.log(parseFloat('32')) // =&amp;gt; 32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way to convert a string into a number is using a unary operator&lt;/p&gt;

&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+'23' // =&amp;gt; 23
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can also convert a string into a number using a &lt;code&gt;Number&lt;/code&gt; constructor.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number('445') // =&amp;gt; 445
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Concatenate Strings &amp;amp; Numbers
&lt;/h5&gt;

&lt;p&gt;This means adding a number to a string, or vice versa, and the result is always a string.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log('32' + 32) // =&amp;gt; "3232"
console.log(2 + 12 + '9') // =&amp;gt; "149"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Convert Numbers into Strings
&lt;/h5&gt;

&lt;p&gt;This can represent textual data. For example, a set of elements of 16-bit unsigned integer values where each element in the string occupies a position/index. This can also create another string based on an operation on the original string. &lt;/p&gt;

&lt;p&gt;There are 3 different ways to convert numbers into strings.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here are code examples:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(220).toString() // =&amp;gt; "220"
'' + 220 // =&amp;gt; "220"
String(121) // =&amp;gt; "121"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  #7 Symbol
&lt;/h4&gt;

&lt;p&gt;Symbols are unique and can also be used as a key of an object property. &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#determining_types_using_the_typeof_operator"&gt;MDN Web Docs: JavaScript Data Types and Data Structures&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values"&gt;ECMAScript Specification: Data Types and Values&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/"&gt;The Secret Life of JavaScript Primitives by Angus Croll&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Complex Data Types - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 17:18:58 +0000</pubDate>
      <link>https://forem.com/angelinewang/complex-data-types-javascript-core-concepts-1f29</link>
      <guid>https://forem.com/angelinewang/complex-data-types-javascript-core-concepts-1f29</guid>
      <description>&lt;p&gt;&lt;strong&gt;"JavaScript Core Concepts"&lt;/strong&gt; is a 5-Section Series consisting of:&lt;/p&gt;

&lt;p&gt;Section 1 Data Types &amp;amp; Variables &lt;/p&gt;

&lt;p&gt;Part 1 Variables&lt;br&gt;
Part 2 Primitive Data Types&lt;br&gt;
&lt;strong&gt;Part 3&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Complex/Composite Data Types&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Section 2 Functions &amp;amp; Methods&lt;br&gt;
Section 3 Control Flow &amp;amp; Conditional Statements &lt;br&gt;
Section 4 Past, Present &amp;amp; Future &lt;br&gt;
Section 5 Data Structures &amp;amp; Algorithms&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript Complex/Composite Data Types
&lt;/h2&gt;
&lt;h3&gt;
  
  
  What is a Complex/Composite Data Type?
&lt;/h3&gt;

&lt;p&gt;A complex/composite data type represents a number of similar or different data under a single declaration of a variable. It is a data type that allows multiple values to be grouped together. &lt;/p&gt;
&lt;h3&gt;
  
  
  JS Complex/Composite Data Types
&lt;/h3&gt;

&lt;p&gt;JavaScript has 1 complex data type: objects. And other data types like arrays and functions described below are just different types of objects. &lt;/p&gt;
&lt;h3&gt;
  
  
  #1 Objects
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Definition
&lt;/h4&gt;

&lt;p&gt;An object is a collection of properties, also known as a mapping between keys and values. &lt;/p&gt;
&lt;h5&gt;
  
  
  Here’s an example:
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let event = {
location: "123 Event Street",
date: "12-03-2022",
host: "Angeline"
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;Objects are useful for storing more than one value for a single variable. In the example above, I stored location, date, and host of an event in one variable named &lt;code&gt;event&lt;/code&gt;. This means that objects are valuable to store collections of data, and creates a value in memory that could be referenced by an identifier. &lt;/p&gt;
&lt;h4&gt;
  
  
  Contents
&lt;/h4&gt;

&lt;p&gt;Objects contain properties, which are defined as key-value pairs. The key is always a string/symbol, and the value is any data type (primitive or complex).&lt;/p&gt;
&lt;h4&gt;
  
  
  Use Case
&lt;/h4&gt;

&lt;p&gt;Objects are useful for processing large amounts of data. For example, to store the data of a group of people.&lt;/p&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Create an empty Object
&lt;/h5&gt;

&lt;p&gt;To create an empty object and add properties later, use the &lt;code&gt;new&lt;/code&gt; keyword.&lt;/p&gt;
&lt;h6&gt;
  
  
  Here’s an example:
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let event = new Object();
event.location = "123 Event Street";
event.date = "12-03-2022";
event.host = "Angeline";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Adding Properties
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Naming Properties
&lt;/h6&gt;

&lt;p&gt;Quotes are optional when naming a property if it is a valid JavaScript names (ie &lt;code&gt;firstname&lt;/code&gt;), and quotes are mandatory for non-valid JavaScript names (ie &lt;code&gt;"first-name"&lt;/code&gt;).&lt;/p&gt;
&lt;h6&gt;
  
  
  Using Properties
&lt;/h6&gt;

&lt;p&gt;Objects are a collection of properties, and the object literal syntax is where a limited set of properties are initialized. Properties can be added and removed.&lt;/p&gt;
&lt;h6&gt;
  
  
  Property Values
&lt;/h6&gt;

&lt;p&gt;Property values can be any data type (primitive or composite), including other objects. Thus enabling building of complex data structures. &lt;/p&gt;
&lt;h6&gt;
  
  
  Identification of Properties
&lt;/h6&gt;

&lt;p&gt;Properties are identified using key values which are either strings or symbols. And each property has its own corresponding attributes. Each attribute is accessed internally by the JavaScript engine, which can be set through &lt;code&gt;Object.defineProperty()&lt;/code&gt; and read through &lt;code&gt;Object.getOwnPropertyDescriptor()&lt;/code&gt;.&lt;/p&gt;
&lt;h6&gt;
  
  
  Types of Object Properties
&lt;/h6&gt;

&lt;p&gt;There are 2 types of object properties: The data property and the accessor property. &lt;/p&gt;

&lt;p&gt;A data property associates a key with a value, and has these attributes: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;value&lt;br&gt;
This is retrieved by a get access of the property, and can be any JavaScript value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;writable&lt;br&gt;
This is a boolean value indicating whether the property can be changed with an assignment. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;enumerable&lt;br&gt;
This is a boolean value that indicates whether the property can be enumerated by a for…in loop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;configurable&lt;br&gt;
This is a boolean value that indicates if the property can be deleted, changed to an accessor property, and have its attributes changed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Accessing Object Value
&lt;/h5&gt;

&lt;p&gt;Each individual value within an object can be fetched for later use through the following 2 ways:&lt;/p&gt;
&lt;h6&gt;
  
  
  1. Dot Operator
&lt;/h6&gt;


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

&lt;/div&gt;


&lt;p&gt;Creates this output:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h6&gt;
  
  
  2. Square Bracket
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(event["host"]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates this output:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  More Objects
&lt;/h4&gt;

&lt;p&gt;More objects can be found through the JavaScript standard library of built-in objects. &lt;/p&gt;

&lt;h3&gt;
  
  
  #2 Arrays
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What are arrays?
&lt;/h4&gt;

&lt;p&gt;Arrays are a type of regular object. What makes an array special is the particular relationships between integer-keyed properties and the length property. And the purpose of an array is to store multiple values in one variable in order to represent lists or sets. &lt;/p&gt;

&lt;h4&gt;
  
  
  How to create an array
&lt;/h4&gt;

&lt;p&gt;To create an array, you need to specify the array elements as a comma-separated list that is then surrounded by square brackets. &lt;/p&gt;

&lt;h5&gt;
  
  
  Here’s an example:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let users = ["Angeline", "Bob", "Sarah", "George"];

console.log(users[0]); //Output: "Angeline"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What do arrays contain?
&lt;/h4&gt;

&lt;p&gt;Each value/element in an array has a numeric position called its index, which starts from 0 and may contain data of any data type (primitive or complex). &lt;/p&gt;

&lt;h4&gt;
  
  
  What are array methods?
&lt;/h4&gt;

&lt;p&gt;Array methods are inherited from Array.prototype, and they are methods to manipulate arrays. For example: &lt;code&gt;indexOf()&lt;/code&gt; searches a value in the array and &lt;code&gt;push()&lt;/code&gt; adds an element to the array.&lt;/p&gt;

&lt;h4&gt;
  
  
  Typed Arrays
&lt;/h4&gt;

&lt;p&gt;Typed arrays are an array-like view of the underlying binary data buffer, which offers methods with similar semantics to array counterparts. Typed arrays is the umbrella term for a range of data structures, for example: Int8Array and Float32Array.&lt;/p&gt;

&lt;h3&gt;
  
  
  #3 Functions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What are functions?
&lt;/h4&gt;

&lt;p&gt;Functions are regular objects with the additional capability of being callable, which means that it executes a block of code. &lt;/p&gt;

&lt;h4&gt;
  
  
  How do you create a function?
&lt;/h4&gt;

&lt;p&gt;Because functions are objects, you can assign them to variables. Furthermore, functions can be used in any other place where other values can be used–meaning that they can be stored in objects and arrays as well.&lt;/p&gt;

&lt;h5&gt;
  
  
  Here’s an example:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greeting = function() {
return "Hi!";
}

console.log(typeof greeting) //Output: function
console.log(greeting()); //Output: "Hi!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functions can also be passed as arguments to other functions and functions can be returned from other functions. &lt;/p&gt;

&lt;h5&gt;
  
  
  Here’s an example:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greeting(name) {
return "Hi, " + name;
}
function displayGreeting(greetingFunction, userName) {
return greetingFunction(userName);
}

let result = displayGreeting(createGreeting, "Angeline");
console.log(result); //Output: "Hi, Angeline"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  #4 Dates
&lt;/h3&gt;

&lt;p&gt;The best choice to represent data is using the built-in date utility in JavaScript. &lt;/p&gt;

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

&lt;h3&gt;
  
  
  How do primitives and complex data types differ in action?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Coercion in JavaScript
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Coercing Objects in Values
&lt;/h5&gt;

&lt;p&gt;Objects are wrappers, which means that the value of an object is the primitive they are wrapped around. And then the object is coerced down to this value as necessary. &lt;/p&gt;

&lt;p&gt;Boolean objects are a tricky case where the value will always be coerced into a true primitive boolean, even if the initial value of the object is falsey. The only two cases where a boolean object is coerced into a false primitive boolean is when the initial value is &lt;code&gt;undefined&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This means that when working with a boolean object, in order to use the value within the boolean object, the value needs to be explicitly asked for. &lt;/p&gt;

&lt;h5&gt;
  
  
  Coercing Primitives
&lt;/h5&gt;

&lt;p&gt;Primitive data types cannot be coerced for the assignment of a property value. An attempt to assign a property to a primitive will lead to JavaScript coercing the primitive into an object; however, this new object has no reference, so it will be immediately disposed of. &lt;/p&gt;

&lt;h4&gt;
  
  
  What is the advantage of using an object?
&lt;/h4&gt;

&lt;p&gt;Objects are handy as they allow you to assign properties, but this is its only arguable practical benefit. &lt;/p&gt;

&lt;h4&gt;
  
  
  What is the advantage of using primitives?
&lt;/h4&gt;

&lt;p&gt;Primitives have specific and well-defined purposes, which also means that redefining them as state holders is a confusing act that should be avoided. These variables are immutable, which means that they cannot be modified by tweaking the properties of an object wrapper. &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.tutorialspoint.com/What-is-a-composite-data-type-i-e-object-in-JavaScript"&gt;What is a composite data type i.e. object in JavaScript?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.tutorialrepublic.com/javascript-tutorial/javascript-data-types.php#:~:text=Data%20Types%20in%20JavaScript&amp;amp;text=String%2C%20Number%2C%20and%20Boolean%20are,objects"&gt;TutorialRepublic: JavaScript Data Types&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hoisting - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 17:03:46 +0000</pubDate>
      <link>https://forem.com/angelinewang/hoisting-javascript-core-concepts-c1f</link>
      <guid>https://forem.com/angelinewang/hoisting-javascript-core-concepts-c1f</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Section 2:&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Functions &amp;amp; Methods&lt;/em&gt;&lt;/strong&gt; of my &lt;strong&gt;JavaScript Core Concepts&lt;/strong&gt; Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
Part 2 Classes&lt;br&gt;
Part 3 Methods&lt;br&gt;
Part 4 Callback Functions&lt;br&gt;
Part 5 Scope&lt;br&gt;
&lt;strong&gt;Part 6 Hoisting&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Hoisting: Variables vs Functions &amp;amp; Classes
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Part 1 What is Hoisting?
&lt;/h2&gt;

&lt;p&gt;= Here are a few different definitions of Hoisting: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;One of many operations a JS interpreter performs in the background&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variable/Function Declarations are hoisted to top of the Scope &lt;br&gt;
= Hoisting only moves the Declaration &lt;br&gt;
→ Any Assignments are left in place&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mental image to help us illustrate why we can access Functions &amp;amp; Variables before they are defined &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Picture how code is reorganized before Execution&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  During Execution
&lt;/h3&gt;

&lt;p&gt;= When Engine is actually executing our code &lt;br&gt;
→ Our Function &amp;amp; Variable Declarations: No longer there at all &lt;br&gt;
→ They have already been declared in a previous run&lt;/p&gt;
&lt;h3&gt;
  
  
  Impact of Hoisting
&lt;/h3&gt;

&lt;p&gt;= Hoisting Functions &amp;amp; Variables is reason why we can use some of them before they are actually declared &lt;br&gt;
→ Function &amp;amp; Variable Declarations are pulled to top of their scope &lt;br&gt;
Try to access them: They’ve already been declared&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;
&lt;h2&gt;
  
  
  Part 2 Hoisting Variables
&lt;/h2&gt;
&lt;h3&gt;
  
  
  JS Variables’ Behaviour
&lt;/h3&gt;

&lt;p&gt;= 2 Parts&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Declaration &lt;/li&gt;
&lt;li&gt;An Initialisation/Assignment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;= Even when you declare and assign a Variable in one line like this: &lt;code&gt;var name = 'Angeline'&lt;/code&gt;&lt;br&gt;
→ The JS engine still treats this line of code as 2 separate statements&lt;br&gt;
→ It treats it as if you wrote this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name;
name = 'Angeline';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What are the impacts of Block Scope?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;ES6 gives 2 new Variable Declaration keywords: &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;&lt;br&gt;
= Difference between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;&lt;br&gt;
→ Variables declared with ES6 Keywords are block-scoped &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are accessible only in code block they are defined in &lt;br&gt;
= A code block&lt;br&gt;
→ Separated by curly braces&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variables created with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; are not hoisted &lt;br&gt;
= Their definition is not pulled to the top like Variables declared with &lt;code&gt;var&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;var&lt;/code&gt; Variable Declarations
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;var&lt;/code&gt; Variable Declarations are hoisted AND fully initialized&lt;br&gt;
→ With a Value Assignment of &lt;code&gt;undefined&lt;/code&gt; by default &lt;/p&gt;
&lt;h5&gt;
  
  
  Variable Declared w/in a Scope
&lt;/h5&gt;

&lt;p&gt;= Belongs to that Scope &lt;/p&gt;
&lt;h5&gt;
  
  
  Regardless of Location of Variable Declaration w/in a Scope
&lt;/h5&gt;

&lt;p&gt;= All Variable Declarations are moved to top of their Scope (Global or Local)&lt;br&gt;
→ This is called Hoisting &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;let&lt;/code&gt; Variables Declarations
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;let&lt;/code&gt; Variable Declarations cannot be read/written until they are &lt;em&gt;fully&lt;/em&gt; initialized&lt;br&gt;
→ When are they fully initialized? Where they are actually declared in the code &lt;br&gt;
→ &lt;code&gt;let&lt;/code&gt; Variable Declaration is hoisted, but not initialized with &lt;code&gt;undefined&lt;/code&gt; value (which is done by default with &lt;code&gt;var&lt;/code&gt; variables)&lt;br&gt;
→ &lt;code&gt;let&lt;/code&gt; Declarations are not hoisted like &lt;code&gt;var&lt;/code&gt; Declarations&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;const&lt;/code&gt; Variable Declarations
&lt;/h4&gt;

&lt;p&gt;= Same behaviour as &lt;code&gt;let&lt;/code&gt; variables &lt;/p&gt;
&lt;h3&gt;
  
  
  Hoisting In Action
&lt;/h3&gt;

&lt;p&gt;= Variable/Function is not physically moved &lt;br&gt;
→ Hosting is just a model describing what the JS engine does behind the scenes &lt;/p&gt;
&lt;h3&gt;
  
  
  What is Hoisted?
&lt;/h3&gt;

&lt;p&gt;= (&lt;code&gt;var&lt;/code&gt;) Variable &amp;amp; Function Declarations are hoisted &lt;br&gt;
→ But Variable &amp;amp; Function Assignments are left in their place&lt;br&gt;
→ &lt;em&gt;Even if&lt;/em&gt; the Declaration and Assignment happen in the same line of code as in: &lt;code&gt;var name = 'Angeline'&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Reference before Declaration
&lt;/h4&gt;

&lt;p&gt;= If you reference a Variable/Function before its Declaration&lt;br&gt;
→ Expect a &lt;code&gt;ReferenceError&lt;/code&gt; to be thrown&lt;/p&gt;
&lt;h4&gt;
  
  
  Referenced before Assignment
&lt;/h4&gt;

&lt;p&gt;= Except a Default Value of &lt;code&gt;undefined&lt;/code&gt; to be the Output&lt;br&gt;
→ If &lt;code&gt;var&lt;/code&gt; is used&lt;/p&gt;
&lt;h3&gt;
  
  
  Temporal Dead Zone
&lt;/h3&gt;

&lt;p&gt;= Section from beginning of Block to actual Variable Declaration &lt;/p&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Mechanism that ensures better coding practice &lt;br&gt;
→ Forces you to declare a Variable before you use it &lt;/p&gt;
&lt;h4&gt;
  
  
  Compilation
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Definition
&lt;/h5&gt;

&lt;p&gt;= Internals of JS &amp;amp; how it actually works &lt;br&gt;
→ V8 Engine increases performance by compiling JS to machine code before executing it &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;= Engine makes multiple runs through our code &lt;br&gt;
→ 1 of the early runs: It will declare all Functions &amp;amp; Variables&lt;br&gt;
→ So when the code is executed: They will already be defined&lt;/p&gt;
&lt;h5&gt;
  
  
  Reference Error Prevention
&lt;/h5&gt;

&lt;p&gt;= Make sure you are using only &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; for Variable Declaration&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;
&lt;h2&gt;
  
  
  Part 3 Hoisting Functions
&lt;/h2&gt;

&lt;p&gt;= Hoisting also affects Function Declarations&lt;/p&gt;
&lt;h3&gt;
  
  
  Function vs Variable Hoisting
&lt;/h3&gt;

&lt;p&gt;= Only Declaration of the Variable is pulled to the top &lt;br&gt;
→ Value Assignment: Stays where it is&lt;br&gt;
→ Cannot access Value of a Variable the same way we can call Functions&lt;/p&gt;
&lt;h3&gt;
  
  
  Function Declaration vs Expression
&lt;/h3&gt;

&lt;p&gt;= Difference: Check position of word &lt;code&gt;function&lt;/code&gt; in the statement &lt;br&gt;
→ If &lt;code&gt;function&lt;/code&gt; is very 1st thing in the statement: It is a Function Declaration&lt;br&gt;
→ Not &lt;code&gt;function&lt;/code&gt; is not the first thing: It is a Function Expression&lt;/p&gt;
&lt;h3&gt;
  
  
  Hoisting of Declarations vs Expressions
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Declarations
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Hoisted completely &lt;br&gt;
= Entire Function’s body is moved to the top&lt;br&gt;
→ Allows you to call a Function &lt;em&gt;before&lt;/em&gt; it has been declared &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JS Engine&lt;br&gt;
= Moves Declaration &amp;amp; its contents &lt;br&gt;
→ To beginning of the Scope&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Expressions
&lt;/h4&gt;

&lt;p&gt;= Are not hoisted &lt;br&gt;
→ When a Function is assigned to a Variable &lt;br&gt;
Rules are the same as Variable Hoisting &lt;/p&gt;

&lt;p&gt;= Only the Declaration is moved&lt;br&gt;
→ While the Assignment is left in place&lt;/p&gt;
&lt;h4&gt;
  
  
  Caution w/ Function Expressions
&lt;/h4&gt;

&lt;p&gt;= Variable Declaration will be hoisted&lt;br&gt;
→ But Function assigned to Value not hoisted&lt;br&gt;
→ Function will not be Hoisted&lt;/p&gt;

&lt;p&gt;= Cannot be used before it is read&lt;br&gt;
→ Actual Assignment of the Function as a Value stays where it is &lt;br&gt;
→ So if we try to call the Function, we will get an Error &lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;
&lt;h2&gt;
  
  
  Part 5 Hoisting Priority
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Function Declaration &lt;/li&gt;
&lt;li&gt;Variable Declaration 
= Assignments: Variable &lt;em&gt;or&lt;/em&gt; Function, are not hoisted, so are read later, and will overwrite Function and Variable Declaration Values&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Create Function w/ Variable Assignment 1st
&lt;/h3&gt;

&lt;p&gt;= Will still be read after Function Declaration&lt;/p&gt;
&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var showState = function() {
    console.log(“Idle”);
};

function showState() {
    console.log(“Ready”);
}

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

&lt;/div&gt;


&lt;p&gt;= This above code is interpreted by the JS Engine 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;function showState() {
    console.log(“Ready”);
}

var showState;

showState = function(){
    console.log(“Idle”);
};

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

&lt;/div&gt;



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

&lt;p&gt;= Interpreted the same way Function Expressions are in terms of hosting? &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Part 4 Hoisting Classes
&lt;/h2&gt;

&lt;p&gt;= Class Declarations &lt;br&gt;
→ Hoisted similarly as Variables declared with &lt;code&gt;let&lt;/code&gt; statement&lt;/p&gt;
&lt;h3&gt;
  
  
  Code Example
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var user = new Person(‘Angeline’, 20);

class Person {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= &lt;code&gt;Person&lt;/code&gt; Class being used before Declaration &lt;br&gt;
→ Produces a Reference Error: Similar to that in &lt;code&gt;let&lt;/code&gt; Variables&lt;/p&gt;
&lt;h4&gt;
  
  
  Solution
&lt;/h4&gt;

&lt;p&gt;= Must use the &lt;code&gt;Person&lt;/code&gt; Class after the Declaration 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;class Person {
    constructor(name, age) {#
        this.name = name;
        this.age = age;
    }
}

var user = new Person(‘Angeline’, 20);
console.log(user);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Alternative Way to Create Classes
&lt;/h3&gt;

&lt;p&gt;= Using a Class Expression &lt;br&gt;
→ Using &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, or &lt;code&gt;const&lt;/code&gt; Variable Declaration Statements&lt;/p&gt;
&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;


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

var user = new Person(‘Angeline’, 20);

var Person = class {
    constructor(name, age) {
        this.name = name;
        this.age = age;
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= &lt;code&gt;Person&lt;/code&gt; Class is hoisted as a Function Expression &lt;br&gt;
→ But it cannot be used because its value is &lt;code&gt;undefined&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Solution
&lt;/h5&gt;

&lt;p&gt;= Use &lt;code&gt;Person&lt;/code&gt; Class after Declaration:&lt;br&gt;
&lt;/p&gt;

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

var Person = class {
    constructor(name. age) {
        this.name = name;
        this.age = age;
    }
};

var user = new Person(‘Angeline’, 20);
console.log(user);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Scope - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 16:58:23 +0000</pubDate>
      <link>https://forem.com/angelinewang/scope-javascript-core-concepts-456o</link>
      <guid>https://forem.com/angelinewang/scope-javascript-core-concepts-456o</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Section 2:&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Functions &amp;amp; Methods&lt;/em&gt;&lt;/strong&gt; of my &lt;strong&gt;JavaScript Core Concepts&lt;/strong&gt; Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
Part 2 Classes&lt;br&gt;
Part 3 Methods&lt;br&gt;
Part 4 Callback Functions&lt;br&gt;
&lt;strong&gt;Part 5 Scope&lt;/strong&gt;&lt;br&gt;
Part 6 Hoisting&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript Scope
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Part 1 What is Scope?
&lt;/h2&gt;

&lt;p&gt;= Visibility of Functions &amp;amp; Variables in different parts of your code during Runtime&lt;br&gt;
→ Part of the code where it is available&lt;/p&gt;

&lt;p&gt;= Determines Variables’ accessibility (differs depending on programming language)&lt;br&gt;
&lt;em&gt;Variables defined inside a Function&lt;/em&gt;&lt;br&gt;
→ Not accessible from outside Function &lt;/p&gt;

&lt;p&gt;&lt;em&gt;But can be used as many times&lt;/em&gt;&lt;br&gt;
→ As their Function is used throughout Program&lt;/p&gt;

&lt;h3&gt;
  
  
  What does Scope look like in action?
&lt;/h3&gt;

&lt;p&gt;= Working w/ Variables &amp;amp; Scope comes intuitively to most developers&lt;br&gt;
→ Mental models help developers understand when something can be off limits &lt;/p&gt;

&lt;h3&gt;
  
  
  What determines a Variable's Scope?
&lt;/h3&gt;

&lt;p&gt;= Location of Variable Declaration &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Part 2 JavaScript Scope Types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Global Scope
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is Global Scope?
&lt;/h4&gt;

&lt;p&gt;= Outermost scope&lt;br&gt;
→ Any variables declared in thai scope become global variables &lt;br&gt;
→ And are accessible from anywhere in the program&lt;/p&gt;

&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = “Angeline”;

function sayHi() {
    console.log(`Hi ${name}`);
}

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

&lt;/div&gt;



&lt;p&gt;= Variable &lt;code&gt;name&lt;/code&gt; is Global &lt;br&gt;
→ Defined in Global Scope &lt;br&gt;
→ Accessible throughout the Program&lt;/p&gt;

&lt;h4&gt;
  
  
  Use Case of Global Scope
&lt;/h4&gt;

&lt;p&gt;= Discouraged in JavaScript&lt;br&gt;
→ Can potentially be overwritten by other Scripts&lt;br&gt;
→ Or from elsewhere in the Program&lt;/p&gt;

&lt;h4&gt;
  
  
  Global Variable Assignment w/in a Function
&lt;/h4&gt;

&lt;p&gt;= Global Variable assigned a different Value inside a Function&lt;br&gt;
→ Value only retained in boundaries of same Function&lt;/p&gt;

&lt;h5&gt;
  
  
  Outside the function
&lt;/h5&gt;

&lt;p&gt;= The variable has as different value &lt;br&gt;
→ One declared in the global scope&lt;br&gt;
→ Will not get an error for using the same Variable Name&lt;/p&gt;

&lt;h5&gt;
  
  
  Undeclared Variables
&lt;/h5&gt;

&lt;p&gt;= JS will not stop use of undeclared variables &lt;br&gt;
→ Any point: You can assign a value to a variable without using &lt;code&gt;const&lt;/code&gt; &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;&lt;br&gt;
→ When this is done: Engine tries to look for the variable bubbling up to the global scope &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If does not find it there:&lt;/em&gt;&lt;br&gt;
= Creates a Global Variable for you&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Local Scope
&lt;/h3&gt;

&lt;p&gt;= Local scope has 2 variations:&lt;/p&gt;

&lt;h4&gt;
  
  
  #1 (Old) Function scope
&lt;/h4&gt;

&lt;p&gt;= Variables can be accessed in boundaries of the function in which they are defined &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;var&lt;/code&gt; Variables&lt;/em&gt;&lt;br&gt;
= Have the Old Function Scope&lt;br&gt;
= Are either Globally Scoped, or Locally Scoped to Function defined in &lt;br&gt;
→ Thus, it is not affected by Block Scope, so you cannot declare a new Locally Scoped Variable with the same name as one declared in the Global Scope&lt;/p&gt;

&lt;h4&gt;
  
  
  #2 (New) Block Scope – introduced w/ ES6
&lt;/h4&gt;

&lt;p&gt;= Function scope is a special type of a block scope&lt;br&gt;
= Variables can be accessed in the block in which they are defined&lt;br&gt;
→ A block is separated by { and }&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; &amp;amp; &lt;code&gt;const&lt;/code&gt; Variables have Block Scope&lt;br&gt;
= Creates a new, local scope for any block they’re declared in &lt;br&gt;
→ Can also define standalone code blocks in JS &lt;br&gt;
→ They similarly delimit a scope&lt;/p&gt;

&lt;h5&gt;
  
  
  New Block Scope Rules
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Variables w/ Same Name &lt;br&gt;
= Can be specified at multiple layers of nested Scope &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Local Variables &lt;br&gt;
= Gain priority over Global Variables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Local &amp;amp; Global Variable declared w/ Same Name &lt;br&gt;
&lt;em&gt;Local Variable takes precedence&lt;/em&gt;&lt;br&gt;
= Declare a Local Variable &amp;amp; a Global Variable with same name &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Local variable takes precedence&lt;/em&gt;&lt;br&gt;
= When you use it inside a Function or Block &lt;br&gt;
→ This behaviour is called Shadowing&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables declared inside a Block 
= Belong to that particular Block 
→ And become Local Variables&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3. Lexical (Static) Scope
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is Lexical Scope?
&lt;/h4&gt;

&lt;p&gt;= Created when a new Function is created&lt;br&gt;
→ A new Lexical Scope is created&lt;/p&gt;

&lt;h4&gt;
  
  
  What is the purpose of Lexical Scope?
&lt;/h4&gt;

&lt;p&gt;= Allows inner functions to access the scope of outer functions &lt;/p&gt;

&lt;p&gt;= To find a Variable, the JS interpreter uses Lexical Scope:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Works starting from the currently Executing Scope &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Works its way out until it finds the Variable in question&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If Variable is not found in any Scope &lt;br&gt;
= An exception is thrown&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Lexical Scope of Variables
&lt;/h4&gt;

&lt;p&gt;= Static/Lexical Structure of a Program &lt;br&gt;
→ Determines Variable Scope &lt;/p&gt;

&lt;h4&gt;
  
  
  Lexical Scope of Functions
&lt;/h4&gt;

&lt;p&gt;= No matter where a Function is called from&lt;br&gt;
→ No matter how it’s called: Its Lexical Scope depends only on where the function was declared&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Shadowing?
&lt;/h3&gt;

&lt;p&gt;= Inner Variable shadows the outer&lt;br&gt;
→ This is the mechanism used&lt;br&gt;
→ For JS interpreter to find a particular Variable&lt;/p&gt;

&lt;h4&gt;
  
  
  How does Shadowing work?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Starts at innermost scope being executed at the time &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Continues until 1st match is found &lt;br&gt;
= No matter if there are other variables with same name in outer levels or not&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even with same name &lt;br&gt;
= Local variable does not overwrite the global one after execution of function&lt;br&gt;
→ And means that 2 different variables are created &lt;br&gt;
→ BUT not always the case &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the local variable is assigned a value without the &lt;code&gt;var&lt;/code&gt; keyword, it becomes a global variable&lt;br&gt;
= Simply as a value assignment &lt;br&gt;
→ This will overwrite the global variable with the same name&lt;br&gt;
→ And the global variable will be officially reassigned&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Nesting
&lt;/h3&gt;

&lt;p&gt;= Function &amp;amp; Block scopes can be nested&lt;br&gt;
→ Where there are multiple nested scoped:&lt;br&gt;
Variable is accessible within its own scope (parent function)&lt;br&gt;
Or from inner scope&lt;br&gt;
→ Outside of its scope:&lt;br&gt;
Variable is inaccessible&lt;/p&gt;

&lt;h3&gt;
  
  
  Need Variable inside a Function
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Engine looks for it in Scope of current Function &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Goes 1 level up in Function containing it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If not found, continues to go up &lt;br&gt;
= Until it reaches the Global Scope&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If Variable not found there&lt;br&gt;
= Will get a &lt;code&gt;ReferenceError&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Assignment w/o Declaration
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Prevent Overwriting Global Variables
&lt;/h4&gt;

&lt;p&gt;= Always declare your local variables &lt;br&gt;
→ Before you used them &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
= Any variable declared with &lt;code&gt;var&lt;/code&gt; keyword inside a function &lt;br&gt;
→ Is a Local Variable: It is best practice to declare your variables&lt;/p&gt;

&lt;h4&gt;
  
  
  Strict Mode
&lt;/h4&gt;

&lt;p&gt;= In strict mode, it is an error if you assign a value to a variable without first declaring the variable&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Part 4 Best Practice
&lt;/h2&gt;

&lt;p&gt;= Do not pollute the global scope&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If a Variable is meant to be globally used:&lt;/em&gt;&lt;br&gt;
= Declare it in the global scope&lt;br&gt;
→ So intentions can be clear&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If it is not meant to be globally used:&lt;/em&gt;&lt;br&gt;
= Keep it inside the scope it is used in&lt;/p&gt;

&lt;h5&gt;
  
  
  How to master JS?
&lt;/h5&gt;

&lt;p&gt;= Must look to build on top of those existing mental models &lt;br&gt;
→ AND go into the specifics &lt;/p&gt;

&lt;p&gt;= Though it is possible to write fine code without deep understanding of scope&lt;br&gt;
→ Only those that have put in the time to read the small print &lt;br&gt;
→ Can avoid pitfalls in trickieset of situations&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Part 5 Hoisting Priority
&lt;/h2&gt;

&lt;p&gt;= Hoisting happens in this order: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Function Declarations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variable Declarations&lt;br&gt;
→ Class Declarations are hoisted as Variables&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Variable (&amp;amp; Class) Assignments&lt;br&gt;
= Are not Hoisted&lt;br&gt;
→ Will instead overwrite Declarations after code is read in cascading order &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/"&gt;Sitepoint: Demystifying JavaScript Variable Scope and Hoisting By Ivaylo Gerchev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackernoon.com/understanding-javascript-scope-1d4a74adcdf5"&gt;Hackernoon – Understanding JavaScript: Scope – By Alexander Kondov&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Callback Functions - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 16:38:36 +0000</pubDate>
      <link>https://forem.com/angelinewang/callback-functions-javascript-core-concepts-952</link>
      <guid>https://forem.com/angelinewang/callback-functions-javascript-core-concepts-952</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Section 2:&lt;/strong&gt; &lt;em&gt;&lt;strong&gt;Functions &amp;amp; Methods&lt;/strong&gt;&lt;/em&gt; of my &lt;strong&gt;JavaScript Core Concepts&lt;/strong&gt; Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
Part 2 Classes&lt;br&gt;
Part 3 Methods&lt;br&gt;
&lt;strong&gt;Part 4 Callback Functions&lt;/strong&gt;&lt;br&gt;
Part 5 Scope&lt;br&gt;
Part 6 Hoisting&lt;/p&gt;
&lt;h2&gt;
  
  
  Callback Functions
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Part 1 What is a Callback Function?
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;Callback&lt;/code&gt;: Name of a JS Function Convention &lt;br&gt;
→ Not a tool w/ unique functionality &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here are a few definitions:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Function executed&lt;br&gt;
= At end of execution of another function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function passed into another Function as an Argument &lt;br&gt;
= To be executed later&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function that runs asynchronously&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Functions = Objects in JS&lt;/em&gt;&lt;br&gt;
= They can take Functions as Arguments&lt;br&gt;
→ &amp;amp; Can be returned by other Functions&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Difference between Callbacks &amp;amp; most Functions&lt;/em&gt;&lt;br&gt;
= Callbacks do not immediately return some result &lt;br&gt;
→ They take time to product a result&lt;/p&gt;
&lt;h4&gt;
  
  
  Higher-Order Function
&lt;/h4&gt;

&lt;p&gt;= Function that takes other functions as arguments&lt;br&gt;
→ Function being passed in: Called a Callback Function&lt;/p&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const button = document.querySelector(‘button’)
button.addEventListener(‘click’, function(e) {
    this.classList.add(‘clicked’)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= JS listening for &lt;code&gt;click&lt;/code&gt; event on button&lt;br&gt;
→ Only calls the function in 2nd argument if event is detected&lt;/p&gt;

&lt;p&gt;…&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 2 What is the purpose of a Callback Function?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Store things to do at later time &lt;br&gt;
= Order in which events occur: Does not work top-to-bottom&lt;br&gt;
→ Skips around depending on when things complete&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dealing with tasks that get dispatched&lt;br&gt;
= Go off and do something in the background &lt;br&gt;
→ Then, complete successfully or abort due to failure &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Callbacks are used in 2 different ways:&lt;/p&gt;
&lt;h4&gt;
  
  
  1st Way: Synchronous Functions
&lt;/h4&gt;

&lt;p&gt;= Code is synchronous&lt;br&gt;
→ If executes top-to-bottom, left-to-right, sequentially &lt;br&gt;
→ Waiting until 1 line of code finishes &lt;br&gt;
Before next line begins &lt;br&gt;
→ Process continues until last line of code is executed&lt;/p&gt;
&lt;h5&gt;
  
  
  Callbacks in Synchronous Functions
&lt;/h5&gt;

&lt;p&gt;= When want a part of code to be easily swapped w/ something else&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [10, 11, 19, 40]
const getLessThanFifteen = num =&amp;gt; num &amp;lt; 15
const getMoreThanTwenty = num =&amp;gt; num &amp;gt; 20 

const lessThanFifteen = numbers.filter(getLessThanFifteen)

const moreThanTwenty = numbers.filter(getMoreThaTwenty)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Normal vs Async Functions
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;Normal Functions&lt;/em&gt;&lt;br&gt;
= Allow you to use its return value&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Async Functions that use callbacks&lt;/em&gt;&lt;br&gt;
= Don’t return anything straight away&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Waiting for Response&lt;/em&gt;&lt;br&gt;
= Don’t want program to pause&lt;br&gt;
→ So you store the code that should run afterwards&lt;br&gt;
Inside a Function: Called a Callback Function &lt;/p&gt;
&lt;h4&gt;
  
  
  2nd Way: Asynchronous Functions
&lt;/h4&gt;

&lt;p&gt;= Takes some time, happens in the future, not right now&lt;br&gt;
→ JS needs to wait for something to complete&lt;br&gt;
→ Will run rest of tasks given to it: While waiting&lt;/p&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;

&lt;p&gt;= Asynchronous Function that takes a Callback to execute at later time&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twentySecondsLater = () =&amp;gt; console.log(‘20 seconds passed!’)


setTimeout(twentySecondsLater, 20000)
console.log(‘Start!’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= JS executes &lt;code&gt;setTimeout&lt;/code&gt;&lt;br&gt;
→ Then it waits for 20 seconds&lt;br&gt;
→ And then logs ‘20 seconds passed!’&lt;/p&gt;

&lt;p&gt;= Same time as waiting for &lt;code&gt;setTimeout&lt;/code&gt; to complete in 20 seconds&lt;br&gt;
→ JS executes `console.log(“Start!”)&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Part 3 How do you create a Callback?
&lt;/h3&gt;

&lt;p&gt;= There are 2 ways to create Callbacks:&lt;/p&gt;

&lt;h4&gt;
  
  
  1st Way: Anonymous Functions
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pass Callback Function Definition as an Argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define it in the Function Call&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To do this, you pass in &lt;code&gt;callback&lt;/code&gt; as the last Parameter of the Function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then the Callback Function itself is defined in the 2nd Argument during the Function Call&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
function createEvent(date, callback) {&lt;br&gt;
    console.log(&lt;/code&gt;The event on ${date} has been created.`);&lt;br&gt;
    callback();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;createEvent(“September 22nd, 2022”, function() {&lt;br&gt;
    console.log(&lt;code&gt;The event is being displayed.&lt;/code&gt;)&lt;br&gt;
})&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2nd Way: Named Functions
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pass reference to Callback as an Argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Or you can define the Callback Function elsewhere&lt;br&gt;
= &amp;amp; Pass its reference as the 2nd Argument during the Function Call&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can also pass in any amount of arguments that the callback may need&lt;br&gt;
= &amp;amp; Arguments passed into Callbacks&lt;br&gt;
→ Make their way through to the Callback&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
function createEvent(date, callback) {&lt;br&gt;
        console.log(&lt;/code&gt;The event on ${date} has been created.`);&lt;br&gt;
        callback();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function displayEvent(){&lt;br&gt;
    console.log(&lt;code&gt;The event is being displayed.&lt;/code&gt;);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;createEvent(‘September 22nd, 2022’, displayEvent);&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Part 4 What do Callbacks look like in-action?
&lt;/h3&gt;

&lt;p&gt;= Asynchronous Callbacks are useful as a &lt;em&gt;Solution&lt;/em&gt; to &lt;strong&gt;Blocking Behavior&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;= Usually used when there is a transfer of data when doing I/O&lt;br&gt;
→ ie Downloading things, reading files, talking to database, etc. &lt;/p&gt;

&lt;h4&gt;
  
  
  Callback Queue
&lt;/h4&gt;

&lt;p&gt;= Everything in the Stack is ran before moving onto the Callback Queue &lt;br&gt;
→ Anything in a &lt;code&gt;setTimeout()&lt;/code&gt; is ran with the Callback Queue&lt;br&gt;
→ This means that even if something in the Callback Queue is never completed, the code keeps running&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Is the Callback Queue for all Callbacks or only Async Callbacks?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Common Use Cases
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;When an event fires&lt;br&gt;
= Event listeners &lt;br&gt;
ie &lt;code&gt;addEventListener&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After AJAX Calls&lt;br&gt;
= jQuery’s ajax method &lt;br&gt;
ie &lt;code&gt;jQuery.ajax&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After reading or writing to files &lt;br&gt;
= Node, ExpressJS&lt;br&gt;
ie &lt;code&gt;fs.readFile&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Purpose of Callbacks
&lt;/h4&gt;

&lt;p&gt;= Ensure response of Function is received/finished executing&lt;br&gt;
→ Before executing other code&lt;/p&gt;

&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;

&lt;p&gt;= Make Requests to an API&lt;br&gt;
→ Need to wait to receive a Response from Server&lt;br&gt;
To act based on Response&lt;br&gt;
→ Do not know if API Request is going to be successful&lt;/p&gt;

&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
T.get(’search/tweets’, params, function(err, data, response) {&lt;br&gt;
    if(!err){&lt;br&gt;
    // What to do if API request successfully executes&lt;br&gt;
    } else {&lt;br&gt;
        console.log(err);&lt;br&gt;
    }&lt;br&gt;
})&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
= After Response received&lt;br&gt;
→ Callback is invoked&lt;br&gt;
→ Twitter will either send an &lt;code&gt;err&lt;/code&gt; Object&lt;br&gt;
Or a &lt;code&gt;response&lt;/code&gt; Object back to us &lt;/p&gt;

&lt;p&gt;= Conditional w/in Callback &lt;br&gt;
→ Uses Information &lt;br&gt;
To determine if Request was successful or not &lt;br&gt;
Then act accordingly &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Part 5 What are the problems with Callbacks?
&lt;/h3&gt;

&lt;p&gt;The biggest problem with Callbacks is &lt;strong&gt;Callback Hell&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Callback Hell?
&lt;/h4&gt;

&lt;p&gt;= Multiple Callbacks nested after each other &lt;br&gt;
→ ie Doing an asynchronous activity &lt;br&gt;
That depends on previous asynchronous activity&lt;/p&gt;

&lt;h5&gt;
  
  
  Example Scenario
&lt;/h5&gt;

&lt;p&gt;= Usually, Callback Hell is found in the Backend&lt;br&gt;
→ While using Node &lt;br&gt;
→ Rare to see Callback Hell in Frontend JavaScript&lt;/p&gt;

&lt;p&gt;= Pyramid shape with numerous &lt;code&gt;})&lt;/code&gt;s at the end&lt;br&gt;
→ Result of attempts to write JS so execution occurs chronologically&lt;br&gt;
→ In JS, what occurs on 1st line will not necessarily finish before code in next line starts running&lt;br&gt;
ie Async functions, &lt;code&gt;setTimeout()&lt;/code&gt;s (which get ran after the call stack)&lt;/p&gt;

&lt;h5&gt;
  
  
  Why are Nested Callbacks bad?
&lt;/h5&gt;

&lt;p&gt;= Code much more difficult to read &lt;/p&gt;

&lt;h5&gt;
  
  
  What is the solution to Callback Hell?
&lt;/h5&gt;

&lt;p&gt;= To prevent Callback Hell, you can do these things:&lt;/p&gt;

&lt;h6&gt;
  
  
  1. Write Shallow Code
&lt;/h6&gt;

&lt;p&gt;&lt;em&gt;#1 Do not nest Anonymous Functions&lt;/em&gt;&lt;br&gt;
= Name all Functions&lt;br&gt;
→ Use Functions through reference to Names &lt;br&gt;
→ Rather than writing out elaborate logic of anonymous function&lt;br&gt;&lt;br&gt;
→ Code will be easier to understand → B/c descriptive Names&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If exceptions occur&lt;/em&gt;&lt;br&gt;
= Have Stack Traces w/ Function Names&lt;br&gt;
→ Bugs are easier to investigate&lt;/p&gt;

&lt;p&gt;&lt;em&gt;#2 Place all Functions at top-level program (‘below the fold’)&lt;/em&gt;&lt;br&gt;
= Take advantage of Function Hoisting&lt;br&gt;
→ Move all Functions to bottom of File&lt;br&gt;
→ Then, move into another File: When &amp;amp; If the load demands &lt;/p&gt;

&lt;h6&gt;
  
  
  2. Modularize
&lt;/h6&gt;

&lt;p&gt;&lt;em&gt;#1 Write small Modules&lt;/em&gt;&lt;br&gt;
= That each do 1 thing &lt;br&gt;
→ Compile them into other Modules that do a bigger thing&lt;br&gt;
→ ie Split code into couple of Files&lt;/p&gt;

&lt;p&gt;&lt;em&gt;#2 Isolated Files&lt;/em&gt;&lt;br&gt;
= Used by loading them through a relative &lt;code&gt;require()&lt;/code&gt;&lt;br&gt;
→ Then, can move Functions into standalone Module&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
= Create a new File for a series of Functions &lt;br&gt;
→ Performing related functionality&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ie&lt;/strong&gt; Module named &lt;code&gt;useruploader.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
module.exports.create = userCreate&lt;/p&gt;

&lt;p&gt;function userSubmit (submitEvent) {&lt;br&gt;
    var name = document.querySelector(‘input’).value&lt;br&gt;
    request({&lt;br&gt;
        uri: “&lt;a href="http://example.com/upload%E2%80%9D"&gt;http://example.com/upload”&lt;/a&gt;,&lt;br&gt;
        body: name,&lt;br&gt;
        method: “POST”&lt;br&gt;
    }, postResponse)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function postResponse (err, response, body) {&lt;br&gt;
    var statusMessage = document.querySelector(‘.status’)&lt;br&gt;
    if (err) return statusMessage.value = err&lt;br&gt;
    statusMessage.value = body &lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;module.exports&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Example of Node.js Module System &lt;br&gt;
→ Works in Node, Electron &amp;amp; Browser&lt;/p&gt;

&lt;h5&gt;
  
  
  Benefit of &lt;code&gt;module.exports&lt;/code&gt;
&lt;/h5&gt;

&lt;p&gt;= This style of Modules is good because it works everywhere&lt;br&gt;
→ Easy to understand&lt;br&gt;
→ Does not require complicated config files or scripts&lt;/p&gt;

&lt;h5&gt;
  
  
  Using &lt;code&gt;module.exports&lt;/code&gt; Modules
&lt;/h5&gt;

&lt;p&gt;= After File is created&lt;br&gt;
→ You need to require it &lt;br&gt;
→ &amp;amp; Use it in your application specific code&lt;/p&gt;

&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
var userUploader = require(‘useruploader’)&lt;br&gt;
document.querySelector(‘form’).onsubmit = userUploader.submit &lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Benefits of Modularising
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Comprehensibility
&lt;/h5&gt;

&lt;p&gt;= Code required in app is only 2 lines&lt;br&gt;
→ Allows new devs to more easily understand you code &lt;br&gt;
→ Won’t need read through details of all Functions w/in Module: When trying to grasp what Program is trying to do&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Error-handling, test-writing, creating a stable and documented public API
&lt;/h5&gt;

&lt;h5&gt;
  
  
  3. Refactoring
&lt;/h5&gt;

&lt;h5&gt;
  
  
  4. Reuse
&lt;/h5&gt;

&lt;p&gt;= W/o duplicating code &lt;br&gt;
→ Can easily be shared on Github or npm&lt;/p&gt;

&lt;h4&gt;
  
  
  How do you create good Modules?
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Move repeatedly used code into a Function
&lt;/h5&gt;

&lt;h5&gt;
  
  
  2. When Function/group of Functions gets large enough
&lt;/h5&gt;

&lt;p&gt;= Move them into another File &lt;br&gt;
→ Expose them using &lt;code&gt;module.exports&lt;/code&gt;&lt;br&gt;
→ Which can be loaded w/ a relative require&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Code that can be used across multiple projects
&lt;/h5&gt;

&lt;p&gt;= Give it a Read.me, tests, and &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
→ Public it to Github &amp;amp; npm &lt;/p&gt;

&lt;h5&gt;
  
  
  4. A Good Module
&lt;/h5&gt;

&lt;p&gt;= Small &amp;amp; focuses on 1 problem&lt;/p&gt;

&lt;h5&gt;
  
  
  5. Module Should Not
&lt;/h5&gt;

&lt;p&gt;= Have &amp;gt; 1 level of nested Folders full of JS Files&lt;br&gt;
→ If it does: It is likely doing too many things&lt;/p&gt;

&lt;h5&gt;
  
  
  6. Reference Examples of Good Modules
&lt;/h5&gt;

&lt;p&gt;= Get a good idea of what they look like&lt;/p&gt;

&lt;h5&gt;
  
  
  7. If Module takes &amp;gt; a few minutes to understand
&lt;/h5&gt;

&lt;p&gt;= Not Good&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Part 6 How should Callbacks be used?
&lt;/h3&gt;

&lt;p&gt;= Write Stable Code&lt;br&gt;
= Handle Every Error &lt;br&gt;
→ You should handle every single error&lt;br&gt;
→ In Every One of your Callbacks&lt;/p&gt;

&lt;h4&gt;
  
  
  How can you handle every error?
&lt;/h4&gt;

&lt;h5&gt;
  
  
  a. Plan on errors always happening
&lt;/h5&gt;

&lt;p&gt;= Can never know when Errors happens&lt;br&gt;
→ Must make code stable&lt;/p&gt;

&lt;h5&gt;
  
  
  b. Node.js Style
&lt;/h5&gt;

&lt;p&gt;= 1st Argument to Callback&lt;br&gt;
→ Always reserved for an Error&lt;br&gt;
→ Use &lt;code&gt;error&lt;/code&gt; as 1st Argument Convention &lt;br&gt;
→ Instead of adding it as the 2nd Argument&lt;/p&gt;

&lt;p&gt;= Reminds you to handle your errors &lt;/p&gt;

&lt;h5&gt;
  
  
  c. Code Linters
&lt;/h5&gt;

&lt;p&gt;= Help remind you to handle Callback Errors&lt;br&gt;
→ Show you every Callback in your code &lt;br&gt;
→ With an Unhandled Error &lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Errors
&lt;/h4&gt;

&lt;h5&gt;
  
  
  #1 Syntax Errors
&lt;/h5&gt;

&lt;p&gt;= Caused by Programmers &lt;br&gt;
→ Usually caught when trying to 1st run program &lt;/p&gt;

&lt;h5&gt;
  
  
  #2 Runtime Errors
&lt;/h5&gt;

&lt;p&gt;= Caused by Programmer&lt;br&gt;
→ Code ran, but had a bug that caused something to mess up &lt;/p&gt;

&lt;h5&gt;
  
  
  #3 Platform Errors
&lt;/h5&gt;

&lt;p&gt;= Caused by &lt;br&gt;
→ ie Invalid File Permissions, Hard Drive Failures, no Network Connection etc.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced"&gt;JavaScript: What the heck is a Callback? By Brandon Morelli&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://callbackhell.com/"&gt;Callback Hell: A guide to writing asynchronous JavaScript programs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/8aGhZQkoFbQ"&gt;What the heck is the event loop anyway? | Philip Roberts | JSConf EU&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Methods - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 16:17:08 +0000</pubDate>
      <link>https://forem.com/angelinewang/methods-javascript-core-concepts-146</link>
      <guid>https://forem.com/angelinewang/methods-javascript-core-concepts-146</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Section 2:&lt;/strong&gt; &lt;em&gt;&lt;strong&gt;Functions &amp;amp; Methods&lt;/strong&gt;&lt;/em&gt; of my &lt;strong&gt;JavaScript Core Concepts&lt;/strong&gt; Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
Part 2 Classes&lt;br&gt;
&lt;strong&gt;Part 3 Methods&lt;/strong&gt;&lt;br&gt;
Part 4 Callback Methods&lt;br&gt;
Part 5 Scope&lt;br&gt;
Part 6 Hoisting&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript Custom Methods
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Part 1 What are Methods in JavaScript?
&lt;/h3&gt;

&lt;p&gt;= Functions connected to an Object (becoming part of the Object)&lt;br&gt;
→ Behaviors of the Object&lt;/p&gt;

&lt;p&gt;= The fact that methods are usually inside an Object&lt;br&gt;
→ Is what makes it different to a function&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 2 How do you create Methods?
&lt;/h3&gt;

&lt;p&gt;= Assign a created Function to an Object&lt;/p&gt;

&lt;p&gt;Here are 3 ways to do it: &lt;/p&gt;
&lt;h4&gt;
  
  
  1st Way: Using a constructor
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date) {
    this.date = date    
    this.displayEvent = function(){
        return ‘The event is on ‘ + this.date
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2nd Way: Without a Constructor
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var flat8 = {date: ‘September 27th, 2022’}
flat8.displayEvent = function(){
    return ‘This event is on ‘ + this.date
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3rd Way: Using one big Object
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var flat8 = {
    date: ‘September 28th, 2022’
    displayEvent: function(){
        return ‘This event is on ‘ + this.date
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;...&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript Built-in Methods
&lt;/h2&gt;

&lt;p&gt;Below, I'll be going over a couple useful String Methods, Math Methods, Array Methods, and Object Methods.&lt;/p&gt;

&lt;p&gt;These should provide a brief overview of functionality offered...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 1 String Methods
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Where can you find Built-in Methods?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;MDN Web Docs&lt;/strong&gt;&lt;br&gt;
= Core document for the web, Javascript, CSS&lt;br&gt;
= Maintained by Mozilla for a while &lt;br&gt;
→ Look for: "String" → "Instance Methods" → "Code Examples"&lt;/p&gt;
&lt;h4&gt;
  
  
  View String Methods in VSCode
&lt;/h4&gt;

&lt;p&gt;= Type “myName.”&lt;/p&gt;
&lt;h4&gt;
  
  
  String Methods vs Properties
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;myName.length = Popular&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;.length&lt;/code&gt; is a &lt;strong&gt;Property&lt;/strong&gt;&lt;br&gt;
→ Returns number of characters w/in string&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;myName.toUpperCase()&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;.toUpperCase&lt;/code&gt; is a &lt;strong&gt;Method&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Concatenating Strings
&lt;/h4&gt;

&lt;p&gt;= Adding them together &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;const myName = firstName + secondName;&lt;/code&gt;&lt;br&gt;
= Adds them tightly together &lt;/p&gt;

&lt;p&gt;If you want &lt;em&gt;space&lt;/em&gt; between strings &lt;br&gt;
= Add them &lt;em&gt;within a string&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;.toUpperCase()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Logs all characters of string in uppercase &lt;br&gt;
Does not change original variable value&lt;/p&gt;
&lt;h5&gt;
  
  
  First Character Uppercase &amp;amp; All Else Lowercase
&lt;/h5&gt;

&lt;p&gt;= Options to complete:&lt;/p&gt;

&lt;p&gt;a. &lt;code&gt;language.replace(“j”, “J”)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;b. &lt;code&gt;language.charAt().toUpperCase() + language.slice(i)&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;charAt&lt;/code&gt;: Finding the character at that position&lt;br&gt;
= &lt;code&gt;slice&lt;/code&gt;: Takes a beginning index &amp;amp; an optional ending index &lt;br&gt;
→ Including &amp;amp; excluding the number is different for the two&lt;br&gt;
&lt;code&gt;${langugae.charAt().toUpperCase()}${language.slice()}&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Character Codes
&lt;/h5&gt;

&lt;p&gt;= Where the character is on this table: &lt;a href="http://www.AsciiTable.com"&gt;www.AsciiTable.com&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 2 Math Methods
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Display in VSCode Color
&lt;/h4&gt;

&lt;p&gt;= Orange &lt;/p&gt;
&lt;h4&gt;
  
  
  Math.floor
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Takes a Floating Point Number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eliminates Decimals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rounds down to nearest Whole Number less than it&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Math.ceil
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Takes Floating Point Number &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eliminates Decimals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rounds to nearest Whole Number more than it&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Math.round
&lt;/h4&gt;

&lt;p&gt;= Rounds to nearest Whole Number&lt;br&gt;
→ Depending on Decimal Amount&lt;/p&gt;
&lt;h4&gt;
  
  
  Math.random
&lt;/h4&gt;

&lt;p&gt;= Generates a Random Number between 0 &amp;amp; 1&lt;br&gt;
→ Numbers generated are not truly random &lt;br&gt;
→ Have scenes to create pseudo-random numbers&lt;/p&gt;
&lt;h4&gt;
  
  
  View Math Methods
&lt;/h4&gt;

&lt;p&gt;= To apply Math methods to Math objects&lt;br&gt;
→ You can type “Math.” into VSCode&lt;br&gt;
→ And you can find what you need in the list &lt;/p&gt;
&lt;h4&gt;
  
  
  Practical Uses
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Docs &amp;amp; Autocomplete&lt;/li&gt;
&lt;li&gt;Memorizing Objects &amp;amp; Methods&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 3 Array Methods
&lt;/h3&gt;
&lt;h4&gt;
  
  
  How do you access Array Methods?
&lt;/h4&gt;

&lt;p&gt;= Arrays are tied to &lt;code&gt;Array.prototype&lt;/code&gt;&lt;br&gt;
→ Array methods work on Arrays &amp;amp; any Array-like Objects&lt;/p&gt;

&lt;p&gt;Here are a few useful Array Methods…&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.indexOf()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.indexOf(searchElement, *from index of*)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;p&gt;= Searches Array for an Element including a specific value&lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;Option&lt;/em&gt;: Provide a starting Index to Function&lt;br&gt;
&lt;em&gt;No Provided Start Index&lt;/em&gt;: Search will begin from Index 0 &lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Lowest Index greater than or equal to start of Array&lt;br&gt;
→ Where Element is equal to given value &lt;br&gt;
→ AKA the Index of the 1st Element equal to the given value&lt;/p&gt;
&lt;h6&gt;
  
  
  What happens if no match is found?
&lt;/h6&gt;

&lt;p&gt;= Function returns: &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Examples:
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var events = [‘Party’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’];

console.log(events.indexOf(‘Dinner’)); // Logs: 1
console.log(events.indexOf(‘Show’, 1)); // Starts searching at element at index 1, and Logs: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Array of events, and there might be multiple of a given event
&lt;/h5&gt;

&lt;p&gt;→ &lt;code&gt;indexOf()&lt;/code&gt; can be used to find all Instances of ‘Party’ in the array of events&lt;br&gt;
→ Executing the code displays that ‘Party’ is found at Index 0 and 4 of the Array &lt;/p&gt;
&lt;h6&gt;
  
  
  Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var events = [‘Party’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];
var event = ‘Party’;
var eventLocation = events.indexOf(event);
while (eventLocation != -1) { // While there exists an event called ‘Party’ within the events array
    locatedat.push(eventLocation);
    eventLocation = events.indexOf(event, eventLocation + 1); // Starts searching for other instances of ‘Party’ AFTER the index of where the first instance of ‘Party’ was found
}
console.log(locatedat); // Logs: 0, 4 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Using a Custom Function to ensure that each Event is within the array of events, and if they do not exist, we add them to the array:
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function existingEvents(events, event) {
    if (events.indexOf(event) ===  -1) { // If the event does not exist within the array of events 
        events.push(event);
        console.log(‘The new events are ’ + events);
} else if (events.indexOf(event) &amp;gt; -1) {
    console.log(event + ‘ is already part of the events.’)
}
}

var events = [‘Party’, ‘Dinner’, ‘Show’];

existingEvents(events, ‘Party’); // Party is already part of the events.
existingEvents(events, ‘Movie’); // The new events are Party,Dinner,Show,Movie 
existingEvents(events, Dance); // The new events are Party,Dinner,Show,Movie,Dance
existingEvents(events, ‘Parade’); // The new events are Party,Dinner,Show,Movie,Dance,Parade
existingEvents(events, ‘Dinner’); // Dinner is already part of the events.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.slice()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.slice([beginning index], [ending index])&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Accepts a start and end Argument &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only looks into the Array from start (inclusive) to end (non-inclusive) Index&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eliminates a specific amount of Elements &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;No End Value Provided&lt;/em&gt;&lt;br&gt;
= Returns rest of Array&lt;br&gt;
→ Beginning from provided start point&lt;/p&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= No&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Returns a new Array including all Elements of original Array&lt;br&gt;
→ From Element specified by starting point provided &lt;br&gt;
→ And up to but not including Element specified by ending point provided&lt;/p&gt;
&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var events = [‘Party’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];
var choppedEvents = events.slice(2,3);

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

&lt;/div&gt;


&lt;p&gt;= Slice Method needs to be assigned to a Variable upon invocation in order for the Result to be recorded&lt;br&gt;
→ The elements being sliced will be picked out and recorded &lt;br&gt;
→ In order to return only one element, the element’s index, along with the index after it, needs to be provided&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.toString()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.toString()&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Converts all Elements in Array to Strings &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Outputs 1 big String&lt;br&gt;
= As a comma separated list of items &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.filter()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.filter(*callback function*, *arguments*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;p&gt;= Filters down a collection of Elements &lt;br&gt;
→ Based on a given test&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In order to call filter()&lt;/em&gt;&lt;br&gt;
= Need to pass a Callback &lt;br&gt;
→ Callback is executed against every Element in Array &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If Callback results in &lt;code&gt;true&lt;/code&gt; value&lt;/em&gt;&lt;br&gt;
= That particular Element is added to a NEW Array &lt;br&gt;
→ Leaving original Array unchanged &lt;/p&gt;
&lt;h5&gt;
  
  
  Mutate Original?
&lt;/h5&gt;

&lt;p&gt;= No&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= New Array&lt;br&gt;
→ Containing only Elements of original Array that returned &lt;code&gt;true&lt;/code&gt; when provided Callback ran &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.join()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;string = array.join([separator = ‘,’])&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Converts each Element of Array to a String &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then concatenates those Strings together &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;If separator string provided&lt;/em&gt;&lt;br&gt;
= Gets inserted between all Elements in final String&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;String that results from converting each Element of original Array to a String &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then joins them together &lt;br&gt;
= With separator String between Elements &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.splice()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.splice(*starting index*, *number of elements to delete*, *element to insert in place of deleted*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Delete 0 or more Elements &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Beginning from provided start location &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replaces those Elements with 0 or more new values provided &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Existing items in Array are shifted&lt;br&gt;
= As needed to make room for any added or deleted Elements&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= Yes, it modifies the original Array directly&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Returns an Array containing any Elements that may have been deleted from Array &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.forEach()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.forEach(*callback function*, *arguments*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;p&gt;= Executes a provided Function&lt;br&gt;
→ On each Element of Array &lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= No return value &lt;br&gt;
→ Does not return the original Array &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;= Related to &lt;code&gt;.map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, &lt;code&gt;every()&lt;/code&gt;, and &lt;code&gt;some()&lt;/code&gt;&lt;br&gt;
→ Because they share some related details &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;All expect a Callback Function as 1st argument &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All check length of array before looping &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Optional 2nd Argument&lt;/em&gt;&lt;br&gt;
= Way to specify the &lt;code&gt;this&lt;/code&gt; value for Callback Function &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If Callback Provided&lt;/em&gt;&lt;br&gt;
= Adds Elements to Array during execution &lt;br&gt;
→ Elements are not included for looping by &lt;code&gt;forEach()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If Callback changes original Array values&lt;/em&gt;&lt;br&gt;
= Before they are looped over&lt;br&gt;
→ Those changed values will be passed during Callback execution&lt;/p&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= Yes &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.concat()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;var newArray = oldArray.concat(value1, value2, value3)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creates new Array which is result of adding supplied Arguments to original Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Original Array left intact &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;New Array is original plus any added Elements&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= No &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Any Arguments in &lt;code&gt;concat()&lt;/code&gt; Function are Arrays&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Elements of the supplied Array are added&lt;br&gt;
= Rather than entire Array itself &lt;br&gt;
→ So you are adding all those Elements&lt;br&gt;
→ Rather than adding an Array as one Element within an Array &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= A new Array &lt;br&gt;
→ Which is created by adding each of the supplied Arguments to original Array &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.shift()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.shift()&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Removes &amp;amp; Returns 1st Element of original Array &lt;/li&gt;
&lt;li&gt;All remaining Elements in Array get shifted 1 slot to the left 
= To fill hole created by removing 1st Element&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= Yes &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;If apply function to empty Array&lt;/em&gt; &lt;br&gt;
= Does nothing &lt;br&gt;
→ Simply returns &lt;code&gt;undefined&lt;/code&gt;&lt;br&gt;
= Does not create a new Array&lt;br&gt;
→ Modifies original array directly&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Returns 1st Element from original Array &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.unshift()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.unshift(*element1*, *element2*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Direct opposite of &lt;code&gt;shift()&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inserts any Arguments passed into beginning of Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All existing Elements need to shift to right to accommodate new Elements &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each Argument passed to &lt;code&gt;unshift()&lt;/code&gt; gets added&lt;br&gt;
= In order starting from Index 0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modifies original Array directly &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Mutates Original?
&lt;/h5&gt;

&lt;p&gt;= Yes &lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= New length of the Array&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.map()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.map(*callback function*, *arguments*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Loops over every Element in Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Executes a Callback Function on each item&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After &lt;code&gt;map()&lt;/code&gt; has completed looping through Array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Takes results from each Callback applied to each Element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then returns all those results as an Array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Left with: New Array w/ updated Values &amp;amp; Old Array w/ original Values &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The 2 Arrays are equal in length &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;When Callback Invoked&lt;/em&gt;&lt;br&gt;
= Done so with 3 arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Value of element &lt;/li&gt;
&lt;li&gt;Index of element &lt;/li&gt;
&lt;li&gt;Array object being traversed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Optional 2nd Parameter Provided&lt;/em&gt;&lt;br&gt;
= Used at the &lt;code&gt;this&lt;/code&gt; value for each execution of the Callback &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; vs &lt;code&gt;forEach()&lt;/code&gt;&lt;br&gt;
= Seem like same &lt;br&gt;
→ But different&lt;/p&gt;

&lt;p&gt;&lt;code&gt;forEach()&lt;/code&gt; &lt;br&gt;
= Iterates over Array &lt;br&gt;
= &amp;amp; Applies some operation with side effects to each array member&lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; Saving each one to the database or Some other side effect &lt;/p&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt;&lt;br&gt;
= Iterates over Array &lt;br&gt;
= &amp;amp; Updates each member of Array &lt;br&gt;
→ Returns: Another array of same size → With transformed members &lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; Converting array of strings to all lowercase&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Returns a new Array &lt;br&gt;
→ With Elements computed by provided Callback Function &lt;/p&gt;
&lt;h5&gt;
  
  
  Use Cases
&lt;/h5&gt;

&lt;p&gt;= A lot in professional software&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.sort()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.sort([compareFunction])&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Applies the sort directly on original Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No copy is made&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Optionally provide a Callback Function &lt;br&gt;
= To create custom behavior for tne sort&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  Mutuates Original?
&lt;/h6&gt;

&lt;p&gt;= Yes&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Reference to original Array &lt;/p&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;No Callback Function Provided&lt;/em&gt;&lt;br&gt;
= Function will 1st convert all elements to strings &lt;br&gt;
→ Then sort based on something called Unicode code point value &lt;br&gt;
→ Alphabetical&lt;br&gt;
→ But with some special rules &lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; Capital letters coming before lowercase &lt;/p&gt;
&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Without Callback
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var names = [‘Angeline Wang’, ‘Paul Smith’, ‘Judy Palmer’, ‘Tracey Chan’];
names.sort(); // Sorts the elements into alphabetical order

var nums = [1, 10, 2, 21, 33, 04, 12, 09, 300];
nums.sort(); // Sorts numbers by unicode code point value, so not directly by chronological order: For example, 10 comes before 2 in Unicode code point order

var usernames = [‘223angeline’, ‘angelinewang’, ‘4paulsmith’] ;
usernames.soft();
// In Unicode, numbers come before uppercase letters, which come before lowercase letters 

console.log(names);
// [“Angeline Wang", "Judy Palmer", "Paul Smith", "Tracey Chan"]

console.log(nums);
// [1, 10, 12, 2, 21, 300, 33, 4, 9]

console.log(usernames);
// [‘223angeline’, ‘4paulsmith’, ‘angelinewang’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;If Callback not provided to sort method&lt;/em&gt;&lt;br&gt;
= Ordering may not be what you expect: B/c unicode code point order &lt;br&gt;
→ Rules for ordering in Unicode are a bit unique &lt;br&gt;
→ &lt;strong&gt;ie&lt;/strong&gt; Numbers come before uppercase letters, uppercase letters come before lowercase letters&lt;br&gt;
→ Array of numbers is converted to Strings, before sorting: So this is why 33 comes before 4 &amp;amp; 9 in above example&lt;/p&gt;
&lt;h6&gt;
  
  
  With Callback
&lt;/h6&gt;

&lt;p&gt;= And now sorts in the order for numbers you’d expect&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var nums = [1, 10, 2, 21, 33, 04, 12, 09, 300];
nums.sort(numsasexpected);

function numsasexpected(one, two) {
    return one - two;
}

console.log(nums);
// [1, 2, 4, 9, 10, 12, 21, 33, 300]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.pop()&lt;/code&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.pop()&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Opposite of &lt;code&gt;push()&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Removes last Element from an Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decrements length of Array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns value removed from Array &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;= If you apply &lt;code&gt;pop()&lt;/code&gt; to an empty array &lt;br&gt;
→ Will return &lt;code&gt;undefined&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Last Element of Array it is called on &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.reduce()&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.reduce(*callback function*, *initial value*)&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Accepts a function as 1st parameter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Acts like a binary operator &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Callback Function takes 2 values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Operates on them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns a value &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Number of times Callback Function runs &lt;br&gt;
= Always 1 less than total length of original Array&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If original Array has length of 10&lt;br&gt;
= Callback will run 9 times &lt;br&gt;
→ Final result: 1 combined Value &lt;/p&gt;
&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Reduced value of Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is the return value of the last time the Callback Function is executed &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;

&lt;p&gt;= Execute &lt;code&gt;.reduce()&lt;/code&gt; over values inside a simple array of objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var users = [
    {   
        name: ‘Stacey’,
        university: ‘King’s College London’,
        course: ‘Law’,
        degreeLevel: ‘BA’,
        age: 21,
        partiesHosted: 2
    },
    {   
        name: ‘Tom’,
        university: ‘King’s College London’,
        course: ‘Business’,
        degreeLevel: ‘BA’,
        age: 21,
partiesHosted: 4
    },
    {   
        name: ‘Drake’,
        university: ‘King’s College London’,
        course: ‘Business’,
        degreeLevel: ‘BA’,
        age: 22,
        partiesHosted: 2
    },
    {   
        name: ‘Emily’,
        university: ‘King’s College London’,
        course: ‘Social Sciences’,
        degreeLevel: ‘MA’,
        age: 19,
        partiesHosted: 2
    }
];

var totalParties = users.reduce(function (prev, current) {
    return prev + current.partiesHosted;
}, 0);

console.log(‘Users have a cumulative of: ’ + totalParties + ‘parties hosted!’);
// Users have a cumulative of: 10 parties hosted! 

var degreeLevelTotals = users.reduce(function (groupedByDegreeLevel, user) {
    var degreeLevel = user.degreeLevel;
    if (!groupedByDegreeLevel[degreeLevel]) {
        groupedByDegreeLevel[degreeLevel] = 0;
    }
    groupedByDegreeLevel[degreeLevel] += user.partiesHosted;
    return groupedByDegreeLevel;
}, {});

console.log(‘Our users have ’ + degreeLevelTotals[‘MA’] + ‘ parties hosted by masters students and ‘ + degreeLevelTotals[‘BA’] + ‘ parties hosted by bachelors students!’);

// Our users have 2 parties hosted by masters students and 8 parties hosted by bachelors students!

var usersByDegreeLevel = users.reduce(function (groupedByDegreeLevel, user) {
    if (!groupedByDegreeLevel[user.degreeLevel]) {
        groupedByDegreeLevel[user.degreeLevel] = 0;
    }
    groupedByUsers[user.degreeLevel]++;
    return groupedByUsers;
}, {}); 

console.log(‘We have ’ + usersByDegreeLevel[‘MA’] + ‘ user(s) completing a masters degree, and ’ + usersByDegreeLevel[‘BA’] + ‘ users completing a bachelor's degree!’);

// We have 1 user(s) completing a masters degree, and 3 users completing a bachelor’s degree!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.some()&lt;/code&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.some(*callback function*, *arguments*)&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Runs provided Callback on each Element in the Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If Callback returns &lt;code&gt;true&lt;/code&gt; even once&lt;br&gt;
= Function stops straight away &lt;br&gt;
→ And returns &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If ALL Callback Iterations return &lt;code&gt;false&lt;/code&gt; &lt;br&gt;
= Function returns &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Takes a Callback as 1st Argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Takes an Optional 2nd Argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If 2nd Argument Provided&lt;br&gt;
= Specifies &lt;code&gt;this&lt;/code&gt; value for invocations of supplied Callback&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;p&gt;= Returns either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;&lt;br&gt;
→ At least 1 item in array must return &lt;code&gt;true&lt;/code&gt; &lt;br&gt;
→ For Function to return &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function containsParty(element, index, array) {
    return element === ‘Party’;
} 

var eventsThisWeek =  [‘Party’, ‘Show’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];
var eventsNextWeek =  [‘Show’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’];

console.log(eventsThisWeek.some(containsParty)); // true 
console.log(eventsNextWeek.some(containsParty)); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Array.prototype.lastIndexOf()
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.lastIndexOf(*searchElement*, [*fromIndex = arr.length-1*])&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Tests for Strict Equality &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Searches through an array backwards for the value provided in the first argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the function locates the value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns the index position of where it exists in the array &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Optional 2nd Argument not provided&lt;/em&gt;&lt;br&gt;
= Search will begin from that point&lt;br&gt;
→ And goes backwards&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2nd Argument is Provided&lt;/em&gt;&lt;br&gt;
= Search starts at end of Array &lt;br&gt;
→ If no match is found &lt;br&gt;
→ &lt;code&gt;-1&lt;/code&gt; is returned&lt;/p&gt;

&lt;h5&gt;
  
  
  Returns
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Highest index position (first found, counting from end)&lt;br&gt;
= That is less than or equal to the start of the array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Element needs to match strictly equal to value provided&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If no match, then returns &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Find One
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var events = [‘Party’, ‘Show’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];

console.log(events.lastIndexOf(‘Show’)) // Finds the last instance of ‘Show’ and logs: 3
console.log(events.lastIndexOf(‘Party’)) // Starts looking from end of array and logs: 6
console.log(events.lastIndexOf(‘Dance’, 3)); // Starts looking at index position 3, and looks backwards, and logs: -1 because there are no instances of ‘Dance’ at or before the index position 3 
console.log(events.lastIndexOf(‘Show’, -4)); // Starts looking at index position 3, and finds the element there so logs: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  Find All
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var locatedat = [];
var events = [‘Party’, ‘Show’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];
var event = ‘Show’;
var eventLocation = enemies.lastIndexOf(event);
while (enemyLocation != -1) {
    locatedat.push(enemyLocation);
    eventLocation = events.lastIndexOf(event, eventLocation -1);
}
console.log(locatedat); // 3, 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.reduceRight()&lt;/code&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.reduceRight(*callback function*, *initial Value*)&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Works same as &lt;code&gt;reduce()&lt;/code&gt;
= But w/ 1 difference: &lt;code&gt;reduceRight()&lt;/code&gt; counts array elements from &lt;em&gt;right&lt;/em&gt; to left 
→ Counts from &lt;em&gt;highest&lt;/em&gt; index to the lowest index number
→ Rather than left to right, lowest to highest index number &lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var sum = [0, 1, 1, 2, 3, 5, 8].reduceRight(function (a, b) {
    return a + b;
});

console.log(sum); // 20

var flat = [[0, 10], [20, 30, [1, 2, 3, 4]], [40, 50]].reduceRight(function (a, b) {
    return a.concat(b);
}, []);

console.log(flat); // [40, 50, 20, 30, [1, 2, 3, 4], 0, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Array.prototype.every()
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.every(*callback function*, *arguments*)&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Test if a condition is true for ALL Elements in Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expected to provide a Callback Function &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Callback Function runs on each Element in Array &lt;br&gt;
= From lowest to highest index &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;em&gt;all&lt;/em&gt; Iterations return &lt;code&gt;true&lt;/code&gt; when Callback runs &lt;br&gt;
= &lt;code&gt;every()&lt;/code&gt; function itself will return &lt;code&gt;true&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;em&gt;even one&lt;/em&gt; iteration of Callback returns &lt;code&gt;false&lt;/code&gt; &lt;br&gt;
= &lt;code&gt;every()&lt;/code&gt; stops right away &amp;amp; returns &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greaterThan10(element, index, array) {
    return element &amp;gt; 10;
}

arr1 = [11, 12, 13, 14];
arr2 = [20, 21, 12, 9];

console.log(arr1.every(greaterThan10)); // true
console.log(arr2.every(greaterThan10)); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;Array.prototype.reverse()&lt;/code&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;array.reverse()&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Reverses order of Elements in Array &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mutates original Array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No new Array created or returned &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Mutates original?
&lt;/h5&gt;

&lt;p&gt;= Yes&lt;/p&gt;

&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Many references to particular Array in the Program&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And you reverse the array&lt;br&gt;
= All references now also see an array which has been reversed&lt;br&gt;
→ Leaving dependent operations affected&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var events = [‘Party’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’];
events.reverse();

console.log(events);
// [‘Party’, ‘Dinner’, ‘Show’, ‘Movie’, ‘Dance’, ‘Party’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Note how this method invocation does not need to be attached to a variable since it directly works on the original &lt;/p&gt;

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

&lt;h3&gt;
  
  
  Part 4 Object Methods
&lt;/h3&gt;

&lt;h4&gt;
  
  
  How do you access values in an Object?
&lt;/h4&gt;

&lt;p&gt;= Since values in an Object are not indexed&lt;br&gt;
→ They are accessed through their Keys &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;.forEach()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Array Iterator Method that CANNOT be used to iterate over the keys on an &lt;em&gt;Object&lt;/em&gt;&lt;br&gt;
→ Instead, a &lt;code&gt;for in&lt;/code&gt; Loop should be used instead…&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;for in&lt;/code&gt; Loop
&lt;/h4&gt;

&lt;p&gt;= This is similar to a &lt;code&gt;forEach&lt;/code&gt; Loop&lt;br&gt;
→ Purpose: Iterate over an Object&lt;/p&gt;

&lt;h5&gt;
  
  
  Parameters
&lt;/h5&gt;

&lt;h6&gt;
  
  
  1. Key
&lt;/h6&gt;

&lt;p&gt;= All Keys in that Object &lt;/p&gt;

&lt;h6&gt;
  
  
  2. Object
&lt;/h6&gt;

&lt;p&gt;= Name of the Object &lt;/p&gt;

&lt;h5&gt;
  
  
  Syntax
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let key in car) {
    console.log(car[key])
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;p&gt;= Iterates over each key/value pair&lt;/p&gt;

&lt;p&gt;&lt;em&gt;During Each Iteration&lt;/em&gt;&lt;br&gt;
The Key = Whatever is incrementing&lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; &lt;code&gt;car.type = (let type in car)&lt;/code&gt;, &lt;code&gt;car.color = (let color in car)&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Log Value of a Key of an Object
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Syntax
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;console.log(car[key])&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Object.keys&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Returns all the keys within the Object = An Array &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Object.values&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Returns all the values within the Object = An Array&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;Object.entries&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Returns all the key/value pairs = An Array of Arrays &lt;/p&gt;

&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://vegibit.com/most-useful-javascript-array-functions/"&gt;Most Useful JavaScript Array Functions&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Classes - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 15:01:15 +0000</pubDate>
      <link>https://forem.com/angelinewang/classes-javascript-core-concepts-1gd9</link>
      <guid>https://forem.com/angelinewang/classes-javascript-core-concepts-1gd9</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Section 2:&lt;/strong&gt; &lt;em&gt;&lt;strong&gt;Functions &amp;amp; Methods&lt;/strong&gt;&lt;/em&gt; of my &lt;strong&gt;JavaScript Core Concepts&lt;/strong&gt; Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
&lt;strong&gt;Part 2 Classes&lt;/strong&gt;&lt;br&gt;
Part 3 Methods&lt;br&gt;
Part 4 Callback Methods&lt;br&gt;
Part 5 Scope&lt;br&gt;
Part 6 Hoisting&lt;/p&gt;
&lt;h2&gt;
  
  
  Classes
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Part 1 What are Classes?
&lt;/h3&gt;

&lt;p&gt;= Template for creating Objects &lt;br&gt;
→ Record data using logic that works through the data &lt;/p&gt;
&lt;h4&gt;
  
  
  How are JavaScript classes created?
&lt;/h4&gt;

&lt;p&gt;= They are created on Prototypes &lt;br&gt;
→ And include some syntax &amp;amp; semantics that are not shared with ES5 class-like semantics&lt;/p&gt;
&lt;h4&gt;
  
  
  What is the purpose of Classes?
&lt;/h4&gt;

&lt;p&gt;= Class declaration introduced in ES2015&lt;br&gt;
→ Just syntactic sugar: On top of existing prototype-based inheritance &lt;br&gt;
→ Does not add anything new to JavaScript&lt;/p&gt;

&lt;p&gt;= Classes can add Properties, Methods &amp;amp; Functions &lt;br&gt;
→ Methods created can be ran later: After the Constructor/Object is created&lt;br&gt;
&lt;strong&gt;2 Types of Methods&lt;/strong&gt;:&lt;br&gt;
&lt;em&gt;1. Instance Methods&lt;/em&gt;&lt;br&gt;
= Can be called by Instances&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Static Methods&lt;/em&gt;&lt;br&gt;
= Can be called by the Class&lt;/p&gt;
&lt;h4&gt;
  
  
  How do you define a &lt;code&gt;Class&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;= 2 Ways to define a Class:&lt;/p&gt;
&lt;h5&gt;
  
  
  1st Way: Class Expressions
&lt;/h5&gt;
&lt;h6&gt;
  
  
  #1 Can be Named or Unnamed
&lt;/h6&gt;

&lt;p&gt;= Name given: Is local to Class’ body &lt;br&gt;
→ But can be accessed through the &lt;code&gt;name&lt;/code&gt; property of the Class&lt;/p&gt;
&lt;h6&gt;
  
  
  #2 Need to be declared
&lt;/h6&gt;

&lt;p&gt;= Before they can be used&lt;br&gt;
→ Due to hoisting restrictions&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Body of a Class&lt;/em&gt;&lt;br&gt;
= W/in curly braces &lt;br&gt;
→ Where Class members &lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; Methods &amp;amp; Constructor are defined &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Execution in Strict Mode&lt;/em&gt;&lt;br&gt;
= Stricter syntax for optimal performance&lt;br&gt;
→ Normally silent errors thrown&lt;br&gt;
→ Particular keywords reserved for ECMAScript future versions&lt;/p&gt;
&lt;h5&gt;
  
  
  2nd Way: Class Declarations
&lt;/h5&gt;

&lt;p&gt;= Using &lt;code&gt;Class&lt;/code&gt; keyword&lt;br&gt;
→ Followed by the name of the Class&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    constructor(date, time) {
        this.date = date;
        this.time = time;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h6&gt;
  
  
  Function Declarations vs Class Declarations
&lt;/h6&gt;

&lt;p&gt;&lt;em&gt;Function Declarations&lt;/em&gt;&lt;br&gt;
= Can be called in code before they are defined &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Class Declarations&lt;/em&gt; &lt;br&gt;
= Need to be defined before they can be constructed&lt;br&gt;
→ Because the Class is hoisted: But its values are not initialized &lt;/p&gt;
&lt;h4&gt;
  
  
  Class Re-definition
&lt;/h4&gt;

&lt;p&gt;= Re-defining a Class is not possible &lt;br&gt;
→ An Attempt to redefine a Class will result in: &lt;code&gt;SyntaxError&lt;/code&gt; &lt;br&gt;
Alerting you that you are trying to declare a variable that has already been declared&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 2 Constructor Methods
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose of Constructors &amp;amp; Prototypes
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Act as JavaScript’s main method of defining similar &amp;amp; related Objects &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bring similar functionality facilitated through Classes in &lt;em&gt;other&lt;/em&gt; languages &lt;br&gt;
= Does not &lt;em&gt;add&lt;/em&gt; extra functionality&lt;br&gt;
→ Thus &lt;code&gt;Class&lt;/code&gt; Declaration made available through ES2015: Just syntactic sugar for existing prototype-based inheritance&lt;br&gt;
Rapidly accumulate many different Objects &lt;br&gt;
= By calling a Constructor different times w/ different arguments&lt;br&gt;
→ Reflective of pattern used in built-in constructors &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  What are Constructor Methods?
&lt;/h4&gt;

&lt;p&gt;= Here are a few definitions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Mold for creating multiple Objects w/ same Properties &amp;amp; Methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Special Method for creating &amp;amp; initializing an Object created w/ a &lt;code&gt;Class&lt;/code&gt;&lt;br&gt;
= Can only be 1 special method w/ name &lt;code&gt;constructor&lt;/code&gt; in a Class &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any Function that can be used as a Constructor &lt;br&gt;
= No specific distinction within the language &lt;br&gt;
→ Function can be written to be used as a Constructor, to be called as a Normal Function, or it can be used either way&lt;br&gt;
&lt;em&gt;ie JS functions&lt;/em&gt;: Are also Object Constructors &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date, time) {
    this.date = date;
    this.time = time;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Types of Constructors
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Type #1: Built-in constructors
&lt;/h5&gt;

&lt;p&gt;= Accessible directly in execution environment at runtime &lt;/p&gt;
&lt;h6&gt;
  
  
  #1 Object()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #2 Array()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #3 String()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #4 Number()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #5 Boolean()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #6 Date()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #7 Function()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #8 Error()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  #9 RegExp()
&lt;/h6&gt;
&lt;h6&gt;
  
  
  Creation of Values
&lt;/h6&gt;

&lt;p&gt;= There are 2 ways to create values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Object Literals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constructors&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Object literals vs Constructors&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  1 Barely any difference
&lt;/h1&gt;

&lt;p&gt;= Can call Methods on Literals&lt;br&gt;
→ Which means JavaScript will turn the Literal into a temporary Object &lt;br&gt;
→ Helping the Method perform the operation &lt;br&gt;
→ Temporary Object is then trashed when it is no longer useful&lt;/p&gt;
&lt;h1&gt;
  
  
  2 Why are Object Literals better?
&lt;/h1&gt;

&lt;p&gt;a. Easier to read&lt;/p&gt;

&lt;p&gt;b. Faster to run&lt;br&gt;
= Can be optimised at parse time&lt;br&gt;
Simple Objects &lt;/p&gt;

&lt;p&gt;Example: &lt;br&gt;
Instead of using this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var obj = new Object(5);
obj.toFixed(2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should use this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var num = 5;
num.toFixed(2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Type #2: Custom Constructors
&lt;/h5&gt;

&lt;p&gt;= Define Properties &amp;amp; Methods for your own type of Object&lt;/p&gt;

&lt;h6&gt;
  
  
  Custom Constructor Creation
&lt;/h6&gt;

&lt;p&gt;= Just like creating a Function &lt;br&gt;
→ Capitalize their name: As convention &amp;amp; for identifiability&lt;/p&gt;

&lt;p&gt;= A Constructor can also use the &lt;code&gt;super&lt;/code&gt; keyword&lt;br&gt;
→ To call the Constructor of a superclass&lt;/p&gt;
&lt;h4&gt;
  
  
  Scope-safe Constructors
&lt;/h4&gt;
&lt;h5&gt;
  
  
  What are scope-safe constructors?
&lt;/h5&gt;

&lt;p&gt;= Made to return same result &lt;br&gt;
→ No matter if it’s called with or without &lt;code&gt;new&lt;/code&gt; &lt;br&gt;
→ Protects against mistake of omitting &lt;code&gt;new&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  What is the purpose of scope-safe constructors?
&lt;/h5&gt;

&lt;p&gt;= New programmers can accidentally call a Constructor&lt;br&gt;
→ W/o &lt;code&gt;new&lt;/code&gt; keyword &lt;br&gt;
Resulting in bugs&lt;/p&gt;
&lt;h5&gt;
  
  
  Which constructors are scope-safe?
&lt;/h5&gt;

&lt;p&gt;= Majority of Built-in Constructors&lt;br&gt;
→ ie &lt;code&gt;Object&lt;/code&gt;, &lt;code&gt;Regex&lt;/code&gt; and &lt;code&gt;Array&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;= They use a unique pattern to call the Constructor&lt;br&gt;
→ So that in the case &lt;code&gt;new&lt;/code&gt; is not used&lt;/p&gt;

&lt;p&gt;= Returns a proper Instance of the Object&lt;br&gt;
→ Through calling Constructor again w/ &lt;code&gt;new&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  Make a Custom Constructor scope-safe
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date, time) {
    if (!(this instanceof Event)) {
        return new Event(date, time);
    }
    this.date = date;
    this.time = time;
}

var event1 = new Event(“September 24th, 2022”, “12:20PM”);
var event2 = Event(“September 24th, 2022”, “12:20PM”);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Now both these variable definitions (with and without &lt;code&gt;new&lt;/code&gt;), will return an instance of &lt;code&gt;Event&lt;/code&gt; &lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;Object.defineProperty()&lt;/code&gt; Method
&lt;/h4&gt;

&lt;p&gt;= Can be used w/in a Constructor &lt;br&gt;
→ To execute the Property setup needed &lt;/p&gt;

&lt;p&gt;Here’s a Use Case…&lt;/p&gt;
&lt;h5&gt;
  
  
  User Input Manipulation
&lt;/h5&gt;

&lt;p&gt;= Before assignment to an Object &lt;br&gt;
→ Manipulate Value given through &lt;code&gt;date&lt;/code&gt; Parameter into a String&lt;br&gt;
Consisting of &lt;code&gt;Date:&lt;/code&gt; followed by the Value&lt;br&gt;
→ &amp;amp; Assign it to the &lt;code&gt;date&lt;/code&gt; property of Object created&lt;/p&gt;
&lt;h6&gt;
  
  
  Purpose
&lt;/h6&gt;

&lt;p&gt;= Need to manipulate user-given Values &lt;br&gt;
→ Into a suitable/consistent format &lt;br&gt;
Before saving it to an Object&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date) {
    Object.defineProperty(this, ‘date’, {
        get: function() {
            return ‘Event: ‘ + date;
        },
        set: function(newDate) {
            date = newDate;
        },
        configurable: false
});
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Accessor Properties
&lt;/h4&gt;

&lt;p&gt;= Do not contain any Properties or Methods&lt;br&gt;
→ Create a Getter to call when Property is read &lt;br&gt;
Expected to return a Value &lt;br&gt;
→ Create a Setter to call when Property is written to &lt;br&gt;
Receives Value assigned at Getter as an Argument&lt;/p&gt;

&lt;p&gt;= Entire Constructors: Containing &lt;code&gt;Object.defineProperty()&lt;/code&gt; Method &lt;br&gt;
→ Returns an Instance whose &lt;code&gt;date&lt;/code&gt; property can be set or changed in &lt;code&gt;Object.defineProperty()&lt;/code&gt; Method&lt;br&gt;
→ But cannot be deleted&lt;/p&gt;
&lt;h5&gt;
  
  
  Above Example
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;After receiving the value of &lt;code&gt;date&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Getter adds &lt;code&gt;Date:&lt;/code&gt; to beginning of the Value &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns that &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Object.defineProperty&lt;/code&gt; creates these accessor properties&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Purpose of Calling Constructor
&lt;/h4&gt;

&lt;p&gt;= So that JavaScript can perform these 4 Tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new Object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set &lt;code&gt;constructor&lt;/code&gt; Property of the Object that is the Variable the Constructor is assigned to &lt;br&gt;
= This Property is different from Standard Properties&lt;br&gt;
→ Because it will not be listed &lt;br&gt;
→ And it cannot be overwritten &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Underlying &lt;code&gt;constructor&lt;/code&gt; property&lt;br&gt;
= Something that cannot be set manually &lt;br&gt;
→ Can only be set up by JavaScript when &lt;code&gt;new&lt;/code&gt; keyword is used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Object is created to delete &lt;code&gt;Event.prototype&lt;/code&gt; in the above example&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript calls Event()&lt;br&gt;
= In the Context of the new Object&lt;br&gt;
→ Result of &lt;code&gt;new Event&lt;/code&gt;: Is the new Object &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  How to Call a Constructor
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an Instance of it&lt;br&gt;
= Using the &lt;code&gt;new&lt;/code&gt; keyword &lt;br&gt;
→ And assigning it to a Variable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constructor assigns given Arguments to Parameters indicated in Initial Definition &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then Constructor assigns given Arguments to the relevant Properties&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event() {

}

var myEvent = new Event();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  When to use a Constructor
&lt;/h4&gt;

&lt;p&gt;= Creating various similar Objects &lt;br&gt;
→ With same Properties &amp;amp; Methods&lt;/p&gt;
&lt;h5&gt;
  
  
  Example Use Case
&lt;/h5&gt;

&lt;p&gt;= Creating an Event&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If Function exists&lt;/em&gt;&lt;br&gt;
= All need to do is use a &lt;code&gt;new&lt;/code&gt; statement &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If the &lt;code&gt;new&lt;/code&gt; Keyword is not used&lt;/em&gt;&lt;br&gt;
= Alteration of Global Object will occur&lt;br&gt;
→ Instead of the newly created one&lt;/p&gt;

&lt;p&gt;&lt;em&gt;W/o &lt;code&gt;new&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
= Calling a Function w/o a Return Statement &lt;br&gt;
→ &lt;code&gt;this&lt;/code&gt; in the Constructor points to &lt;code&gt;Window&lt;/code&gt;&lt;br&gt;
→ Instead of &lt;code&gt;flat8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thus, &lt;em&gt;2 Global Variables&lt;/em&gt; are created&lt;br&gt;
W/ &lt;code&gt;new&lt;/code&gt;&lt;br&gt;
= Context is switched from Global (&lt;code&gt;Window&lt;/code&gt;)&lt;br&gt;
→ To Instance correctly pointing to &lt;code&gt;flat8&lt;/code&gt;&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var flat8  = new Event(‘September 18th, 2022’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;new&lt;/code&gt; not used &amp;amp; in Strict Mode
&lt;/h5&gt;

&lt;p&gt;= Code would throw an Error &lt;br&gt;
→ B/c Strict Mode designed to protect from accidental calls of a Constructor w/o the &lt;code&gt;new&lt;/code&gt; keyword&lt;/p&gt;
&lt;h4&gt;
  
  
  Check if Object is Instance
&lt;/h4&gt;

&lt;p&gt;= There are 2 ways to see if an Object is an Instance of another:&lt;/p&gt;
&lt;h5&gt;
  
  
  1st Way: &lt;code&gt;instanceof&lt;/code&gt; Operator
&lt;/h5&gt;

&lt;p&gt;= Right side of the operator must be a function&lt;br&gt;
→ Even if the &lt;code&gt;prototype.constructor&lt;/code&gt; is reassigned, and the &lt;code&gt;constructor&lt;/code&gt; is lost&lt;br&gt;
→ &lt;code&gt;instanceof&lt;/code&gt; operator will still have the accurate information&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;

&lt;p&gt;Check a new Event has been created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flat-8 instanceof Event
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= This will return &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  2nd Way: &lt;code&gt;constructor&lt;/code&gt; Property
&lt;/h5&gt;

&lt;p&gt;= &lt;code&gt;constructor&lt;/code&gt; property of any object&lt;br&gt;
→ Will point to the constructor function that created it&lt;br&gt;
→ This property is inherited from its prototype&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myEvent.constructor === Event;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Returns &lt;code&gt;true&lt;/code&gt; if &lt;code&gt;myEvent&lt;/code&gt; is an instance of &lt;code&gt;Event&lt;/code&gt;&lt;/p&gt;
&lt;h6&gt;
  
  
  Warning
&lt;/h6&gt;

&lt;p&gt;= Using the &lt;code&gt;constructor&lt;/code&gt; property to check the type of an instance &lt;br&gt;
→ It can be overwritten: So it is bad practice&lt;/p&gt;
&lt;h4&gt;
  
  
  Constructor vs Function Creation
&lt;/h4&gt;

&lt;p&gt;= When writing a Constructor&lt;br&gt;
→ You should use it like a Constructor &lt;/p&gt;

&lt;p&gt;= When writing a Function &lt;br&gt;
→ You should use it like a Function &lt;/p&gt;
&lt;h4&gt;
  
  
  Call as Function w/o &lt;code&gt;new&lt;/code&gt;
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;

&lt;p&gt;= Call &lt;code&gt;Event&lt;/code&gt; as a Function w/o using &lt;code&gt;new&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Event(‘September 18th, 2022’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Returns &lt;code&gt;undefined&lt;/code&gt;&lt;br&gt;
→ Creates a &lt;code&gt;date&lt;/code&gt; global variable&lt;br&gt;
Overriding existing &lt;code&gt;date&lt;/code&gt; variable&lt;br&gt;
→ Not what we want&lt;/p&gt;
&lt;h4&gt;
  
  
  Call Function as Function w/o &lt;code&gt;new&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;this&lt;/code&gt; is set to the Global Object &lt;br&gt;
→ Which is the &lt;code&gt;Window&lt;/code&gt; object&lt;br&gt;
→ Which is the Browser&lt;/p&gt;
&lt;h4&gt;
  
  
  Polluting Namespace
&lt;/h4&gt;

&lt;p&gt;= You should prevent pollution of the namespace&lt;br&gt;
→ This is done by not creating Global Variables&lt;/p&gt;

&lt;p&gt;= Confirm if &lt;code&gt;this&lt;/code&gt; is an &lt;code&gt;Event&lt;/code&gt;&lt;br&gt;
→ And if it is not, use &lt;code&gt;new&lt;/code&gt; to create an &lt;code&gt;Event&lt;/code&gt;&lt;br&gt;
→ And return it&lt;/p&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date) {
    if(!(this instanceof Person))
        return new Event(date)
    this.date = date
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Benefit of Constructor Usage
&lt;/h4&gt;

&lt;p&gt;= To create Methods (instead of creating one big object)&lt;/p&gt;

&lt;p&gt;→ Inheritance&lt;/p&gt;
&lt;h5&gt;
  
  
  Inheritance in JavaScript
&lt;/h5&gt;

&lt;p&gt;= Inheritance in JS is different to inheritance in traditional Object-oriented languages &lt;br&gt;
→ Bc it uses Prototype Inheritance&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 3 Prototype
&lt;/h3&gt;
&lt;h4&gt;
  
  
  What is the &lt;code&gt;prototype&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;Here are a few definitions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A Property &lt;br&gt;
= That all Functions automatically get &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An Empty Object&lt;br&gt;
= Receives some special treatment&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Object created through Constructor
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creates its own &lt;code&gt;prototype&lt;/code&gt; Object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Own &lt;code&gt;prototype&lt;/code&gt; Object inherits all Properties of its Constructor’s &lt;code&gt;prototype&lt;/code&gt;&lt;br&gt;
= Constructor’s &lt;code&gt;prototype&lt;/code&gt; Object is the Parent of its own &lt;code&gt;prototype&lt;/code&gt; Object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any Properties set on own &lt;code&gt;prototype&lt;/code&gt; Object &lt;br&gt;
= Can override inherited Properties from Constructor’s &lt;code&gt;prototype&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  New Property
&lt;/h5&gt;

&lt;p&gt;= Setting a New Property to &lt;code&gt;prototype&lt;/code&gt; Object on the Constructor &lt;br&gt;
→ Will be passed down to any Objects created by Constructor&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Event.prototype.totalLength = 4;
flat8.totalLength; //This will output 4 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Properties created on &lt;code&gt;prototype&lt;/code&gt;
&lt;/h5&gt;

&lt;p&gt;= Passed down to Instances &lt;br&gt;
→ But can always be overridden on the Instance itself&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flat8.totalLength = 10;
flat8.totalLength; //Now this will output 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Prototype Inheritance
&lt;/h4&gt;

&lt;p&gt;= In place of Classes, JS uses the &lt;code&gt;prototype&lt;/code&gt;&lt;br&gt;
→ Allows Inheritance to happen&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If Object has many of Properties&lt;/em&gt;&lt;br&gt;
= And a Special Parent Property called the &lt;code&gt;prototype&lt;/code&gt; of the Object&lt;br&gt;
→ JS Objects inherit all Properties of its Parent &lt;br&gt;
→ These Properties can be overridden by setting the Property on itself&lt;/p&gt;
&lt;h4&gt;
  
  
  Define Methods on Objects
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Most Memory Efficient
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Declare methods on the &lt;code&gt;prototype&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensuring only 1 &lt;code&gt;displayEvent&lt;/code&gt; is ever created &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And it is shared between all the Events created&lt;br&gt;
= Done by making &lt;code&gt;Event.prototype&lt;/code&gt; their parent&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Event(date){
    this.date = date
}
Event.prototype.displayEvent = function(){
    return ‘This event is on ‘ + this.date
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Define Instance Methods
&lt;/h4&gt;

&lt;p&gt;= Defining Methods that can be used from all Instances of a Constructor &lt;br&gt;
→ Done on Constructor’s Prototype Property&lt;/p&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Event.prototype = {
    display: function display() {
        return “This is the event!”;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;apply&lt;/code&gt; Method
&lt;/h4&gt;

&lt;p&gt;= Belongs to &lt;code&gt;Function.prototype&lt;/code&gt;&lt;br&gt;
→ Can be used to call a Function while binding it to an Object&lt;br&gt;
→ Works even if the Function is not connected to the Object, and if the Object is a different type&lt;/p&gt;

&lt;p&gt;Can you bind a Function to an Object yourself?&lt;br&gt;
= Yes&lt;br&gt;
→ Can also include Parameters by passing them as an Array as the 2nd parameter of the &lt;code&gt;apply()&lt;/code&gt; Method&lt;/p&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function displayEvent(other){
    return ‘This event is on ‘ + this.date + ‘and on’ + other.date
}

displayEvent.apply(flat8, [flat9]) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;apply&lt;/code&gt; Use Cases
&lt;/h5&gt;
&lt;h6&gt;
  
  
  1. Calling a Function w/ a List of Arguments
&lt;/h6&gt;

&lt;p&gt;= That is a Dynamic List&lt;br&gt;
ie &lt;code&gt;Math.max(4, 1, 8, 9, 2)&lt;/code&gt;&lt;br&gt;
→ Use &lt;code&gt;Math.max&lt;/code&gt; on an arbitrary array (instead of a statically set one)&lt;br&gt;
Use &lt;code&gt;Math.max.apply(Math, myarray)&lt;/code&gt;&lt;/p&gt;
&lt;h6&gt;
  
  
  2. Calling it as a Constructor
&lt;/h6&gt;

&lt;p&gt;= Rather than calling it as a function &lt;br&gt;
→ Create a &lt;code&gt;new&lt;/code&gt; Method of &lt;code&gt;Function.prototype&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function.prototype.new = function() {
    var args = arguments
    var constructor = this
    function Fake(){
        constructor.apply(this, args)
}
Fake.prototype = constructor.prototype
return new Fake
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= &lt;code&gt;new&lt;/code&gt; method inside &lt;code&gt;Function.prototype&lt;/code&gt;&lt;br&gt;
→ Can call constructors with the &lt;code&gt;new&lt;/code&gt; method&lt;br&gt;
→ Will have feel of calling a constructor&lt;br&gt;
Without actually using a constructor&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Usage&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var nextWeek = [new Event(‘September 24th, 2022’), new Event(‘September 29th, 2022’)]
var args = [‘September 20th, 2022’].concat(nextWeek)
var allEvents = Event.new.apply(Event, args)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Simplify even further, create a Helper Method&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Helper Method&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function.prototype.applyNew = function(){
    return this.new.apply(this, arguments)
}

var allEvents = Event.applyNew(args)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;call&lt;/code&gt; Function
&lt;/h4&gt;

&lt;p&gt;= Another Method of &lt;code&gt;Function.prototype&lt;/code&gt;&lt;br&gt;
→ Works like &lt;code&gt;apply()&lt;/code&gt;&lt;br&gt;
→ Passes parameters differently&lt;br&gt;
Instead of as an array in the 2nd parameter&lt;br&gt;
They are added to the end&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;displayEvent.call(flat8, flat9)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Subclass Creation: 1st Way
&lt;/h4&gt;

&lt;p&gt;= Set &lt;code&gt;prototype&lt;/code&gt; of subclass to an Instance of superclass&lt;br&gt;
→ ‘subclass’ only called once&lt;br&gt;
→ Cannot customize ‘subclass’ on different calls of ‘superclass’&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var Event = function Event() {};
Event.prototype = new Venue(“Shoreditch”);
Event.prototype.displayVenue = function displayVenue() { return “Venue Submitted” };
var flat8 = new Event();
flat8 instanceof Event; // Outputs true
flat8 instanceof Venue; // Outputs true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Inheritance w/o Power to Override
&lt;/h4&gt;

&lt;p&gt;= In most prototype-based languages&lt;br&gt;
→ There is inheritance without power to override &lt;br&gt;
→ However, JavaScript does not work like this &lt;/p&gt;

&lt;p&gt;Here’s a way to do it:&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function create(parent) {
    var F = function() {};
    F.prototype = parent;
    return new F();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Static Methods &amp;amp; Properties
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;static&lt;/code&gt; keyword&lt;br&gt;
→ Defines a static method or property for a class&lt;/p&gt;

&lt;p&gt;= Called w/o creating an instance of the class&lt;br&gt;
→ Cannot be called through a class instance&lt;/p&gt;

&lt;h5&gt;
  
  
  Static methods
&lt;/h5&gt;

&lt;p&gt;= Used to create utility functions for an application&lt;/p&gt;

&lt;h5&gt;
  
  
  Static Properties
&lt;/h5&gt;

&lt;p&gt;= Used for caches, fixed-configuration&lt;br&gt;
→ Or any other data you do not need to be replicated across instances &lt;br&gt;
Unlike &lt;code&gt;prototype&lt;/code&gt; methods and properties which will appear on individual instances&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    constructor(date, time) {
        this.date = date;
        this.time = time;
}

    static displayName = “September Events”;
    static timeframe(a, b) {
        const tdate = a.date - b.date;
        const ttime = a.time - b.time;

return Math.hypot(tdate, ttime); 
    }
}

const flat8 = new Event(123, 2);
const flat9 = new Event(432, 5);

flat8.displayName; //Outputs undefined
flat9.displayName; //Outputs undefined

flat8.timeframe; //Outputs undefined 
flat9.timeframe; //Outputs undefined

console.log(Event.displayName); //Outputs “September Events”;
console.log(Event.timeframe); //Outputs …
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Bind &lt;code&gt;this&lt;/code&gt; w/ Prototype &amp;amp; Static Methods
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Value for &lt;code&gt;this&lt;/code&gt; &lt;br&gt;
= Must be included when calling a static or prototype method&lt;br&gt;
→ Or else the &lt;code&gt;this&lt;/code&gt; value will be &lt;code&gt;undefined&lt;/code&gt; inside the method&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Body is always executed in strict mode&lt;br&gt;
= So this will occur regardless of whether or not the &lt;code&gt;“use strict”&lt;/code&gt; directive is present&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Calling Static &amp;amp; Property Methods
&lt;/h5&gt;

&lt;p&gt;= Static &amp;amp; Property Methods cannot be called on their own &lt;br&gt;
→ Must be called as a Property of another Object&lt;/p&gt;

&lt;h4&gt;
  
  
  Instance Properties
&lt;/h4&gt;

&lt;p&gt;= Must be defined inside Class Methods&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    constructor(date, time) {
        this.date = date;
        this.time = time;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Field Declarations
&lt;/h4&gt;

&lt;p&gt;= 2 Different Types of Field Declarations:&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Public
&lt;/h5&gt;

&lt;p&gt;= Do not need to be made w/ Keyword like &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;&lt;br&gt;
→ Allow Class Definitions to become more self-documenting &lt;br&gt;
→ Fields will always be there &lt;br&gt;
= Can be declared w/ or w/o a Default Value&lt;/p&gt;

&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    date = “”;
    time = “”;
    constructor (date, time) {
        this.date = date;
        this.time = time;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  2. Private
&lt;/h5&gt;

&lt;p&gt;= Cannot be referenced from outside of the Class&lt;br&gt;
→ Can only be read or written w/in Class body&lt;/p&gt;

&lt;h6&gt;
  
  
  Benefit of Private Field Declarations
&lt;/h6&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use of Field Declarations not visible outside of Class &lt;br&gt;
= Ensures Classes’ users cannot depend on&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intervals (which may change version to version)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can only be declared upfront in a Field Declaration&lt;br&gt;
= Cannot be created later through assigning them the way normal properties can&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    #date = “”;
    #time;
    constructor(date, time) {
        this.#date = date;
        this.
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Subclass Creation: 2nd Way
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;extends&lt;/code&gt; is used in Class Declarations or Class Expressions&lt;br&gt;
→ For sake of creating a Class as a child of another Class&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Constructor in Subclass&lt;/em&gt;&lt;br&gt;
= Constructor must first call &lt;code&gt;super()&lt;/code&gt; before using &lt;code&gt;this&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Traditional Function-based “Classes”&lt;/em&gt;&lt;br&gt;
= Can also be extended&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Subclass &amp;amp; Superclass both have same method&lt;/em&gt;&lt;br&gt;
= Subclass’ method overrides Superclass’&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    constructor(date) {
        this.date = date;
    }

    display() {
        console.log(`${this.date} is the date of the event.`);  
    }
}

class smallEvent extends Event {
    constructor(date) {
        super(date);
    }

    speak() {
        console.log(`${this.date} is the date of a small event.`);
    }
}

const houseWarming = new smallEvent(‘September 22nd, 2022’);
houseWarming.display(); // Output: September 22nd, 2022 is the date of a small event.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Inappropriate Use Case
&lt;/h5&gt;

&lt;p&gt;= Classes cannot extend regular (non-constructible) Objects &lt;br&gt;
→ They must extend another Class&lt;/p&gt;

&lt;h4&gt;
  
  
  Regular Object Inheritance
&lt;/h4&gt;

&lt;p&gt;= For a Class to inherit Methods &amp;amp; Properties from a Regular Object&lt;br&gt;
→ Instead of another Class &lt;br&gt;
Use &lt;code&gt;Object.setPrototypeOf&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Event = {
    display() {
        console.log(`${this.date} is the date of the event.`);
    }
};

class smallEvent = {
    constructor(date) {
        this.date = date;
}
}

Object.setPrototypeOf(smallEvent.prototype, Event);

const houseWarming = new smallEvent(‘September 22nd, 2022’);
houseWarming.display(); //Output: September 22nd, 2022 is the date of the event.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Species Pattern
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Allows creation of Objects which are Instances of Superclass that a Subclass extends&lt;br&gt;
= Instead of creating Objects that are Instances of the Subclass&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constructor of Objects created by the Subclass&lt;br&gt;
= Overridden &amp;amp; Set to the Superclass&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can create Instances of Superclass that contain more Methods &amp;amp; Properties&lt;br&gt;
= On top of ones defined in original Class Creation &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyArray extends Array {
static get [Symbol.species] () {
    return Array; // This overwrites the Object Constructor and sets it to Array instead of MyArray
}
}
const a = new MyArray(1, 2, 3);
//This allows a to access the default Constructors set at Array

const mapped = a.map((x) =&amp;gt; x * x);

//Because a.map() uses a method defined in Array rather than MyArray, the variable called mapped will be an instance of Array rather than MyArray

console.log(mapped instanceof MyArray); //Output: false
console.log(mapped instanceof Array); //Output: true 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;super&lt;/code&gt; vs Prototype-based Inheritance
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Advantage of &lt;code&gt;super&lt;/code&gt;
&lt;/h5&gt;

&lt;p&gt;= Ability to call Superclass Methods w/in Subclass&lt;/p&gt;

&lt;h6&gt;
  
  
  Make Superclass calls w/ &lt;code&gt;super&lt;/code&gt;
&lt;/h6&gt;

&lt;p&gt;= Call Methods of Superclass w/in a Method being defined in a Subclass&lt;br&gt;
→ Using &lt;code&gt;super&lt;/code&gt; keyword &lt;/p&gt;

&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Event {
    constructor(date) {
        this.date = date;
    }

    display() {
        console.log(`${date} is the date of the event.`);
}
}

class smallEvent extends Event {
    display() {
        super.display();
        console.log(`${this.date} is a good time for a small event.`);
    }
    //Since a method with the same name in the subclass overrides the one defined in the superclass, object created with the subclass will have a method called display() which has additional utility to the objects created with the superclass
}

const houseWarming = new smallEvent(‘September 22nd, 2022’);
houseWarming.display();
//September 22, 2022 is the date of the event.
//September 22, 22 is a good time for a small event.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What are Mixins?
&lt;/h4&gt;

&lt;p&gt;Here are a few definitions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A Class that includes Methods &lt;br&gt;
= That can be used by &lt;em&gt;other&lt;/em&gt; Classes&lt;br&gt;
→ W/o need to be Parent Class of those Classes using its Methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Abstract Subclasses &lt;br&gt;
= Which are Templates for Classes &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Rule for Mixins&lt;/em&gt;&lt;br&gt;
= Each Subclass can only have &lt;em&gt;1&lt;/em&gt; Superclass &lt;br&gt;
→ Multiple inheritance from Tooling Classes is not possible&lt;br&gt;
→ Functionality that needs to be inherited must be provided by 1 Superclass&lt;/p&gt;

&lt;h5&gt;
  
  
  Using Mix-ins
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a Function w/ a Superclass as Input &lt;br&gt;
= &amp;amp; a Subclass extending that Superclass as Output &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One Class must accept another Class as an Argument&lt;br&gt;
= This Class must also be accepted as an Argument of another Class&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Examples of Mix-ins
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const calculatorMixin = (Base) =&amp;gt; class extends Base {
    calc() {}
};

const randomizerMixin = (Base) =&amp;gt; class extends Base {
    randomize() {}
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Example Class using Mix-in
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo {}
class Bar extends calculatorMixin(randomizerMixin(Foo)) {}
// Base is in the end set as Base { randomize() {} }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Resources for Further Exploration:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://tobyho.com/2010/11/22/javascript-constructors-and/"&gt;Javascript Constructors and Prototypes By Toby Ho&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/understanding-javascript-constructors/"&gt;Understanding JavaScript Constructors By Faraz Kelhini&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#static_methods_and_properties"&gt;MDN Web Docs: Classes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor"&gt;MDN Web Docs: Object.prototype.constructor&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tanzu.vmware.com/content/blog/javascript-constructors-prototypes-and-the-new-keyword"&gt;VMWare: JavaScript constructors, prototypes, and the &lt;code&gt;new&lt;/code&gt; keyword&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Functions - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Wed, 26 Oct 2022 13:56:20 +0000</pubDate>
      <link>https://forem.com/angelinewang/functions-javascript-core-concepts-l1p</link>
      <guid>https://forem.com/angelinewang/functions-javascript-core-concepts-l1p</guid>
      <description>&lt;p&gt;The Functions &amp;amp; Methods Section of my JavaScript Core Concepts Series is divided into 6 Parts:&lt;/p&gt;

&lt;p&gt;Part 1 Functions&lt;br&gt;
Part 2 Classes&lt;br&gt;
Part 3 Methods&lt;br&gt;
Part 4 Callback Methods&lt;br&gt;
Part 5 Scope &lt;br&gt;
Part 6 Hoisting&lt;/p&gt;
&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Part 1 What is a Function?
&lt;/h3&gt;

&lt;p&gt;Here are a few definitions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Block of code &lt;br&gt;
= Performs an action or returns a value &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom code&lt;br&gt;
= Defined by programmers and are reusable &lt;br&gt;
→ Can make programs more modular &amp;amp; efficient &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 2 Function Definition
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Option 1: &lt;code&gt;function&lt;/code&gt; keyword
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Code Example
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newEvent() {
    console.log(‘New event created!’)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Begins with &lt;code&gt;function&lt;/code&gt; keyword&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Followed by name of function &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function names follow same rules as variables &lt;br&gt;
= Can contain letters, numbers, underscores and dollar signs&lt;br&gt;
→ Frequently written in camel case&lt;br&gt;
→ Name is followed by a set of parentheses: Which can be used for optional parameters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code of function &lt;br&gt;
= Contained in curly brackets&lt;br&gt;
→ Like a for statement or an if statement&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nothing will happen&lt;br&gt;
= No code will execute&lt;br&gt;
→ Until the function is invoked/called&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Option 2: Function Expressions
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Creation
&lt;/h5&gt;

&lt;p&gt;= Assign a Function to a Variable&lt;/p&gt;
&lt;h6&gt;
  
  
  Code Example
&lt;/h6&gt;

&lt;p&gt;= Using &lt;code&gt;add&lt;/code&gt; example above&lt;br&gt;
→ Directly apply returned value to a variable (&lt;code&gt;sum&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sum = function add(x, y) {
    return x + y;
}

// Invoked function to find the sum
sum(20, 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Output: 25&lt;br&gt;
→ &lt;code&gt;sum&lt;/code&gt; Constant Variable is a Function &lt;/p&gt;
&lt;h6&gt;
  
  
  Adding Concision
&lt;/h6&gt;

&lt;p&gt;= Turn it into an Anonymous Function (aka Unnamed Function)&lt;br&gt;
→ Currently, function name is &lt;code&gt;add&lt;/code&gt;&lt;br&gt;
→ But with Function Expressions, it is not needed to name the Function&lt;/p&gt;

&lt;p&gt;So the Name is usually omitted like below: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sum = function(x, y) {
    return x + y;
}

//Invoke function to find the sum
sum(100, 3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Name of function: &lt;code&gt;add&lt;/code&gt; is removed&lt;br&gt;
→ Turned it into an anonymous function&lt;/p&gt;
&lt;h6&gt;
  
  
  Preserving Function Name
&lt;/h6&gt;

&lt;p&gt;= Could be used to help debugging &lt;br&gt;
→ However, the Name is usually omitted&lt;/p&gt;
&lt;h4&gt;
  
  
  Option 3: Arrow Functions
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Purpose
&lt;/h5&gt;

&lt;p&gt;= Newer, more concise method to define a function as of ECMAScript 6&lt;br&gt;
→ Represented by an Equals Sign, followed by a greater than sign: &lt;code&gt;=&amp;gt;&lt;/code&gt;&lt;br&gt;
= Always anonymous functions &lt;br&gt;
→ They are a type of function expression &lt;/p&gt;
&lt;h5&gt;
  
  
  Basic Example
&lt;/h5&gt;

&lt;p&gt;= Find product of 2 numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const multiply = (x, y) =&amp;gt; {
    return x * y;
}

// Invoke function to find product
multiply(30, 4);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Instead of writing out the keyword &lt;code&gt;function&lt;/code&gt;&lt;br&gt;
→ Used &lt;code&gt;=&amp;gt;&lt;/code&gt; arrow: Indicate a function &lt;br&gt;
= Otherwise, it works similarly to a regular function expression&lt;br&gt;
→ With some advanced differences &lt;/p&gt;
&lt;h5&gt;
  
  
  Benefits
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Concise Syntax&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implicit Returns &lt;br&gt;
= Allows us to write one-liners &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No rebinding the value of &lt;code&gt;this&lt;/code&gt; when you use an Arrow Function inside another Function &lt;br&gt;
= Helpful for doing things like click handlers etc. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Application
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Transformation to Arrow Function
&lt;/h6&gt;

&lt;p&gt;= Turn into an Arrow Function &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Delete keyword &lt;code&gt;function&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add a fat arrow: &lt;code&gt;=&amp;gt;&lt;/code&gt;&lt;br&gt;
= Which does the same thing as &lt;code&gt;function&lt;/code&gt;&lt;br&gt;
→ And when &lt;code&gt;console.log&lt;/code&gt;ged, you get the same thing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove parentheses if you only have 1 parameter&lt;br&gt;
= Though you can keep the parenthesis as a stylistic choice&lt;br&gt;
→ Example: In callback functions ie map function it’s nice to leave them out for clean syntax&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h6&gt;
  
  
  1 Parameter
&lt;/h6&gt;

&lt;p&gt;= Parentheses can be excluded&lt;br&gt;
Example: Squaring &lt;code&gt;x&lt;/code&gt;, which only requires 1 number to be passed as an argument&lt;/p&gt;

&lt;p&gt;= Parentheses have been omitted:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const square = x =&amp;gt; {
    return x * x;
}   

square(8);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Output: 64&lt;br&gt;
→ These example only contain a &lt;code&gt;return&lt;/code&gt; statement&lt;br&gt;
→ Thus: Arrow functions allow syntax to be reduced even further &lt;/p&gt;
&lt;h6&gt;
  
  
  Single-line &lt;code&gt;return&lt;/code&gt;
&lt;/h6&gt;

&lt;p&gt;If function is only a single line &lt;code&gt;return&lt;/code&gt;:&lt;br&gt;
= Both curly brackets and &lt;code&gt;return&lt;/code&gt; statement can be omitted&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

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

square(10);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Output: 100&lt;/p&gt;

&lt;h6&gt;
  
  
  No Parameter/Argument
&lt;/h6&gt;

&lt;p&gt;= An empty set of parentheses is still required in the arrow functions&lt;br&gt;
→ Could also use an underscore &lt;code&gt;_&lt;/code&gt; in the place of &lt;code&gt;()&lt;/code&gt;&lt;br&gt;
→ Underscore = Throwaway variable: B/c we’re actually creating a variable called &lt;code&gt;_&lt;/code&gt; but not using it &lt;br&gt;
→ &lt;code&gt;_&lt;/code&gt; does not have any significance at all&lt;/p&gt;

&lt;p&gt;= Any variable name can be used &lt;br&gt;
→ Just thrown away (because there’s no parenthese around it)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;names.map(_ =&amp;gt; `Angeline Wang`);
names.map(x =&amp;gt; `Angeline Wang`);
names.map(boo_yaa =&amp;gt; `Angeline Wang`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= You can do this however you want &lt;/p&gt;

&lt;h5&gt;
  
  
  Return
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Implicit vs Explicit
&lt;/h6&gt;

&lt;p&gt;&lt;em&gt;Implicit Return&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Many callback functions written in JS are just one liners&lt;br&gt;
= Where we just return something immediately in one line&lt;br&gt;
→ Don’t need a whole bunch of lines&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only purpose of arrow function is to return something &lt;br&gt;
= No need for &lt;code&gt;return&lt;/code&gt; keyword &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Implicit Return in Arrow Functions&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Delete the &lt;code&gt;return&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Put it up on all of one line&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete the curly brackets &lt;br&gt;
= Going to be an implicit return &lt;br&gt;
→ Means we do not need to specify what we are returning&lt;br&gt;
→ Will be assumed that we are doing so&lt;br&gt;
→ &lt;code&gt;console.log&lt;/code&gt; will see the same thing again &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Explicit Return&lt;/em&gt;&lt;br&gt;
= Explicitly write &lt;code&gt;return&lt;/code&gt; for what you want to return &lt;/p&gt;
&lt;h5&gt;
  
  
  Named vs Anonymous Function
&lt;/h5&gt;
&lt;h6&gt;
  
  
  Named Function
&lt;/h6&gt;

&lt;p&gt;= Function has a Name attached to it&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Named Example&lt;/em&gt;&lt;br&gt;
This is what a Named Function looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sayMyName(name) {
    alert(`Hello ${name}`);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Benefits of Naming Functions&lt;/em&gt;&lt;br&gt;
= In the case of a Stack trace: When you have an Error&lt;br&gt;
→ To figure out where something has gone wrong&lt;/p&gt;

&lt;p&gt;= Line num may not be very helpful &lt;br&gt;
→ Need to know actually the name of the function it got called in &lt;/p&gt;
&lt;h6&gt;
  
  
  Arrow Function Anonymity
&lt;/h6&gt;

&lt;p&gt;But, if an Arrow Function is used &lt;br&gt;
= You cannot name them &lt;br&gt;
→ None of arrow functions have a name&lt;br&gt;
→ Arrow Functions are always Anonymous Functions&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt;&lt;br&gt;
= Can put an arrow function inside a variable &lt;br&gt;
→ This means that you would be passing the arrow function a name and creating a function declaration that way &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sayMyName = (name) =&amp;gt; {alert(`Hello ${name}!`)}

sayMyName(‘Angeline Wang’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= This is still an anonymous function &amp;amp; it will not give us very good stack traces&lt;br&gt;
→ But if you’re not concerned about stack traces: you can do this&lt;/p&gt;
&lt;h4&gt;
  
  
  Which Option to Choose
&lt;/h4&gt;

&lt;p&gt;= The 3 different types of syntax result in the same output&lt;br&gt;
→ Which to use depends on preference/Company coding standards to decide how you’ll structure own functions&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 3 Function Invocation
&lt;/h3&gt;
&lt;h4&gt;
  
  
  How to Call a Function
&lt;/h4&gt;

&lt;p&gt;= Write name of function followed by parentheses &lt;br&gt;
→ And can be reused as many times as you want&lt;/p&gt;
&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;


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

&lt;/div&gt;


&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 4 Function Parameters
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Definition
&lt;/h4&gt;

&lt;p&gt;= Input that gets passed into functions as names and behave as local variables &lt;/p&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make code more dynamic by creating dynamic functions &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add additional functionality &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make code more flexible &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;

&lt;p&gt;Example: Add date of event&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newEvent(date) {
    console.log(`New event on ${date}!`);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Name of function is newEvents &lt;br&gt;
→ Now have single parameter inside the parentheses &lt;br&gt;
→ Name of parameter follows same rules as naming a Variable&lt;/p&gt;
&lt;h4&gt;
  
  
  Use Parameter inside Function
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Example
&lt;/h5&gt;

&lt;p&gt;= To use parameters inside a string:&lt;br&gt;
→ Instead of a Static String: Add a Template Literal String&lt;br&gt;
Contains Parameter&lt;br&gt;
Not behaving as a Local Variable &lt;/p&gt;
&lt;h4&gt;
  
  
  Parameter Value Assignment
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If the parameter is not defined anywhere&lt;br&gt;
= A value can be assigned to it when invoking the function &lt;br&gt;
→ Value is placed w/in Parentheses of Function Call&lt;br&gt;
→ It is used as the Argument &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every time the parameter is used within the Function &lt;br&gt;
= The value passed during Function Call is used&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Real World Use Case
&lt;/h4&gt;

&lt;p&gt;= For example, the function would pull the username from a database instead of directly supplying the name as an argument value &lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 5 Declarations inside Functions
&lt;/h3&gt;

&lt;p&gt;= Variables can be declared inside functions &lt;br&gt;
→ Known as Local Variables&lt;br&gt;
They will only exist inside the scope of their own Function Block &lt;/p&gt;
&lt;h4&gt;
  
  
  Variable Scope
&lt;/h4&gt;

&lt;p&gt;= Determines variables’ accessibility &lt;br&gt;
→ ie Variables defined inside a Function: Not accessible outside function &lt;br&gt;
But can be used at the same time as the Function is used throughout the program  &lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 6 Return Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Amount of Parameters Allowed
&lt;/h4&gt;

&lt;p&gt;= &amp;gt; 1 Parameter can be used in a Function&lt;br&gt;
→ You can pass multiple values into a Function and Return a value&lt;/p&gt;
&lt;h4&gt;
  
  
  Code Example
&lt;/h4&gt;

&lt;p&gt;= Create function to find sum of 2 values&lt;br&gt;
→ Represented by &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize add function
function add(x, y) {
    return x + y;
}

// Invoke function to find the sum
add(9, 7);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Defined function with parameters x and y&lt;br&gt;
→ Then passed the values 9 and 7 to the function &lt;br&gt;
→ When we run the program, we’ll received sum of those numbers as the output&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;return&lt;/code&gt; Keyword
&lt;/h4&gt;

&lt;p&gt;= When the &lt;code&gt;return&lt;/code&gt; keyword is used &lt;br&gt;
→ The function stops executing:&lt;br&gt;
Value of the Expression is returned &lt;br&gt;
Output will be where the Function was invoked &lt;br&gt;
Value can be used straight away&lt;br&gt;
Or placed into a Variable&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h3&gt;
  
  
  Part 7 Pure Functions
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Definition
&lt;/h4&gt;

&lt;p&gt;It needs to pass 2 requirements:&lt;/p&gt;
&lt;h5&gt;
  
  
  1. Always returns same result
&lt;/h5&gt;

&lt;p&gt;= If same arguments are passed it &lt;br&gt;
→ Does not depend on any state, or data change during program execution&lt;br&gt;
= Must only depend on input arguments &lt;/p&gt;
&lt;h5&gt;
  
  
  2. Does not produce any observable side effects
&lt;/h5&gt;

&lt;p&gt;= ie Network requests, input and output devices, or data mutation &lt;/p&gt;
&lt;h4&gt;
  
  
  Observable Side Effects
&lt;/h4&gt;

&lt;p&gt;= Any interaction with outside world &lt;br&gt;
→ From within a function&lt;br&gt;
= Could be anything from changing a variable that exists outside the function &lt;br&gt;
→ To calling another method from within a function &lt;/p&gt;
&lt;h5&gt;
  
  
  Pure Function calling a Pure Function
&lt;/h5&gt;

&lt;p&gt;= Not a side effect&lt;br&gt;
→ And the calling function is still pure&lt;/p&gt;
&lt;h5&gt;
  
  
  Examples of side effects:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Making a HTTP request&lt;/li&gt;
&lt;li&gt;Mutating data&lt;/li&gt;
&lt;li&gt;Printing to a screen or console &lt;/li&gt;
&lt;li&gt;DOM Query/Manipulation&lt;/li&gt;
&lt;li&gt;Math.random()&lt;/li&gt;
&lt;li&gt;Getting the current time &lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Characteristics of Side effects:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Not bad in and of themselves &lt;/li&gt;
&lt;li&gt;They are often required&lt;/li&gt;
&lt;li&gt;But for a function to be called pure, it must not contain any &lt;/li&gt;
&lt;li&gt;Not all functions need to be, or should be, pure&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example of Pure Function
&lt;/h4&gt;

&lt;p&gt;= Calculating price of a product including tax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function priceAfterTax(productPrice) {
    return (productPrice * 0.20) + productPrice;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Passes 1 and 2 of the requirements for function to be pure:&lt;br&gt;
→ Does not depend on any external input&lt;br&gt;
→ Does not mutate any data &lt;br&gt;
→ Does not have any side effects &lt;/p&gt;

&lt;p&gt;= If you run this function with same input 100 million times&lt;br&gt;
→ It will always produce the same result&lt;/p&gt;

&lt;h4&gt;
  
  
  Example of Impure Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var tax = 20;

function calculateTax(productPrice) {
    return (producePrice * (tax/100)) + productPrice;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= This is impure because it depends on an external tax variable &lt;br&gt;
→ Pure functions cannot depend on outside variables &lt;br&gt;
→ This function fails one of the requirements, so it is impure &lt;/p&gt;

&lt;h4&gt;
  
  
  Use Cases
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Heavily used in Functional Programming &lt;br&gt;
= And libraries like ReactJS and Redux require use of pure functions &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Regular JS that does not depend on single programming paradigm &lt;br&gt;
= Can mix pure and impure functions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not all functions need to be or should be pure &lt;br&gt;
→ Example: Event handler for a button press that manipulates the DOM should not be pure&lt;br&gt;
→ Example: Event handler can call other pure functions which will reduce the number of impure functions in your app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing &amp;amp; Refactoring &lt;br&gt;
= Benefit of using pure functions: Immediately testable &lt;br&gt;
→ Always product same result if pass same arguments &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make maintaining &amp;amp; refactoring code easier&lt;br&gt;
= Can change pure function &amp;amp; not worry about unintended side effects altering the entire app &amp;amp; making debugging very difficult &lt;br&gt;
→ Better quality code, cleaner way of working&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pure functions are not limited to JavaScript&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Resources for Further Exploration:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-define-functions-in-javascript"&gt;How To Define Functions in JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@jamesjefferyuk/javascript-what-are-pure-functions-4d4d5392d49c"&gt;JavaScript: What Are Pure Functions And Why Use Them? By James Jeffery&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wesbos.com/arrow-functions"&gt;Wes Bos: JavaScript Arrow Functions Introduction&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Variables - JavaScript Core Concepts</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Tue, 27 Sep 2022 14:41:54 +0000</pubDate>
      <link>https://forem.com/angelinewang/javascript-core-concepts-part-1-data-types-variables-55pj</link>
      <guid>https://forem.com/angelinewang/javascript-core-concepts-part-1-data-types-variables-55pj</guid>
      <description>&lt;p&gt;&lt;strong&gt;"JavaScript Core Concepts"&lt;/strong&gt; is a 5-Section Series consisting of:&lt;/p&gt;

&lt;p&gt;Section 1 Data Types &amp;amp; Variables &lt;br&gt;
&lt;strong&gt;Part 1&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Variables&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Part 2 Primitive Data Types&lt;br&gt;
Part 3 Complex/Composite Data Types &lt;/p&gt;

&lt;p&gt;Section 2 Functions &amp;amp; Methods&lt;br&gt;
Section 3 Control Flow &amp;amp; Conditional Statements &lt;br&gt;
Section 4 Past, Present &amp;amp; Future &lt;br&gt;
Section 5 Data Structures &amp;amp; Algorithms&lt;/p&gt;

&lt;p&gt;The most important thing to learn about any new programming language is its Data Types &amp;amp; Variables. And that is what we are starting off with. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  JavaScript Variables
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the purpose of variables?
&lt;/h3&gt;

&lt;p&gt;JavaScript variables are used to hold data in memory, so that you can access and manipulate it later on. &lt;/p&gt;

&lt;h3&gt;
  
  
  How can you define variables?
&lt;/h3&gt;

&lt;p&gt;There are 3 ways of defining a JavaScript variable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt;&lt;br&gt;
This may or may not be reassigned, and may or may not be used for an entire function, or just for the purpose of a block or loop. This is the weakest method, which should not be used, but is still valid.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;let&lt;/code&gt;&lt;br&gt;
Used when you need to re-assign the variable later on, and is particularly useful in loops. It signals that the variable will only be used within the block that it’s defined in, and this may not always be the entire containing function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const&lt;/code&gt;&lt;br&gt;
Used when the variable does not need to be re-assigned later on, and means that the variable remains constant throughout the script/code block. This does not mean that it has immutable values, as an object can still have its properties mutated. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Which should you use?
&lt;/h3&gt;

&lt;p&gt;When in doubt, use &lt;code&gt;const&lt;/code&gt;, as this allows the usage to be as clear as possible. If later on, you realise that you need to modify the variable, you can always go back and change the definition to &lt;code&gt;let&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; tends to be used for loops or mathematical algorithms to take the place of one thing. This means that it is possible to deallocate the value by unsetting it. For example, it can be used for a counter in a loop or a value swap in an algorithm. &lt;/p&gt;

&lt;h3&gt;
  
  
  How does block scope interact with variables in JS?
&lt;/h3&gt;

&lt;p&gt;All code within curly braces {} is a code block. If a variable is created with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; inside a code block, it will not be available outside of the block. However, variables outside the block will be available inside the block.&lt;/p&gt;

&lt;p&gt;If a variable with the same name as one pre-existing in the global scope is created inside a code block and the variable is defined with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;, then it will be completely separate. If it is defined with &lt;code&gt;var&lt;/code&gt;, then it will override the global variable. &lt;/p&gt;

&lt;h3&gt;
  
  
  When should you define a new variable?
&lt;/h3&gt;

&lt;p&gt;One variable should be used to represent a single concept. It is important to be careful not store multiple values within one identifier. For example, to parse a query string parameter value, it is best to create one identifier for the URL, one for the query string, and another for the parameter value. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Resources for Further Exploration:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75"&gt;JavaScript ES6+: var, let, or const?&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mastering CSS Grid</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Thu, 04 Aug 2022 11:55:00 +0000</pubDate>
      <link>https://forem.com/angelinewang/mastering-css-grid-5ega</link>
      <guid>https://forem.com/angelinewang/mastering-css-grid-5ega</guid>
      <description>&lt;p&gt;Only created in 2011, CSS Grid is the new kid on the block who has enabled new layouts, and simplified old ones! &lt;/p&gt;

&lt;p&gt;(Cheeky updated version of this article now includes a few sidebars :))&lt;/p&gt;

&lt;p&gt;At its core, CSS Grid is used to divide a page into major regions by defining the relationship between elements in terms of size, position, and layer. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t70m9AUp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldurj7u5ougx1wk879yb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t70m9AUp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldurj7u5ougx1wk879yb.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This one I learned through &lt;a href="https://cssgridgarden.com/"&gt;Grid Garden&lt;/a&gt;, &amp;amp; later updated this article with content from &lt;a href="https://gridcritters.com/"&gt;Grid Critters&lt;/a&gt;...&lt;/p&gt;

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

&lt;h1&gt;
  
  
  Part 1 CSS Grid vs Other Options
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1.1 CSS Grid vs Flexbox
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grid Advantage&lt;/strong&gt;&lt;br&gt;
= Can easily position elements in 2 dimensions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Columns &lt;/li&gt;
&lt;li&gt;Rows&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  1.2 CSS Grid vs Tables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Similarities&lt;/strong&gt;&lt;br&gt;
= Allows you to align elements into columns &amp;amp; rows &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Differences&lt;/strong&gt;&lt;br&gt;
= More layouts are possible &amp;amp; easier w/ CSS Grid &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
= Grid container's child elements could position themselves so they overlap &amp;amp; layer (like CSS positioned elements)&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h1&gt;
  
  
  Part 2 Definitions
&lt;/h1&gt;
&lt;h2&gt;
  
  
  2.1 Grid
&lt;/h2&gt;

&lt;p&gt;= Always starts w/ a line &amp;amp; ends w/ a line &lt;br&gt;
→ Always has 1 more line than track &lt;/p&gt;
&lt;h2&gt;
  
  
  2.2 Tracks
&lt;/h2&gt;

&lt;p&gt;= General term for either Columns or Rows &lt;br&gt;
= A vertical/horizontal slice  of the Gird &lt;br&gt;
→ Can be sized &amp;amp; filled w/ Elements &lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h1&gt;
  
  
  Part 3 On the Container
&lt;/h1&gt;
&lt;h2&gt;
  
  
  3.1 Grid Layout
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Default
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Elements in Grid are equal heighted rows &lt;/li&gt;
&lt;li&gt;Grid always has at least 1 row and 1 column
3.&lt;code&gt;grid-template-rows: 1fr;&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;grid-template-columns: 1fr;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: 1fr 1fr 1fr 1fr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= 4 Column &lt;em&gt;Tracks&lt;/em&gt;, but 5 Column &lt;em&gt;Lines&lt;/em&gt;&lt;br&gt;
→ &lt;em&gt;line 1&lt;/em&gt; 1fr &lt;em&gt;line 2&lt;/em&gt; 1fr &lt;em&gt;line 3&lt;/em&gt; 1fr &lt;em&gt;line 4&lt;/em&gt; 1fr &lt;em&gt;line 5&lt;/em&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;To begin using CSS Grid, we must select the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; that is the container for all our elements, and apply the following CSS properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;display: grid;
grid-template-columns: ____;
grid-template-rows: ____;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Column/Row Sizing
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-template-columns/rows&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Set number of columns/rows&lt;/li&gt;
&lt;li&gt;Set size of each column/row
= Control how Grid element are sized &amp;amp; positioned&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Units of Measurement
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Application&lt;/strong&gt;&lt;br&gt;
= The following units of measurement for values can be used in combination &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;grid-template-columns: 100px 3em 40%;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;px&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. &lt;code&gt;em&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. &lt;code&gt;%&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Relative to height/width of Grid&lt;br&gt;
→ % of Grid Size&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#garden {
display: grid;
grid-template-columns: 20% 20% 20% 20% 20%;
grid-template-rows: 20% 20% 20% 20% 20%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Sets up a grid w/ 5 columns, each 20% of full width, &amp;amp; 5 rows, each 20% of full height&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;code&gt;fr&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= The Fractional/A Fraction of the Free Space&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Allocate 1 share of available space&lt;br&gt;
→ Divides up left over space after px, em, % allocated spaces are filled&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application&lt;/em&gt;&lt;br&gt;
= Tell tracks how much of available space to take up &lt;br&gt;
→ After any fixed-unit tracks get their dibs&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;: 2 elements set to &lt;code&gt;1fr&lt;/code&gt; &amp;amp; &lt;code&gt;3fr&lt;/code&gt;&lt;br&gt;
= Available space is divided into 4 equal shares &lt;br&gt;
→ 1st element occupies 1/4 &amp;amp; 2nd element occupies 3/4 of leftover space&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Application&lt;/em&gt;&lt;br&gt;
&lt;code&gt;grid-template-columns: 50px 1fr 1fr 1fr 50px;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. &lt;code&gt;vh&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= Viewport Height &lt;br&gt;
→ Can be used with &lt;code&gt;grid-template-rows&lt;/code&gt; to determine the height of a row&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. &lt;code&gt;vw&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
 = Viewport Width&lt;br&gt;
→ Can be used with &lt;code&gt;grid-template-columns&lt;/code&gt; to determine the width of a column&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;fr&lt;/code&gt; vs &lt;code&gt;%&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Similarities&lt;/em&gt;&lt;br&gt;
= Equal sized tracks: &lt;code&gt;fr&lt;/code&gt; &amp;amp; &lt;code&gt;%&lt;/code&gt; look the same&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Differences&lt;/em&gt;&lt;br&gt;
&lt;code&gt;fr&lt;/code&gt;&lt;br&gt;
= A Fraction of the Free Space&lt;br&gt;
→ Takes &lt;code&gt;gap&lt;/code&gt;s into account&lt;/p&gt;

&lt;p&gt;&lt;code&gt;%&lt;/code&gt;&lt;br&gt;
= A Percentage of the Grid Size &lt;br&gt;
→ Does &lt;em&gt;not&lt;/em&gt; take &lt;code&gt;gap&lt;/code&gt;s into account: Does not make space for them&lt;br&gt;
→ Rows/Columns will take of the specified % of space no matter what: Tracks will get pushed outside bounds of the Grid&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Conclusion&lt;/em&gt;&lt;br&gt;
= &lt;code&gt;fr&lt;/code&gt; &amp;gt; &lt;code&gt;%&lt;/code&gt; &lt;br&gt;
→ When using &lt;code&gt;gap&lt;/code&gt;s &lt;/p&gt;
&lt;h4&gt;
  
  
  Flexible Values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;br&gt;
= Sets a range of possible Element-Size Values &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application&lt;/strong&gt;&lt;br&gt;
= Working with changing size of Content within a Cell&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;auto&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= Working with text content&lt;br&gt;
= Equal to size of content placed&lt;br&gt;
→ An empty track with &lt;code&gt;auto&lt;/code&gt; size = Having size of &lt;code&gt;0px&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. minmax()&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Defines track size as a Range&lt;br&gt;
→ Rather than taking a single value for track size &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application&lt;/em&gt;&lt;br&gt;
= Takes 2 Values as Arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Minimum Size of Track &lt;/li&gt;
&lt;li&gt;Maximum Size of Track&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;= If  &lt;code&gt;max&lt;/code&gt; is lower than &lt;code&gt;min&lt;/code&gt;&lt;br&gt;
→ &lt;code&gt;min&lt;/code&gt; overrides &lt;code&gt;max&lt;/code&gt;&lt;br&gt;
→ Even if &lt;code&gt;max&lt;/code&gt; is set to &lt;code&gt;auto&lt;/code&gt; &amp;amp; Track is empty&lt;/p&gt;

&lt;p&gt;= Range is always between a smaller value &amp;amp; a larger one&lt;br&gt;
→ No matter ascending or descending placement &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interactions&lt;/em&gt;&lt;br&gt;
= Takes priority over regular &lt;code&gt;fr&lt;/code&gt; tracks &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;&lt;br&gt;
&lt;code&gt;minmax(*min*,*max*)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;min/max-content&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;min-content&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
= Size of smallest content in track&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;max-content&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
= Size of largest content in track &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;code&gt;repeat()&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Remove need to specify so many identical widths&lt;br&gt;
→ Shorthand&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;&lt;br&gt;
&lt;code&gt;repeat(*num tracks*, *size of tracks*)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;&lt;br&gt;
Without &lt;code&gt;repeat&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;grid-template-columns: 20% 20% 20% 20% 20%;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;repeat&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;grid-template-columns: repeat(5, 20%);&lt;/code&gt;&lt;br&gt;
→ Creates &lt;code&gt;5&lt;/code&gt; columns, each with &lt;code&gt;20%&lt;/code&gt; width&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1st Parameter Keyword Values&lt;/em&gt;&lt;br&gt;
--&lt;code&gt;auto-fill&lt;/code&gt;--&lt;br&gt;
= Fills Grid w/ as many Tracks of the specified size as possible&lt;br&gt;
→ Dynamic&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;code&gt;grid-template-columns: repeat(auto-fill, 150px)&lt;/code&gt;&lt;br&gt;
= Fill the grid with as many 150px columns as possible &lt;/p&gt;

&lt;p&gt;--&lt;code&gt;auto-fit&lt;/code&gt;--&lt;br&gt;
Similar to &lt;code&gt;auto-fill&lt;/code&gt;&lt;br&gt;
= Grid will create as many of given sized tracks as will fit&lt;/p&gt;

&lt;p&gt;Difference to &lt;code&gt;auto-fill&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;auto-fit&lt;/code&gt;: Any empty tracks get collapsed to 0px&lt;br&gt;
→ If columns are created, but there are no elements inside them, they will exist, but you won't see them&lt;/p&gt;

&lt;p&gt;--&lt;code&gt;auto-fit&lt;/code&gt; &amp;amp; &lt;code&gt;auto-fill&lt;/code&gt; Similarities--&lt;br&gt;
= Takes gaps into account&lt;br&gt;
→ If you have large gaps: grid will have less room to create new tracks&lt;/p&gt;

&lt;p&gt;= Both make tracks 0pc if they don't have any grid items inside them &lt;br&gt;
→ Regardless of whether or not those grid items contain content themselves&lt;/p&gt;
&lt;h2&gt;
  
  
  3.2 Gaps
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;grid-column-gap&lt;/code&gt; takes &lt;em&gt;away&lt;/em&gt; from the available space that &lt;code&gt;justify-content&lt;/code&gt; gets to split between the columns&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;grid-row/column-gap&lt;/code&gt;&lt;br&gt;
= Measures size of gaps between the tracks&lt;/p&gt;
&lt;h3&gt;
  
  
  Implications
&lt;/h3&gt;

&lt;p&gt;= Starting &amp;amp; Ending Line of the &lt;code&gt;gap&lt;/code&gt;: Has the same &lt;em&gt;Line Number&lt;/em&gt;&lt;br&gt;
→ The &lt;code&gt;gap&lt;/code&gt; is 1 thick line, stretched&lt;br&gt;
→ Line now officially starts &lt;em&gt;after&lt;/em&gt; the gap &lt;/p&gt;
&lt;h3&gt;
  
  
  Units of Measurement
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. vw
&lt;/h4&gt;
&lt;h4&gt;
  
  
  2. vh
&lt;/h4&gt;
&lt;h4&gt;
  
  
  3. %
&lt;/h4&gt;
&lt;h4&gt;
  
  
  4. px
&lt;/h4&gt;
&lt;h4&gt;
  
  
  5. rem
&lt;/h4&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Most &lt;code&gt;template-columns/rows&lt;/code&gt;' Units of Measurement can be used&lt;br&gt;
→ Except: &lt;code&gt;fr&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;planet {
 display: grid;
 grid-template-rows: 1fr 1fr;
 grid-template-columns: 1fr 1fr;
 grid-row-gap: 200px;
 grid-column-gap: 50px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  3.3 Flow
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;grid-auto-flow&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Change the flow of the Grid itself &lt;/p&gt;

&lt;p&gt;= Configures 2 things: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Direction&lt;/strong&gt; (&lt;code&gt;row&lt;/code&gt; or &lt;code&gt;column&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Packing&lt;/strong&gt; (&lt;code&gt;sparse&lt;/code&gt; or &lt;code&gt;dense&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;= Can configure Direction &amp;amp; Packing at once&lt;br&gt;
→ &lt;code&gt;grid-auto-flow: row dense;&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  What is &lt;em&gt;Packing&lt;/em&gt;?
&lt;/h4&gt;

&lt;p&gt;= Whether the Grid goes back to previous empty cells or not &lt;/p&gt;
&lt;h3&gt;
  
  
  Example Use Case
&lt;/h3&gt;

&lt;p&gt;Insert Elements into Grid as &lt;strong&gt;Columns&lt;/strong&gt;, instead of Rows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-auto-flow: column;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Elements flow into Grid: Filling up Columns &lt;em&gt;before&lt;/em&gt; Rows &lt;br&gt;
→ Starts from left&lt;/p&gt;
&lt;h3&gt;
  
  
  Implications
&lt;/h3&gt;

&lt;p&gt;= Now &lt;code&gt;grid-column&lt;/code&gt; placement gets priority&lt;br&gt;
→ Instead of &lt;code&gt;grid-row&lt;/code&gt; placement&lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Default
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-auto-flow: sparse row;&lt;/code&gt;&lt;br&gt;
→ Elements flow into the Grid filling up rows before columns: Starting from top&lt;br&gt;
→ Leaves cells empty if Element size does not fit into it: Moves onto next cell to try and fit it&lt;/p&gt;
&lt;h4&gt;
  
  
  2. &lt;code&gt;row&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Elements fill up Rows &lt;em&gt;before&lt;/em&gt; Columns&lt;br&gt;
→ Starting from top&lt;/p&gt;
&lt;h4&gt;
  
  
  3. &lt;code&gt;column&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Elements fill up Columns &lt;em&gt;before&lt;/em&gt; Rows &lt;br&gt;
→ Starting from left&lt;/p&gt;
&lt;h4&gt;
  
  
  4. &lt;code&gt;sparse&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Grid keeps moving forward&lt;br&gt;
→ As it looks for an appropriate cell to place the element &lt;br&gt;
→ Even if that means leaving empty cells behind &lt;/p&gt;
&lt;h4&gt;
  
  
  5. &lt;code&gt;dense&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Instructs the Grid to go back &amp;amp; fill empty cells previously skipped &lt;br&gt;
→ Functionally equivalent to &lt;code&gt;nowrap&lt;/code&gt; in Flexbox&lt;/p&gt;
&lt;h2&gt;
  
  
  3.4 Content Characteristics
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Wrapping
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Text can wrap to multiple lines when they need &lt;br&gt;
→ When size is larger than max value of minmax&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;auto&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;auto&lt;/code&gt; is the size of the content&lt;br&gt;
→ Including wrapping when needed&lt;br&gt;
→ &lt;code&gt;auto&lt;/code&gt; is a somewhat flexible value &lt;br&gt;
→ Text will take up as much space as it can before it hits the &lt;code&gt;max&lt;/code&gt; limit &amp;amp; starts wrapping&lt;/p&gt;
&lt;h4&gt;
  
  
  Implications
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;max&lt;/code&gt; value of &lt;code&gt;minmax&lt;/code&gt; is respected&lt;br&gt;
→ If contents are able to wrap&lt;/p&gt;
&lt;h2&gt;
  
  
  3.5 &lt;code&gt;content&lt;/code&gt; Spacing/Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Controlling the &lt;em&gt;whole Grid&lt;/em&gt;&lt;br&gt;
→ Position tracks(columns/rows) themselves&lt;/p&gt;

&lt;p&gt;= Columns'/Rows' Positioning &amp;amp; Spacing &lt;br&gt;
→ When they do not take up the full Width/Height of Grid Cells &lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;justify/align-content&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Default: &lt;code&gt;stretch&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Changes the size of any &lt;code&gt;auto&lt;/code&gt;-sized column&lt;br&gt;
→ Until grid is completely filled&lt;/p&gt;

&lt;p&gt;= Stretches out &lt;code&gt;auto&lt;/code&gt; columns&lt;br&gt;
→ But not fixed width columns&lt;/p&gt;

&lt;p&gt;= Takes up all available space&lt;br&gt;
→ &amp;amp;&amp;amp; Adds it equally to each of the &lt;code&gt;auto&lt;/code&gt; columns &lt;br&gt;
→ Size of column depends on the size of its content&lt;/p&gt;

&lt;p&gt;= Splits up the free space evenly &lt;br&gt;
→ Adds it to the &lt;code&gt;auto&lt;/code&gt; sized columns &lt;br&gt;
→ On &lt;em&gt;top&lt;/em&gt; of their initial size (size of content)&lt;/p&gt;
&lt;h4&gt;
  
  
  2. &lt;code&gt;center&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Groups all the columns/rows up into center of available space in the Grid &lt;/p&gt;
&lt;h4&gt;
  
  
  3. &lt;code&gt;end&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Columns/rows flush to the right/bottom&lt;/p&gt;
&lt;h4&gt;
  
  
  4. &lt;code&gt;start&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Columns/rows flush to the left/top&lt;/p&gt;
&lt;h4&gt;
  
  
  5. &lt;code&gt;space-between&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Spaces columns/rows out&lt;br&gt;
→ No space on the outside of the outer 2 columns/rows&lt;/p&gt;
&lt;h4&gt;
  
  
  6. &lt;code&gt;space-evenly&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Space around outside 2 columns/rows&lt;br&gt;
→ Even amounts of space everywhere&lt;br&gt;
→ Amount of space is exactly the same&lt;br&gt;
→ On all sides of every column: Including the outer 2 columns&lt;/p&gt;
&lt;h4&gt;
  
  
  7. &lt;code&gt;space-around&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= Space &lt;em&gt;outside&lt;/em&gt; the 2 columns 1/2 the size of space &lt;em&gt;between&lt;/em&gt; the columns&lt;br&gt;
→ Same amount of space &lt;em&gt;around&lt;/em&gt; every column&lt;br&gt;
→ Including the outer ones &lt;br&gt;
→ Middle columns look like they're getting double the space: only bc their space is adjacent to another column's space&lt;/p&gt;
&lt;h2&gt;
  
  
  3.6 &lt;code&gt;item&lt;/code&gt;s Spacing/Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Horizontal/Vertical positioning of Grid elements within their Grid cells &lt;br&gt;
→ When they do not take up the full space of the Grid Cell&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;justify/align-items&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Default: &lt;code&gt;stretch&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= w/o specifying &lt;code&gt;justify-items&lt;/code&gt;&lt;br&gt;
→ Only works for items that don't already specify their size &lt;br&gt;
→ If elements have a &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; set, &lt;code&gt;stretch&lt;/code&gt; is overridden&lt;/p&gt;
&lt;h4&gt;
  
  
  2. &lt;code&gt;start&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= To the Left&lt;/p&gt;
&lt;h4&gt;
  
  
  3. &lt;code&gt;end&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= To the Right&lt;/p&gt;
&lt;h2&gt;
  
  
  3.7 Interaction between Spacing &amp;amp; &lt;code&gt;gap&lt;/code&gt;s
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Adding a column gap&lt;br&gt;
→ Widens the distance between the columns&lt;br&gt;
→ &amp;amp;&amp;amp; &lt;em&gt;spacing&lt;/em&gt; on &lt;em&gt;outside&lt;/em&gt; of columns shrink&lt;/p&gt;
&lt;h3&gt;
  
  
  Implications
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;gap&lt;/code&gt;s are calculated &lt;em&gt;before&lt;/em&gt; spaces&lt;/p&gt;
&lt;h2&gt;
  
  
  3.8 Implicit Tracks
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Creation
&lt;/h3&gt;

&lt;p&gt;= Tracks created beyond &lt;code&gt;template&lt;/code&gt; on the Container &lt;br&gt;
→ Created by adding individual elements to a column/row line number larger than those existing&lt;/p&gt;
&lt;h3&gt;
  
  
  Definition
&lt;/h3&gt;

&lt;p&gt;= Collapsed tracks from auto-fit are &lt;strong&gt;not&lt;/strong&gt; implicit tracks &lt;/p&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Grid adaptability to content inside&lt;br&gt;
→ Automatically adding as many tracks as it needs to fit all its elements&lt;/p&gt;

&lt;p&gt;= Positioning an element into a column that does not exist &lt;br&gt;
→ Creates a column even if that column was not defined before in the Grid template&lt;/p&gt;
&lt;h3&gt;
  
  
  Implications
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;gap&lt;/code&gt;s are still included between implicit tracks&lt;br&gt;
→ Implicit tracks are identical to regular tracks &lt;br&gt;
→ They just don't show up unless needed&lt;/p&gt;
&lt;h3&gt;
  
  
  Example Use Case
&lt;/h3&gt;

&lt;p&gt;= Grid only had 4 cells: 2 rows &amp;amp; 2 columns&lt;br&gt;
→ But 6 elements to fit in &lt;/p&gt;

&lt;p&gt;= Thus, it makes a brand new implicit row &lt;br&gt;
→ Makes room for those 2 extra elements &lt;/p&gt;
&lt;h3&gt;
  
  
  Sizing
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Controlling size of any implicit columns the Grid adds automatically &lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-auto-columns&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Default: &lt;code&gt;auto&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;grid-auto-columns/rows: auto;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;= As tall/wide as content of element &lt;br&gt;
→ Collapses down to 0px if there is no content&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Application&lt;/em&gt;&lt;br&gt;
= If there are only 5 Columns, but you try to place an element in Column Line 7&lt;br&gt;
→ There will be 2 Implicit Tracks created:&lt;br&gt;
One to place the element in &lt;br&gt;
&amp;amp; One before that &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Any &lt;code&gt;template&lt;/code&gt; Values&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3.9 Naming
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Lines
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= To be used instead of Line &lt;em&gt;Numbers&lt;/em&gt;&lt;br&gt;
→ Can assign a Name to any Line&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Setup - Add Names to Lines
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Location&lt;/strong&gt;&lt;br&gt;
= In Values for &lt;code&gt;grid-template-columns/row&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
= "Line, Track, Line Pattern"&lt;br&gt;
→ Brackets [] are used to name Lines&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: [start] 1fr 1fr [center] 1fr 1fr [end];
grid-template-rows: [top] 1fr 1fr [bottom];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Default Line Names&lt;/strong&gt;&lt;br&gt;
= Order of line&lt;br&gt;
→ &lt;strong&gt;ie&lt;/strong&gt; Code Written...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: 1fr 1fr 1fr 1fr 1fr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;→ ... Implied Line Names&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: [1] 1fr [2] 1fr [3] 1fr [4] 1fr [5];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rules&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;1. Do not need to name _all&lt;/em&gt; the Lines_&lt;br&gt;
= Can just name &lt;em&gt;some&lt;/em&gt; that will be used&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Number of Names per Lines&lt;/em&gt;&lt;br&gt;
= No Limit&lt;br&gt;
→ Different Names: Separated by a &lt;em&gt;space&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: 1fr [middle center] 1fr;
grid-template-rows: 1fr [neat-line awesome-line] 1fr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Assign the &lt;em&gt;same&lt;/em&gt; name to many lines &lt;br&gt;
→ ie To Position those lines at the same time&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application&lt;/em&gt;&lt;br&gt;
= Used w/ &lt;code&gt;repeat()&lt;/code&gt;&lt;br&gt;
→ Only affects Lines created w/in &lt;code&gt;repeat()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;repeat(*num tracks/lines*, [*lines' name*] *track size*)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: 1fr repeat(5, [grass] 50px) 1fr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Applications of Line Names
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Capture Line &lt;em&gt;after&lt;/em&gt; Tracks created by &lt;code&gt;repeat()&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= Add Line Name again after &lt;code&gt;repeat()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Target Multiple Lines w/ Same Name&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Syntax&lt;/em&gt;&lt;br&gt;
= Use the &lt;em&gt;Name Number Syntax&lt;/em&gt;&lt;br&gt;
→ Use Name w/ Order Position w/in all those of the same name&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Value&lt;/em&gt;: &lt;code&gt;grass 3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Grouping Line Names&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= Creating a Line Group &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;&lt;br&gt;
Naming line 3 &lt;code&gt;bottom-start&lt;/code&gt; &amp;amp; line 5 &lt;code&gt;bottom-end&lt;/code&gt;&lt;br&gt;
= Giving both &lt;code&gt;bottom&lt;/code&gt; prefix &lt;br&gt;
→ Grouped the 2 lines &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application&lt;/em&gt;&lt;br&gt;
= Lines that are grouped can be referenced through their group name insolation, without the suffixes&lt;br&gt;
&lt;strong&gt;ie&lt;/strong&gt; &lt;code&gt;grid-row: bottom;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Use Names as Values&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Location&lt;/em&gt;&lt;br&gt;
= In Values for &lt;code&gt;grid-column/row-start/end&lt;/code&gt; / &lt;code&gt;grid-column/row&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row: top / bottom;
grid-column: start / center;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Line Name &amp;amp; Number Values Combined&lt;/strong&gt;&lt;br&gt;
= Isolated Line Name &amp;amp;&amp;amp; Number Values as part of &lt;code&gt;grid-column/row&lt;/code&gt; Shorthand Values&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row: 2 / bottom;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Areas
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-template-areas: ". . ." ". . ." ". . ."&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;= Number of ""s = Number of Columns&lt;br&gt;
→ Each pair of quotes separated by a space&lt;/p&gt;

&lt;p&gt;= Number of space-separated values inside each "" = Number of Rows&lt;br&gt;
→ Num of space-separated values inside each “” need to be the same&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#page {
  display: grid;
  width: 100%;
  height: 250px;
  grid-template-areas: "head head"
                       "nav  main"
                       "nav  foot";
  grid-template-rows: 50px 1fr 30px;
  grid-template-columns: 150px 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Each line in &lt;code&gt;grid-template-areas&lt;/code&gt; setting: Represents a row in the Grid &lt;br&gt;
→ Each row/line must contain the same number of cell names &lt;/p&gt;
&lt;h4&gt;
  
  
  Recommended Uses
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Create Group for 4 side column lines&lt;/strong&gt;&lt;br&gt;
= Name &lt;code&gt;side&lt;/code&gt; using &lt;code&gt;-start&lt;/code&gt; and &lt;code&gt;-end&lt;/code&gt; suffixes&lt;br&gt;
&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: 1fr [side-start] 100px 100px 100px [side-end];
grid-template-rows: 1fr [bottom-start] 100px 100px 100px [bottom-end];
&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;grid-area: bottom / side;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Is identical to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-start: bottom;
grid-column-start: side;
grid-row-end: bottom;
grid-column-end: side;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Give &lt;code&gt;column&lt;/code&gt; line group same name as &lt;code&gt;row&lt;/code&gt; line group&lt;/strong&gt;&lt;br&gt;
= All 4 lines working together to form a single &lt;code&gt;area&lt;/code&gt;&lt;br&gt;
→ Ideal b/c can position items by area name&lt;br&gt;
&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: center;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Gives Names to Grid Areas&lt;br&gt;
→ Establishes Cells in the Grid &amp;amp; Assigns them Names&lt;/p&gt;
&lt;h4&gt;
  
  
  Warning
&lt;/h4&gt;

&lt;p&gt;= Areas are not associated with any particular grid item &lt;br&gt;
→ But can be referenced from the grid-placement properties: &lt;code&gt;grid-row-start&lt;/code&gt; &lt;code&gt;grid-row-end&lt;/code&gt; &lt;code&gt;grid-column-start&lt;/code&gt; &lt;code&gt;grid-column-end&lt;/code&gt; &amp;amp; their shorthands &lt;code&gt;grid-row&lt;/code&gt; &lt;code&gt;grid-column&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;grid-area&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;planet {
  display: grid;
  grid-gap: 50px;

  grid-template-areas: "grass grass dunes" "rocky rocky dunes";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

rocky {

  grid-area: rocky;

}

grass {

  grid-area: grass;

}

dunes {

  grid-area: dunes;

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

&lt;/div&gt;

&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Only Creating 1 Area&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Application&lt;/em&gt;&lt;br&gt;
= Do still need to name all the cells in the grid &lt;br&gt;
→ But to indicate the cells where you do not want to create an area: Use a period (.) in place of a name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-areas: ". . ." ". center ." ". . .";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= "." makes for cells with no name &lt;br&gt;
→ But items can still flow into those cells on their own&lt;br&gt;
→ It does not prevent the filling of a cell&lt;br&gt;
→ It just leaves its name blank&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disadvantages&lt;/em&gt;&lt;br&gt;
= Periods mess up how &lt;code&gt;grid-template-areas&lt;/code&gt; can visually represent the Grid &lt;br&gt;
--&amp;gt; No longer resembles the Grid itself &lt;br&gt;
= To keep the Grid look of this definition &lt;br&gt;
--&amp;gt; Can use ore periods&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example Use Case&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-areas: ". ...... ." ". center ." ". ...... .";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Only &lt;em&gt;names&lt;/em&gt; all Grid lines bordering each area&lt;br&gt;
→ Does not &lt;em&gt;create&lt;/em&gt; Grid lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  grid-template-areas: "left . . right";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Defines an area named &lt;code&gt;left&lt;/code&gt;&lt;br&gt;
→ Names all lines bordering that area&lt;br&gt;
→ Column line 1 &amp;amp; Row line 1 named &lt;code&gt;left-start&lt;/code&gt;&lt;br&gt;
→ Column line 2 &amp;amp; Row line 2 names &lt;code&gt;left-end&lt;/code&gt; &lt;br&gt;
= Can position elements using those line names &lt;br&gt;
→ Even though you did not manually name them&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ie&lt;/strong&gt; Make an element start at the line name &lt;code&gt;left-end&lt;/code&gt;(line 2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: left-end;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Advantages
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Not needing to name all lines manually&lt;/strong&gt;&lt;br&gt;
= Also do not need to give every cell a name &lt;br&gt;
→ Use a period (.) for non-named cells &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Most convenient way to name lines: &lt;code&gt;grid-template-areas&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= After naming the lines, you can position elements to those lines using any of the item placement settings or their shorthands&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: center;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= A shorthand for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: center-start / center-end / center-start / center-end;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Recommended Use Case
&lt;/h4&gt;

&lt;p&gt;= Better than naming a ton of lines&lt;br&gt;
→ Areas can be as small or large as you want &lt;br&gt;
→ As long as the cells are adjacent and form a rectangle&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As an Alternative&lt;/strong&gt;&lt;br&gt;
= Naming lines through &lt;code&gt;areas&lt;/code&gt; instead of manually naming lines through  &lt;code&gt;template-columns/rows&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Setup
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Start by defining the areas using empty cells&lt;/strong&gt;&lt;br&gt;
= Make sure to get the correct number of rows &amp;amp; columns&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-areas: ". . ." ". . ." ". . .";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= For 3 rows/columns&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Name the cells you need to&lt;/strong&gt;&lt;br&gt;
= Create 3 area names using &lt;code&gt;grid-template-areas&lt;/code&gt;&lt;br&gt;
--&amp;gt; The top 3 cells &amp;amp; the middle left cell will remain empty &lt;/p&gt;

&lt;p&gt;&lt;em&gt;When naming grid-areas&lt;/em&gt;&lt;br&gt;
= Need to name all of them in order to work&lt;br&gt;
→ Add ""s and .s&lt;/p&gt;
&lt;h4&gt;
  
  
  Types of Values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Default: &lt;code&gt;none&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Keyword Values&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;code&gt;none&lt;/code&gt;&lt;br&gt;
= Grid container does not define any names grid areas&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. String Values&lt;/strong&gt;&lt;br&gt;
= 1 Row is created by each separate string listed&lt;br&gt;
→ 1 Column is created for each cell in the string &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Grid Area&lt;/strong&gt;&lt;br&gt;
= Multiple cell tokens w/ same name w/in &amp;amp; between rows&lt;br&gt;
→ Creates a single names grid area: Spanning corresponding grid cells &lt;br&gt;
→ Unless those cells form a rectangle, the declaration is invalid&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-areas: "a b b" "a c d";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Global Values&lt;/strong&gt;&lt;br&gt;
= &lt;code&gt;inherit&lt;/code&gt;, &lt;code&gt;initial&lt;/code&gt;, &lt;code&gt;revert&lt;/code&gt;, &lt;code&gt;revert-layer&lt;/code&gt;, &lt;code&gt;unset&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;h1&gt;
  
  
  Part 4 On Individual Elements
&lt;/h1&gt;
&lt;h2&gt;
  
  
  4.1 Sizing
&lt;/h2&gt;

&lt;p&gt;= % sizing for each element is relative to the grid cell, rather than the whole grid container&lt;/p&gt;
&lt;h2&gt;
  
  
  4.2 Cell Spacing/Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. &lt;code&gt;span&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;br&gt;
= Span a few row/column lines from wherever it is naturally placed &lt;br&gt;
→ Make Elements take up the space you want: Wherever they are placed in the Grid&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applications&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;1. Used w/ both &lt;code&gt;start&lt;/code&gt; &amp;amp; &lt;code&gt;end&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
Purpose&lt;br&gt;
= Sets element width relative to end (when used w/ &lt;code&gt;start&lt;/code&gt;) position, or start (when used w/ &lt;code&gt;end&lt;/code&gt;) position&lt;/p&gt;

&lt;p&gt;Example Use Case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: 1;
grid-column-end: span 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;2. Use w/ &lt;code&gt;start&lt;/code&gt; OR &lt;code&gt;end&lt;/code&gt; for _both&lt;/em&gt; &lt;code&gt;column&lt;/code&gt; &amp;amp; &lt;code&gt;row&lt;/code&gt;_&lt;br&gt;
Purpose&lt;br&gt;
= Size Element &lt;em&gt;w/o&lt;/em&gt; Positioning it&lt;br&gt;
→ Size it regardless of &lt;em&gt;where&lt;/em&gt; it lies on the Grid&lt;br&gt;
= Make the UI dynamic&lt;/p&gt;

&lt;p&gt;Implications&lt;br&gt;
= Essentially sets the Height (&lt;code&gt;column&lt;/code&gt; &lt;code&gt;span&lt;/code&gt; amount) &amp;amp; Width (&lt;code&gt;row&lt;/code&gt; &lt;code&gt;span&lt;/code&gt; amount) of the Element&lt;br&gt;
= Starts spanning along Grid flow, from 1st lines, by default&lt;/p&gt;

&lt;p&gt;Example Use Case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rocky {
grid-column-start*or -end*: span 2;
grid-row-end*or -start*: span 4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or simplified...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rocky {
grid-column: span 2;
grid-row: span 4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;3. Used Alone: &lt;code&gt;start&lt;/code&gt; OR &lt;code&gt;end&lt;/code&gt; for &lt;code&gt;column&lt;/code&gt; OR &lt;code&gt;row&lt;/code&gt;&lt;/em&gt;_&lt;br&gt;
Purpose&lt;br&gt;
= Set Element's Starting/Ending Column/Row Line&lt;br&gt;
→ Instead of a fixed Line Number&lt;/p&gt;

&lt;p&gt;= No longer need to &lt;em&gt;hard code&lt;/em&gt; a specific line&lt;br&gt;
→ Code becomes more &lt;em&gt;dynamic&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Example Use Cases&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-start: span 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Element will span 3 lines (counting from 1st line)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-end: span 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Element will span 3 lines (counting from 1st line &lt;em&gt;also&lt;/em&gt;) &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I found it quite unexpected that &lt;code&gt;end&lt;/code&gt; and &lt;code&gt;start&lt;/code&gt; would both count from the same direction&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Values&lt;/strong&gt;&lt;br&gt;
= Written after &lt;code&gt;span&lt;/code&gt; &amp;amp; space&lt;br&gt;
→ Only positive numbers&lt;/p&gt;
&lt;h2&gt;
  
  
  4.3 Item Positioning vs Grid Container
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Grid Container
&lt;/h3&gt;

&lt;p&gt;= Think of Rows and Columns as &lt;em&gt;Tracks&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Item Positioning
&lt;/h3&gt;

&lt;p&gt;= Think of Rows and Columns by &lt;strong&gt;Lines&lt;/strong&gt;&lt;br&gt;
→ &lt;strong&gt;ie&lt;/strong&gt; &lt;code&gt;grid-row-start: 3&lt;/code&gt; moves an Element down into the 3rd row, but done by making it start at the 3rd &lt;strong&gt;Line&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4.4 Column/Row Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;grid-column/row-start/end&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Tell Element which line to &lt;code&gt;start&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt; on&lt;br&gt;
= Position an item by Line Number&lt;br&gt;
→ Choose Line Number on which to place the element&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; both used
&lt;/h4&gt;

&lt;p&gt;= Extend Element across multiple columns/rows&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;start&lt;/code&gt; or &lt;code&gt;end&lt;/code&gt; used alone
&lt;/h4&gt;

&lt;p&gt;= Element spans 1 column or row&lt;br&gt;
= Ends on the line of column or row identified &amp;amp;&amp;amp; Takes up a single cell by default&lt;br&gt;
→ Thus, starting on the line directly prior to the one identified&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Use Case&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grass {
  grid-column-end: 3;
  grid-row-end: 4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ol&gt;
&lt;li&gt;Element starts at 3rd row line &amp;amp; ends at 4th row line 
→ Taking up a single row (track 3)&lt;/li&gt;
&lt;li&gt;Starts at 2nd column line &amp;amp; ends at 3rd column line
→ Taking up a single column (track 2)&lt;/li&gt;
&lt;li&gt;The single cell at the intersection of row track 3 &amp;amp; column track 2
→ Is now occupied by the Element&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Positioning individual elements w/in a Grid container&lt;br&gt;
→ Target each Element by selecting itself &lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Example Value
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-column/row-start: 3;&lt;/code&gt;&lt;br&gt;
= Place element starting at the 3rd vertical/horizontal grid line/3rd vertical/horizontal border from left in the grid &lt;/p&gt;
&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-start: 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Start Element at 3rd Horizontal Line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Start Element at 3rd Vertical Line&lt;/p&gt;

&lt;h4&gt;
  
  
  Units of Measurement
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Positive Numbers&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: 1;
grid-column-end: 4;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Element starts at 1st vertical grid line &amp;amp; Ends at 4th vertical grid line&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Negative Numbers&lt;/strong&gt;&lt;br&gt;
= Counts from opposite direction &lt;br&gt;
&lt;em&gt;Examples&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Starts at 1st Line from right&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-end: -2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Ends at 2nd line from bottom &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= &lt;code&gt;grid-column-end&lt;/code&gt; does not need to be greater than &lt;code&gt;grid-column-start&lt;/code&gt;&lt;br&gt;
= Count Grid Lines from right instead of left &lt;/p&gt;
&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: 5;
grid-column-end: 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Same effect as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column-start: 2;
grid-column-end: 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= &lt;code&gt;grid-column-start&lt;/code&gt; &amp;amp; &lt;code&gt;grid-column-end&lt;/code&gt; can be reversed&lt;/p&gt;

&lt;h2&gt;
  
  
  4.5 Combinations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;end&lt;/code&gt; Line Position (Num/Name) used with &lt;code&gt;start&lt;/code&gt; &lt;code&gt;span&lt;/code&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Space in reverse direction &lt;br&gt;
→ Element spans in &lt;em&gt;opposite&lt;/em&gt; direction of Grid flow&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I thought this could be more straight-forwardly done through (the currently redundant) &lt;code&gt;end&lt;/code&gt; with &lt;code&gt;span&lt;/code&gt;. This seems like a very convoluted and verbose way of doing it if you just want to start counting from the natural final line. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Works for both &lt;code&gt;grid-row&lt;/code&gt; &amp;amp; &lt;code&gt;grid-column&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
= If used with &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
→ Changes to bottom-up&lt;br&gt;
= If used with &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
→ Changes to right-to-left &lt;/p&gt;
&lt;h4&gt;
  
  
  Comparison
&lt;/h4&gt;

&lt;p&gt;= Essentially same as &lt;strong&gt;Flexbox&lt;/strong&gt;'s &lt;code&gt;flex-direction: column-reverse&lt;/code&gt; &amp;amp; &lt;code&gt;flex-direction: row-reverse&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rocky {
grid-row-end: 5;
grid-row-start: span 3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Starts counting from the &lt;code&gt;end&lt;/code&gt; line number identified, and counts the full amount of proceeding lines specified after &lt;code&gt;span&lt;/code&gt; of &lt;code&gt;start&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. &lt;code&gt;grid-column/row-start&lt;/code&gt; or &lt;code&gt;grid-column/row-end&lt;/code&gt; used &lt;em&gt;alone&lt;/em&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Only Positioning of Element&lt;br&gt;
→ Defining Start &amp;amp; End Positions of Grid Lines&lt;/p&gt;
&lt;h3&gt;
  
  
  3. &lt;code&gt;grid-column/row-start&lt;/code&gt; &amp;amp; &lt;code&gt;grid-column/row-end&lt;/code&gt; used &lt;em&gt;together&lt;/em&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Sizing &lt;em&gt;on top of&lt;/em&gt; Positioning&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;span&lt;/code&gt; for &lt;code&gt;start&lt;/code&gt; vs &lt;code&gt;span&lt;/code&gt; for &lt;code&gt;end&lt;/code&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Similarities
&lt;/h4&gt;

&lt;p&gt;= Exact Same Effect&lt;br&gt;
→ Both count in the &lt;em&gt;direction&lt;/em&gt; of Grid flow&lt;/p&gt;
&lt;h4&gt;
  
  
  Differences
&lt;/h4&gt;

&lt;p&gt;= If &lt;em&gt;both&lt;/em&gt; are set: &lt;code&gt;start&lt;/code&gt; takes precedence over &lt;code&gt;end&lt;/code&gt;&lt;br&gt;
→ &lt;code&gt;end&lt;/code&gt; will have no effect &lt;/p&gt;
&lt;h2&gt;
  
  
  4.6 Element Spacing/Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Grid Container
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;align/justify-items&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Used on Grid Container&lt;br&gt;
= If &lt;code&gt;align/justify-items&lt;/code&gt; is set to anything but &lt;code&gt;stretch&lt;/code&gt;&lt;br&gt;
→ Elements w/o explicit size specifications: Will Collapse&lt;/p&gt;
&lt;h3&gt;
  
  
  Individual Elements
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Horizontal/vertical positioning&lt;br&gt;
= Used on individual Elements&lt;br&gt;
→ Overrides Grid's &lt;code&gt;align/justify-items&lt;/code&gt; for the one Element &lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;align/justify-self&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;p&gt;= Same values as &lt;code&gt;justify/align-items&lt;/code&gt; (which were used on Grid container)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defaults&lt;/strong&gt;&lt;br&gt;
= Not explicitly placed w/ &lt;code&gt;grid-area&lt;/code&gt;, &lt;code&gt;grid-column&lt;/code&gt;, &lt;code&gt;grid-row&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;start&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. &lt;code&gt;end&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. &lt;code&gt;center&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;4. &lt;code&gt;stretch&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= If &lt;code&gt;justify-self&lt;/code&gt; is set to &lt;code&gt;start&lt;/code&gt; or &lt;code&gt;end&lt;/code&gt;&lt;br&gt;
→ Must specify &lt;code&gt;width&lt;/code&gt; if there is no content in the cell&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;water {
grid-column: span 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;water {
justify-self: start;
grid-column: span 2;
width: 100%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Element starts from left of the grid cell, and also spans 100% of the cell&lt;br&gt;
→ B/c &lt;code&gt;justify-self&lt;/code&gt; is no longer the default &lt;code&gt;stretch&lt;/code&gt;, this explicit width needs to be set&lt;/p&gt;
&lt;h2&gt;
  
  
  4.7 Order
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Use to alter the positioning an element &lt;br&gt;
→ 0-based: Has a default of 0 &lt;/p&gt;
&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Can be used on any element&lt;/p&gt;
&lt;h4&gt;
  
  
  With Row-Positioned Items
&lt;/h4&gt;

&lt;p&gt;= Row-positioned items are still given 1st placement priority&lt;br&gt;
→ Regardless of the order &lt;/p&gt;

&lt;p&gt;= &lt;code&gt;grid-row&lt;/code&gt; trumps &lt;code&gt;order&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Default
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;order: 0&lt;/code&gt;&lt;br&gt;
→ Automatically places all elements according to order in source code&lt;/p&gt;
&lt;h4&gt;
  
  
  Types of Values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Positive or Negative&lt;/strong&gt;&lt;br&gt;
= Similar to z-index&lt;br&gt;
→ When specified, overrides the default &lt;code&gt;order&lt;/code&gt; value of &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Any &lt;code&gt;order&lt;/code&gt; higher than &lt;code&gt;0&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= Moves it to get positioned last&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Less than &lt;code&gt;0&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
= Moves it to the front of the line &lt;br&gt;
→ Gets places first&lt;/p&gt;
&lt;h3&gt;
  
  
  Example Use Case
&lt;/h3&gt;

&lt;p&gt;= Overlapping elements&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.water {
order: 0;
}

#poison {
order: 5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4.8 Row Positioning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Does not move the Grid's tacking position forward &lt;br&gt;
→ Row-positioned items are handled first&lt;br&gt;
→ Grid starts again from the top &lt;br&gt;
= Positioning an element by &lt;code&gt;grid area&lt;/code&gt; is row positioning&lt;/p&gt;
&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= To position elements in rows, use the same properties for columns, replacing the word &lt;code&gt;column&lt;/code&gt; w/ &lt;code&gt;row&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Example Use Case
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-start: 3;

grid-row: 3 / 6;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  4.9 Column Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Columns &amp;amp; Rows Example
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-column: 2;
grid-row: 5;
&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;grid-column: 2 / span 4;
grid-row: span 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;= Sets position of both dimensions at once&lt;/p&gt;
&lt;h2&gt;
  
  
  4.10 Area Positioning
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;grid-area&lt;/code&gt;&lt;br&gt;
= 4 values separated by a / &lt;/p&gt;
&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Combines &lt;code&gt;grid-row-start&lt;/code&gt;, &lt;code&gt;grid-column-start&lt;/code&gt;, &lt;code&gt;grid-row-end&lt;/code&gt;, and &lt;code&gt;grid-column-end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;= Specifies a grid element's Size &amp;amp; Location: W/in a Grid &lt;br&gt;
→ By contributing a line, a span, or nothing (automatic) to its grid placement &lt;/p&gt;

&lt;p&gt;= Specifying the edges of its grid area &lt;/p&gt;
&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Grid Elements &amp;amp; absolutely-positioned boxes whose containing block is a grid container&lt;/p&gt;

&lt;p&gt;= Used w/ multiple elements: We can overlap them&lt;br&gt;
= Starts at top line, works its way counter-clockwise&lt;br&gt;
→ Top line, left line, bottom line, right line&lt;/p&gt;
&lt;h3&gt;
  
  
  Rules
&lt;/h3&gt;

&lt;p&gt;= Does not require specifying all 4 positioning slots&lt;/p&gt;
&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;grid-row-start&lt;/code&gt; / &lt;code&gt;grid-column-start&lt;/code&gt; / &lt;code&gt;grid-row-end&lt;/code&gt; / &lt;code&gt;grid-column-end&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;= Any of the values you use in the longhand positioning settings&lt;br&gt;
→ Line Numbers, Line Names, Negative Numbers, span, etc. &lt;/p&gt;
&lt;h4&gt;
  
  
  1. Default: &lt;code&gt;auto&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;= All 4 values set to &lt;code&gt;auto&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Keyword Values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;auto&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
→ Property contributes nothing to grid element's placement &lt;br&gt;
→ Auto-placement or a default span of &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use Case&lt;/em&gt;&lt;br&gt;
= Used to skip positioning slots &lt;br&gt;
→ Won't assign a position &lt;br&gt;
→ Lets item fill Grid using default behaviour&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: span 5 / span 2 / auto / auto;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Identical to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: auto / auto / span 5 / span 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Everything left off will be set to &lt;code&gt;auto&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: span 5 / span 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3.  Values
&lt;/h4&gt;

&lt;p&gt;= String Names&lt;br&gt;
→ ie Names Lines with names &lt;code&gt;&amp;lt;custom-ident&amp;gt;-start&lt;/code&gt;/&lt;code&gt;&amp;lt;custom-ident&amp;gt;-end&lt;/code&gt;&lt;br&gt;
= Contributes 1st such line to grid item's placement&lt;/p&gt;

&lt;p&gt;Named grid areas auto-generate implicit suffixes for the names of the lines formed &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: foo;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Chooses the start/end edge of that named grid area &lt;br&gt;
&amp;amp;&amp;amp; sets it to &lt;code&gt;foo-start&lt;/code&gt; and &lt;code&gt;foo-end&lt;/code&gt;&lt;br&gt;
→ Unless another line named &lt;code&gt;foo-start&lt;/code&gt; or &lt;code&gt;foo-end&lt;/code&gt; was explicitly specified beforehand&lt;/p&gt;
&lt;h4&gt;
  
  
  4.  &amp;amp;&amp;amp;  Values
&lt;/h4&gt;

&lt;p&gt;= Contributes the nth grid line to the grid item's placement &lt;br&gt;
→ If negative integer: Counts in reverse&lt;br&gt;
= Starting from end edge of explicit grid &lt;/p&gt;

&lt;p&gt;→ If name given as a &lt;br&gt;
= Only lines w/ that name are counted &lt;/p&gt;

&lt;p&gt;→ If not enough lines w/ that name exists &lt;br&gt;
= All implicit grid lines are assumed to have that name for the purpose of finding this position&lt;/p&gt;

&lt;p&gt;→ Invalid  value: 0 &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: 4 some-grid-area / 2 another-grid-area;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. span &amp;amp;&amp;amp; [  ||  ] values
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt; &lt;br&gt;
= Uses a grid span for grid item's placement &lt;br&gt;
→ Corresponding edge of grid item's grid area is n lines from opposite edge&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;If name is given as a &lt;/em&gt;&lt;br&gt;
= Only lines w/ that name are counted&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If not enough lines with that name exist&lt;/em&gt;&lt;br&gt;
= All implicit grid lines on the side of the explicit grid corresponding to search direction: Assumed to have that name for purpose of counting this span&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If  is omitted&lt;/em&gt;&lt;br&gt;
= Defaults to &lt;code&gt;1&lt;/code&gt;&lt;br&gt;
→ Invalid  values: Negative integers or &lt;code&gt;0&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: span 3 / span some-grid-area;
grid-area: 2 span / another-grid-area span;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Global Values
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;inherit&lt;/code&gt;, &lt;code&gt;initial&lt;/code&gt;, &lt;code&gt;revert&lt;/code&gt;, &lt;code&gt;revert-layer&lt;/code&gt;. &lt;code&gt;unset&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax Options
&lt;/h3&gt;

&lt;h4&gt;
  
  
  a. Four Values Specified
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-row-start&lt;/code&gt; set to 1st Value &lt;/p&gt;

&lt;p&gt;Separated with a /&lt;/p&gt;

&lt;p&gt;= &lt;code&gt;grid-column-start&lt;/code&gt; set to 2nd Value &lt;/p&gt;

&lt;p&gt;Separated with a /&lt;/p&gt;

&lt;p&gt;= &lt;code&gt;grid-row-end&lt;/code&gt; set to 3rd Value&lt;/p&gt;

&lt;p&gt;Separated with a /&lt;/p&gt;

&lt;p&gt;= &lt;code&gt;grid-column-end&lt;/code&gt; set to 4th Value &lt;/p&gt;

&lt;h4&gt;
  
  
  b. Three Values Specified
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-column-end&lt;/code&gt; omitted&lt;br&gt;
→ If &lt;code&gt;grid-column-start&lt;/code&gt; is set, the &lt;code&gt;grid-column-end&lt;/code&gt; set to the same&lt;br&gt;
→ If not, &lt;code&gt;grid-column-end&lt;/code&gt; is set to &lt;code&gt;auto&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  c. Two Values Specified
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-row-end&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;grid-column-end&lt;/code&gt; omitted&lt;br&gt;
→ &lt;code&gt;grid-row-end&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;grid-column-end&lt;/code&gt; set to &lt;code&gt;grid-row-start&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  d. One Value Specified
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-column-start&lt;/code&gt; is omitted&lt;br&gt;
→ &lt;code&gt;grid-row-start&lt;/code&gt; = &lt;code&gt;grid-column-start&lt;/code&gt;&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
#item1 {
grid-area: 2 / 2 / auto / span 3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Positioning Elements at Grid Lines
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= More convenient than &lt;code&gt;grid-row&lt;/code&gt; and &lt;code&gt;grid-column&lt;/code&gt; positioning shorthands &lt;/p&gt;

&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;Identify top line/counter-clockwise pattern &lt;br&gt;
= Dynamic retrieval of lines in the relevant position&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-area: &amp;lt;top line&amp;gt; / &amp;lt;left line&amp;gt; / &amp;lt;bottom line&amp;gt; / &amp;lt;right line&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use Case Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;planet {
  display: grid;
  grid-template-columns: [left] 190px 190px [right];
  grid-template-rows: [top] 1fr 1fr 1fr 1fr [bottom];
}

dunes {
  grid-area: top / left / bottom / right;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functionally equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-row-start: top;
grid-column-start: left;
grid-row-end: bottom;
grid-column-end: right;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h1&gt;
  
  
  Part 5 Shorthands
&lt;/h1&gt;

&lt;h2&gt;
  
  
  5.1 On Grid Container
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Grid Template
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-template&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template: [top-line] 1fr
               20% [bottom-line]
               / [left-line] 1fr 1fr 1fr 1fr [right-line];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Syntax layout resembles layout of Grid itself&lt;/p&gt;

&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;p&gt;= Combines &lt;code&gt;grid-template-rows&lt;/code&gt; &amp;amp; &lt;code&gt;grid-template-columns&lt;/code&gt; &amp;amp; &lt;code&gt;grid-template-areas&lt;/code&gt;&lt;br&gt;
→ Accepts rows, then a slash, then the columns&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defaults&lt;/strong&gt;&lt;br&gt;
= &lt;code&gt;auto&lt;/code&gt; : Takes up the next available cell in the Grid when it's their turn &lt;/p&gt;
&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Left to right, top to bottom&lt;br&gt;
→ Elements flow into the Grid one at a time&lt;br&gt;
→ Taking a turn based on their natural order&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Capacity&lt;/strong&gt;&lt;br&gt;
= Can do most things &lt;br&gt;
→ &lt;strong&gt;ie&lt;/strong&gt; Naming lines&lt;/p&gt;
&lt;h4&gt;
  
  
  Warning
&lt;/h4&gt;

&lt;p&gt;= Cannot add BOTH &lt;code&gt;template-areas&lt;/code&gt; naming &amp;amp; &lt;code&gt;repeat()&lt;/code&gt; at the same time &lt;br&gt;
→ B/c setting would not be able to visually mimic the Grid &lt;/p&gt;
&lt;h4&gt;
  
  
  Add &lt;code&gt;template-areas&lt;/code&gt; naming
&lt;/h4&gt;

&lt;p&gt;= Define Tracks ** w/o** using &lt;code&gt;repeat()&lt;/code&gt; in &lt;code&gt;grid-template&lt;/code&gt;&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template: ". rocky rocky ." 200px
               ". rocky rocky ." 1fr
               / 1fr 1fr 1fr 1fr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;= Same as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-areas: ". rocky rocky ."
                     ". rocky rocky .";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-template: 50% 50% / 200px;&lt;/code&gt;&lt;br&gt;
= Creates a grid w/ 2 rows that are 50%  each &amp;amp; 1 column that is 200px wide&lt;/p&gt;

&lt;h3&gt;
  
  
  Grid
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Row properties, than /, then column properties &lt;/p&gt;

&lt;h4&gt;
  
  
  Application
&lt;/h4&gt;

&lt;p&gt;= Exact same as &lt;code&gt;grid-template&lt;/code&gt;&lt;br&gt;
→ Define rows and columns &lt;/p&gt;

&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Row properties&lt;/li&gt;
&lt;li&gt;Column properties&lt;/li&gt;
&lt;li&gt;grid-auto-flow&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Gaps between Columns/Rows
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-gap&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Sets both column and row gaps&lt;/p&gt;

&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;*row gap* *column gap*&lt;/code&gt;&lt;br&gt;
→ With a Space between &lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-gap: 30% 10%;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5.2 Individual Elements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Column/Row
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-row/column: *start line* / *end line*&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;*end line*&lt;/code&gt; value - optional &lt;br&gt;
→ If no &lt;code&gt;*end line*&lt;/code&gt; value: Will by default only set the &lt;code&gt;*start line*&lt;/code&gt; value&lt;/p&gt;

&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;p&gt;= Set both &lt;code&gt;start&lt;/code&gt; &amp;amp; &lt;code&gt;end&lt;/code&gt; values &lt;em&gt;at once&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Values
&lt;/h4&gt;

&lt;p&gt;= &lt;code&gt;grid-column/row-start&lt;/code&gt; &amp;amp; &lt;code&gt;grid-column/row-end&lt;/code&gt; values&lt;br&gt;
→ Separated by a slash &lt;/p&gt;

&lt;p&gt;= Accepts all values accepted normally by &lt;code&gt;start &amp;amp;&lt;/code&gt;end`&lt;/p&gt;

&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;grid-column: 2 / 4;&lt;/code&gt;&lt;br&gt;
= Sets grid element to start on 2nd vertical grid line &amp;amp; end on 4th grid line &lt;br&gt;
→ Functionally identical to...&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
grid-column-start: 2;&lt;br&gt;
grid-column-end: 4;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Area
&lt;/h3&gt;

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

&lt;h1&gt;
  
  
  Part 6 Workflow
&lt;/h1&gt;

&lt;h4&gt;
  
  
  1. Define Grid Tracks &amp;amp; Gaps
&lt;/h4&gt;

&lt;h4&gt;
  
  
  2. Flow Elements into Grid
&lt;/h4&gt;

&lt;h4&gt;
  
  
  3. Adjust Size/Positions of Elements
&lt;/h4&gt;

&lt;p&gt;= If needed&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Double check &lt;code&gt;grid-auto-flow&lt;/code&gt; setting
&lt;/h4&gt;

&lt;p&gt;= Make sure Grid is flowing correctly&lt;br&gt;
→ Comment out explicit sizes temporarily if needed&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Make sure elements are in their correct cells
&lt;/h4&gt;

&lt;h4&gt;
  
  
  6. Align and justify items
&lt;/h4&gt;

&lt;p&gt;= If needed&lt;/p&gt;

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

&lt;h1&gt;
  
  
  Part 7 Tips for Next Article
&lt;/h1&gt;

&lt;h4&gt;
  
  
  1. Do not write so many notes
&lt;/h4&gt;

&lt;p&gt;= If something has already been written: Do not repeat it&lt;/p&gt;

&lt;p&gt;= Keep notes DRY &lt;br&gt;
→ Or else you will waste far too much time cutting &amp;amp; organizing afterwards&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Cut Details
&lt;/h4&gt;

&lt;p&gt;= Make article more digestible&lt;br&gt;
→ Keep one copy for personal &amp;amp; Another for uploading&lt;/p&gt;

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

&lt;p&gt;And that's it for my expanded and revised CSS Grid notes! I may return if I encounter anything unexpected in practice.&lt;/p&gt;

&lt;p&gt;For my next article, I am considering 3 options: Going into the process I used to create a Texas Hold'em Game, Analysing TailwindCSS, or JavaScript Basics. &lt;/p&gt;

&lt;p&gt;Right now, I am leaning towards JavaScript Basics, as I think it is a good way to continue refreshing core concepts. &lt;/p&gt;

&lt;p&gt;Nonetheless, I think it is certainly advantageous to get to the other two topics at &lt;em&gt;some&lt;/em&gt; point.&lt;/p&gt;

&lt;p&gt;With love,&lt;br&gt;
Angeline &lt;/p&gt;

&lt;p&gt;P.S You're welcome to join my journey by checking out my &lt;a href="https://www.angelinewang.com/how-fast-can-you-learn"&gt;blogs&lt;/a&gt; on founding a startup 🤍&lt;/p&gt;

</description>
      <category>css</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Flexbox Basics</title>
      <dc:creator>Angeline Wang</dc:creator>
      <pubDate>Tue, 26 Jul 2022 16:48:00 +0000</pubDate>
      <link>https://forem.com/angelinewang/flexbox-basics-4mfb</link>
      <guid>https://forem.com/angelinewang/flexbox-basics-4mfb</guid>
      <description>&lt;p&gt;Today I'm back with the second building block in CSS: Flexbox! Handily created in 2009 to facilitate dynamic layouts.&lt;/p&gt;

&lt;p&gt;I was first introduced to these concepts by my &lt;a href="https://generalassemb.ly/education/software-engineering-immersive/london?ga_campaign=immersive-remote&amp;amp;ga_variation=sei-tile"&gt;General Assembly&lt;/a&gt; Software Engineering Immersive a few weeks back. Since then, I've completed a few labs and projects with them. 👩‍💻&lt;/p&gt;

&lt;p&gt;But what was most impactful was having played and replayed &lt;a href="https://flexboxfroggy.com/"&gt;Flexbox Froggy&lt;/a&gt; &amp;amp; &lt;a href="https://mastery.games/flexboxzombies/"&gt;Flexbox Zombies&lt;/a&gt; many times. Each time I replayed these games, I discovered a new insight I previously overlooked, and the concepts were further cemented. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--svvgsXyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qet2reeyu8jmss2427wi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--svvgsXyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qet2reeyu8jmss2427wi.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know these games look silly, but truthfully, they are game (no pun intended) changers to your learning experience 🪄&lt;/p&gt;

&lt;h1&gt;
  
  
  Part 1 Setting up Flexbox
&lt;/h1&gt;

&lt;p&gt;In order to begin using the magic of Flexbox, we must set up the relevant containers by adding extra &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s in our HTML. &lt;/p&gt;

&lt;p&gt;In our CSS file, we select the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; by the class we've assigned to it, and apply &lt;code&gt;display: flex&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Then, we can begin using the following properties to target the &lt;em&gt;elements&lt;/em&gt; nested directly within the &lt;em&gt;container&lt;/em&gt;... &lt;/p&gt;

&lt;h1&gt;
  
  
  Part 2 Alignment Properties
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Location Applied&lt;/em&gt;&lt;br&gt;
= These properties &amp;amp; their corresponding values are applied at the container-level &lt;br&gt;
&lt;em&gt;Purpose&lt;/em&gt;&lt;br&gt;
= They will affect the spacing &amp;amp; positioning of elements w/in the container &lt;/p&gt;

&lt;h2&gt;
  
  
  2.1 &lt;code&gt;flex-direction&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Defines direction elements are placed w/in container&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;row&lt;/code&gt; (Much like the effect of &lt;code&gt;display: inline&lt;/code&gt;)&lt;br&gt;
--&amp;gt; Elements nested directly w/ container: Populated along x-axis&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;row&lt;/code&gt;
= (Refer to description above)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;row-reverse&lt;/code&gt;
= Elements populated in reverse order of text direction&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;column&lt;/code&gt;
= Elements populated in order along y-axis &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;column-reverse&lt;/code&gt;
= Elements populated in reverse order along y-axis &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2.2 &lt;code&gt;justify-content&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Spacing along x-axis &lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Spacing along y-axis&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;flex-start&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Elements placed flush against &lt;em&gt;left&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Elements placed flush against &lt;em&gt;top&lt;/em&gt; of container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-end&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Elements placed flush against &lt;em&gt;right&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Elements placed flush against &lt;em&gt;bottom&lt;/em&gt; of container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;center&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Elements packed flush together &amp;amp; placed in middle of container &lt;em&gt;y-axis&lt;/em&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Elements packed flush together &amp;amp; placed in middle of container &lt;em&gt;x-axis&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;space-between&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;x-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;between&lt;/em&gt; elements&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;y-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;between&lt;/em&gt; elements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;space-around&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;x-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;around&lt;/em&gt; both sides of each element&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;y-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;around&lt;/em&gt; both sides of each element&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2.3 &lt;code&gt;align-items&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;--&amp;gt; &lt;code&gt;row&lt;/code&gt; = Spacing along y-axis &lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;= Spacing along x-axis&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;flex-start&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Elements flush to &lt;em&gt;top&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Elements flush to &lt;em&gt;left&lt;/em&gt; of container &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;baseline&lt;/code&gt;&lt;br&gt;
1/ Targets &lt;em&gt;tallest&lt;/em&gt; element&lt;br&gt;
2/ Aligns &lt;em&gt;tallest&lt;/em&gt; element's top-most/left-most (row/column) edge with the top-most/left-most (row/column) edge of container &lt;br&gt;
3/ Aligns rest of elements' baseline w/ baseline of &lt;em&gt;tallest&lt;/em&gt; element&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  What is the baseline?
&lt;/h5&gt;

&lt;p&gt;= Where letters 'sit'&lt;br&gt;
--&amp;gt; Descenders of letters extends below baseline&lt;/p&gt;

&lt;h5&gt;
  
  
  Use Case
&lt;/h5&gt;

&lt;p&gt;= Content size varies among elements&lt;br&gt;
--&amp;gt; If content size is the same, baseline: Same effect as &lt;code&gt;flex-start&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-end&lt;/code&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Align Elements flush to &lt;em&gt;right&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Align Elements flush to &lt;em&gt;bottom&lt;/em&gt; of container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;center&lt;/code&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Elements packed flush together &amp;amp; placed in middle of container &lt;em&gt;x-axis&lt;/em&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Elements packed flush together &amp;amp; placed in middle of container &lt;em&gt;y-axis&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;stretch&lt;/code&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Aligns top &amp;amp; bottom of element flush with top &amp;amp; bottom of container by stretching entire element&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Aligns left &amp;amp; right of element flush with left &amp;amp; right of container by stretching entire element&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2.4 &lt;code&gt;order&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Swap the position of an element w/in its group of elements&lt;/p&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= To individual element&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= Can be Positive or Negative&lt;br&gt;
&lt;strong&gt;Effects of Values&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Since Default Value for any Element: &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Element w/ Positive &lt;code&gt;order&lt;/code&gt; Value
= Immediately moved to back &lt;/li&gt;
&lt;li&gt;Element w/ Negative &lt;code&gt;order&lt;/code&gt; Value 
= Immediately moved to front
&lt;strong&gt;Reason&lt;/strong&gt;
= &lt;code&gt;order&lt;/code&gt; Values set to Elements --&amp;gt; Place the Elements in chronological order (From negative to positive values)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2.5 &lt;code&gt;align-self&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Align an individual element on container's &lt;em&gt;y-axis&lt;/em&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Align an individual element on container's &lt;em&gt;x-axis&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= To a specific element &lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= Same as `align-items&lt;/p&gt;

&lt;h2&gt;
  
  
  2.6 &lt;code&gt;flex-wrap&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Create more space for Elements&lt;br&gt;
--&amp;gt; By providing them w/ space beyond their present line&lt;br&gt;
--&amp;gt; Allowing Elements to maintain size &lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;nowrap&lt;/code&gt;&lt;br&gt;
--&amp;gt; Will shrink Elements to fit into line&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;1 . &lt;code&gt;nowrap&lt;/code&gt;&lt;br&gt;
= Fit all elements into 1 line&lt;br&gt;
--&amp;gt; Even if this means shrinking them &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;wrap&lt;/code&gt;
= Add additional lines to populate elements &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wrap-reverse&lt;/code&gt;
= Add additional lines to populate elements
--&amp;gt; In reverse order &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2.7 &lt;code&gt;align-content&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Spacing &amp;amp; Positioning of 'lines'/'groups' of elements &lt;br&gt;
--&amp;gt; Takes in &amp;amp; manipulates each 'line' the way &lt;code&gt;align-items&lt;/code&gt; take in each 'element'&lt;/p&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Applied with &lt;code&gt;flex-wrap: wrap&lt;/code&gt;&lt;br&gt;
--&amp;gt; W/o &lt;code&gt;flex-wrap: wrap&lt;/code&gt;, &lt;code&gt;align-content&lt;/code&gt; has no effect&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-start&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Lines flush to &lt;em&gt;top&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Lines flush to &lt;em&gt;left&lt;/em&gt; of container &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-end&lt;/code&gt; &lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Elements flush to &lt;em&gt;bottom&lt;/em&gt; of container&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Elements flush to &lt;em&gt;right&lt;/em&gt; of container &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;center&lt;/code&gt; &lt;br&gt;
--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Lines packed flush together &amp;amp; placed in middle of container &lt;em&gt;x-axis&lt;/em&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Lines packed flush together &amp;amp; placed in middle of container &lt;em&gt;y-axis&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;space-between&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;y-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;between&lt;/em&gt; lines&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;x-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;between&lt;/em&gt; lines&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;space-around&lt;/code&gt;&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: row&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;y-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;around&lt;/em&gt; both sides of each line&lt;br&gt;
--&amp;gt; If &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= Divides up remaining container &lt;em&gt;x-axis&lt;/em&gt; space, adds equal amount &lt;em&gt;around&lt;/em&gt; both sides of each line&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;stretch&lt;/code&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;row&lt;/code&gt;&lt;br&gt;
= Aligns top &amp;amp; bottom of line flush with top &amp;amp; bottom of container by stretching each entire line&lt;br&gt;
--&amp;gt; &lt;code&gt;column&lt;/code&gt;&lt;br&gt;
= Aligns left &amp;amp; right of line flush with left &amp;amp; right of container by stretching each entire line&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;align-content&lt;/code&gt; vs &lt;code&gt;align-items&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;align-content&lt;/code&gt;: Spacing &amp;amp; Positioning of &lt;em&gt;lines&lt;/em&gt; of elements&lt;br&gt;
= &lt;code&gt;align-items&lt;/code&gt;: Spacing &amp;amp; Positioning of &lt;em&gt;individual&lt;/em&gt; elements &lt;/p&gt;

&lt;h1&gt;
  
  
  Part 3 Speed of Resizing Properties
&lt;/h1&gt;

&lt;h2&gt;
  
  
  3.1 Alignment vs Resizing Properties
&lt;/h2&gt;

&lt;p&gt;= In all cases, the Flexbox is created on the container&lt;br&gt;
But...&lt;br&gt;
--&amp;gt; Alignment Properties: Applied by selecting Container in CSS&lt;br&gt;
--&amp;gt; Resizing Properties: Applied by selecting Elements themselves in CSS&lt;/p&gt;

&lt;h2&gt;
  
  
  3.2 &lt;code&gt;flex-grow&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Interactions w/ other properties
&lt;/h3&gt;

&lt;p&gt;= Nullifies any effect of &lt;code&gt;justify-content&lt;/code&gt;&lt;br&gt;
--&amp;gt; Unless there are new lines&lt;/p&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Enlarge Element(s) to fill ALL available space&lt;br&gt;
--&amp;gt; Works the same for horizontal (&lt;code&gt;flex-direction: row&lt;/code&gt;) &amp;amp; vertical (&lt;code&gt;flex-direction: column&lt;/code&gt;) space&lt;/p&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Directly to Elements&lt;br&gt;
--&amp;gt; Not on Elements' container&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Apply &lt;code&gt;flex-grow: 1&lt;/code&gt; to class w/ all similar elements&lt;/li&gt;
&lt;li&gt;Override growing for specific elements that do not grow 
= &lt;code&gt;flex-grow: 0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Adjust ratios for specific elements growing faster
= &lt;strong&gt;ie&lt;/strong&gt; &lt;code&gt;flex-grow: 3&lt;/code&gt; 
--&amp;gt; Grows 3X as fast as any other element w/ &lt;code&gt;flex-grow: 1&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;0&lt;/code&gt;&lt;br&gt;
--&amp;gt; Will not grow unless told to &lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= Ratios&lt;br&gt;
--&amp;gt; Set 2 elements &lt;code&gt;flex-grow: 1&lt;/code&gt; = Both grow to fill available space at same rate&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;--&amp;gt; Set 1 element to grow at 2X the speed of another element&lt;br&gt;
= &lt;code&gt;flex-grow: 2&lt;/code&gt;, &lt;code&gt;flex-grow: 1&lt;/code&gt;&lt;br&gt;
= 2X the SPEED, NOT 2X the SIZE: Both growing to fill available space &lt;/p&gt;

&lt;h2&gt;
  
  
  3.2 &lt;code&gt;flex-shrink&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= React when there is not enough space for elements &lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;1&lt;/code&gt;&lt;br&gt;
--&amp;gt; Shrinks without explicitly setting values &lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= Ratios&lt;br&gt;
--&amp;gt; Used to control how quickly each element shrinks (Speed)&lt;/p&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;= Elements shrink at a rate relative to each other &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All Elements shrinking at same speed
= Do not set &lt;code&gt;flex-shrink&lt;/code&gt;: This is covered by default value &lt;/li&gt;
&lt;li&gt;Certain Elements shrinking 2X as fast
= &lt;code&gt;flex-shrink: 2&lt;/code&gt;
--&amp;gt; Shrinking twice the SPEED, not SIZE
--&amp;gt; For every 1 pixel, these shrink 2 pixels each&lt;/li&gt;
&lt;li&gt;Refuse to shrink
= &lt;code&gt;flex-shrink: 0&lt;/code&gt;
--&amp;gt; Specified on individual element&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Shrinking &amp;amp; Growing
&lt;/h3&gt;

&lt;p&gt;= Can be used in combination &lt;br&gt;
--&amp;gt; By Default: Applying &lt;code&gt;flex-grow&lt;/code&gt; = Used w/ &lt;code&gt;flex-shrink: 1&lt;/code&gt;&lt;br&gt;
= Will Grow &amp;amp; Shrink depending on existence of extra space || lack of space &lt;br&gt;
--&amp;gt; If want elements to Shrink at same speed &amp;amp;&amp;amp; Grow&lt;br&gt;
= Only set &lt;code&gt;flex-grow&lt;/code&gt;: B/c &lt;code&gt;flex-shrink&lt;/code&gt; is set to &lt;code&gt;1&lt;/code&gt; by Default already &lt;/p&gt;

&lt;h2&gt;
  
  
  3.3 &lt;code&gt;flex-basis&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Starting point/Ideal world (before any &lt;em&gt;growing&lt;/em&gt; or &lt;em&gt;shrinking&lt;/em&gt;)&lt;br&gt;
--&amp;gt; Enough space to fit &lt;code&gt;flex-basis&lt;/code&gt; defined: Element takes on size defined by &lt;code&gt;flex-basis&lt;/code&gt;&lt;br&gt;
--&amp;gt; Not enough space to fit &lt;code&gt;flex-basis&lt;/code&gt; defined: Element takes on only the amount of size &lt;em&gt;permitted&lt;/em&gt; by space&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Value
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;auto&lt;/code&gt;&lt;br&gt;
--&amp;gt; Same as &lt;code&gt;width&lt;/code&gt; value&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Units of Measurement&lt;/strong&gt;: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pixels&lt;/li&gt;
&lt;li&gt;Percentages
&lt;em&gt;Example&lt;/em&gt;: &lt;code&gt;flex-basis: 50%&lt;/code&gt;
= Takes up 50% of width of container&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Application
&lt;/h3&gt;

&lt;p&gt;--&amp;gt; &lt;code&gt;flex-direction: row&lt;/code&gt; &lt;br&gt;
= &lt;code&gt;flex-basis&lt;/code&gt; targets the &lt;em&gt;width&lt;/em&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;flex-direction: column&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;flex-basis&lt;/code&gt; targets the &lt;em&gt;height&lt;/em&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Final &lt;code&gt;flex-basis&lt;/code&gt; Contributors
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt;&lt;br&gt;
= If &lt;code&gt;flex-basis&lt;/code&gt; specified&lt;br&gt;
--&amp;gt; &lt;code&gt;width&lt;/code&gt;: Overridden &amp;amp; Ignored&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;min-width&lt;/code&gt;/&lt;code&gt;min-height&lt;/code&gt;&lt;br&gt;
= Lower Limit for &lt;code&gt;flex-basis&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;min-width: 300px&lt;/code&gt;/&lt;code&gt;min-height: 300px&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;flex-basis: 100px&lt;/code&gt;&lt;br&gt;
--&amp;gt; Final &lt;code&gt;flex-basis&lt;/code&gt; = 300px (&lt;code&gt;min-width&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;min-width&lt;/code&gt;/&lt;code&gt;min-height&lt;/code&gt; &amp;gt; &lt;code&gt;flex-basis&lt;/code&gt; set&lt;br&gt;
--&amp;gt; Final &lt;code&gt;flex-basis&lt;/code&gt; = &lt;code&gt;min-width/min-height&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;max-width&lt;/code&gt;/&lt;code&gt;max-height&lt;/code&gt;
= Upper Limit for &lt;code&gt;flex-basis&lt;/code&gt;
&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;flex-basis&lt;/code&gt; &amp;gt; &lt;code&gt;max-width&lt;/code&gt;/&lt;code&gt;max-height&lt;/code&gt;
--&amp;gt; Final &lt;code&gt;flex-basis&lt;/code&gt; = &lt;code&gt;max-width&lt;/code&gt;/&lt;code&gt;max-height&lt;/code&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Order of Overriding
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;min/max-width/height&lt;/code&gt; &amp;gt; &lt;code&gt;flex-basis&lt;/code&gt; &amp;gt; &lt;code&gt;width/height&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Interactions w/ Other Properties
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-basis: 0&lt;/code&gt;&lt;br&gt;
= Will not show the Element, unless &lt;code&gt;flex-grow&lt;/code&gt; is set&lt;br&gt;
--&amp;gt; Size set to 0 until growing begins &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-shrink: 0&lt;/code&gt;&lt;br&gt;
= Does not allow Element to shrink past &lt;code&gt;flex-basis&lt;/code&gt; size&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex-grow&lt;/code&gt; need not be specified &lt;br&gt;
= If &lt;code&gt;flex-basis&lt;/code&gt; &amp;gt; Current &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; &lt;br&gt;
&amp;amp;&amp;amp; Element does not need to grow beyond &lt;code&gt;flex-basis&lt;/code&gt; size&lt;br&gt;
--&amp;gt; &lt;code&gt;flex-basis&lt;/code&gt; can sometimes be mistaken for &lt;code&gt;flex-grow&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Available space does not allow for &lt;code&gt;flex-basis&lt;/code&gt; size&lt;br&gt;
= Element shrinks according to &lt;code&gt;flex-shrink&lt;/code&gt;/default shrinking&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Available space increases &amp;amp;&amp;amp; Element has specified &lt;code&gt;flex-grow&lt;/code&gt;&lt;br&gt;
= Element grows &lt;em&gt;beyond&lt;/em&gt; &lt;code&gt;flex-basis&lt;/code&gt; size &lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;flex-basis: 200px&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;flex-grow: 1&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Part 4 Shorthand Properties
&lt;/h1&gt;

&lt;h2&gt;
  
  
  4.1 &lt;code&gt;flex-flow&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Combines &lt;code&gt;flex-direction&lt;/code&gt; &amp;amp; &lt;code&gt;flex-wrap&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;p&gt;= Values of &lt;code&gt;flex-direction&lt;/code&gt; &amp;amp; &lt;code&gt;flex-wrap&lt;/code&gt;&lt;br&gt;
--&amp;gt; Separated by a space&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;flex-flow: row wrap&lt;/code&gt;&lt;br&gt;
= Sets rows &amp;amp; wraps them into additional lines&lt;/p&gt;

&lt;h2&gt;
  
  
  4.2 &lt;code&gt;flex&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Purpose
&lt;/h3&gt;

&lt;p&gt;= Combines 2 Settings: &lt;code&gt;flex-grow&lt;/code&gt;, &lt;code&gt;flex-shrink&lt;/code&gt;, &amp;amp; &lt;code&gt;flex-basis&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Leave off 3rd Value: &lt;code&gt;flex-basis&lt;/code&gt;
= &lt;code&gt;flex-basis&lt;/code&gt; set to &lt;strong&gt;0px&lt;/strong&gt; by default 
--&amp;gt; (unlike how &lt;code&gt;flex-basis&lt;/code&gt; is set to &lt;strong&gt;&lt;code&gt;auto&lt;/code&gt;&lt;/strong&gt; as a default without &lt;code&gt;flex&lt;/code&gt; property)**&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;flex: 1 0 auto&lt;/code&gt; = Grow at speed of 1, not shrink, and use &lt;code&gt;width&lt;/code&gt; as &lt;code&gt;flex-basis&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Leave off 2nd Value: &lt;code&gt;flex-shrink&lt;/code&gt;
= &lt;code&gt;flex-shrink&lt;/code&gt; set to &lt;code&gt;1&lt;/code&gt;
--&amp;gt; Same as &lt;em&gt;regular&lt;/em&gt; &lt;code&gt;flex-shrink&lt;/code&gt; default&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;flex: 0 300px&lt;/code&gt; = No growing &amp;amp;&amp;amp; &lt;code&gt;flex-basis: 300px&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Leave off both 2nd &amp;amp; 3rd Values: &lt;code&gt;flex-shrink&lt;/code&gt; &amp;amp; &lt;code&gt;flex-basis&lt;/code&gt;
= Default: &lt;code&gt;flex-basis: 0px&lt;/code&gt; &amp;amp;&amp;amp; &lt;code&gt;flex-shrink: 1&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;code&gt;flex: 1;&lt;/code&gt; = Only sets &lt;code&gt;flex-grow: 1&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Values: Keyword Shortcuts
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex: auto&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;flex-grow: 1&lt;/code&gt;, &lt;code&gt;flex-shrink: 1&lt;/code&gt;, &lt;code&gt;flex-basis: auto&lt;/code&gt;&lt;br&gt;
--&amp;gt; Grows &amp;amp; Shrinks &amp;amp; Keeps initial size = &lt;code&gt;width&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flex: none&lt;/code&gt;&lt;br&gt;
= &lt;code&gt;flex-grow: 0&lt;/code&gt;, &lt;code&gt;flex-shrink: 0&lt;/code&gt;, &lt;code&gt;flex-basis: auto&lt;/code&gt;&lt;br&gt;
--&amp;gt; No Growing &amp;amp; No Shrinking &amp;amp; Initial size = &lt;code&gt;width&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;= &lt;code&gt;flex: 1 1 300px&lt;/code&gt;&lt;br&gt;
--&amp;gt; &lt;code&gt;flex:&lt;/code&gt; &lt;code&gt;grow&lt;/code&gt; &lt;code&gt;shrink&lt;/code&gt; &lt;code&gt;basis&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Caution
&lt;/h3&gt;

&lt;p&gt;= Setting a &lt;code&gt;flex&lt;/code&gt; without specifying the 3rd value&lt;br&gt;
--&amp;gt; Sets your &lt;code&gt;flex-basis&lt;/code&gt; from &lt;code&gt;auto&lt;/code&gt; to &lt;code&gt;0px&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;...And that's it for &lt;strong&gt;CSS Flexbox&lt;/strong&gt;! I'll be returning here to add additional notes and use cases after further personal usage. Super excited to continue sharing my experiences with you &amp;lt;3&lt;/p&gt;

&lt;p&gt;Next week, we'll be moving onto &lt;strong&gt;CSS Grid&lt;/strong&gt; to wrap up &lt;strong&gt;CSS Essentials&lt;/strong&gt;! 🤳&lt;/p&gt;

&lt;p&gt;With love,&lt;br&gt;
Angeline&lt;/p&gt;

</description>
      <category>flexbox</category>
      <category>beginners</category>
      <category>css</category>
      <category>cssflexbox</category>
    </item>
  </channel>
</rss>
